Not to clear textbox on page reload or button click event

Jay Patel

I have developed a website in C# asp.net which contains a Master Page. I have designed a top menu with Search bar(txtSearch) and a Button(LinkButton). When I click on search Button it redirects to the page where searched data is to be displayed but when it redirects it clear's the txtSearch. What I want is not to clear the txtSearch on page redirect or page reload.

Top Menu (Search bar)

<asp:TextBox runat="server" ID="txtSearch" TextMode="SingleLine" CssClass="form-control" Placeholder="Search term..." />
<span class="input-group-btn">
    <asp:LinkButton runat="server" ID="btnSearch" CssClass="btn btn-default" type="button" OnClick="btnSearch_Click"><span class="glyphicon glyphicon-search"></span></asp:LinkButton>
</span>

I Hope that the question is clear.

Frost_Mourne

What you can do is.. Store the TextBox value in Session in onclick() Function

protected void btnSubmit_Click(object sender, EventArgs e)
{
   Session["TextBoxVal"] = TextBox1.Text;//The particular TextBox that has value
}

and onPageLoad just assign the value to the TextBox value like this

 protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       {
            TextBox1.Text = (string)ViewState["TextBoxVal"];
       }
         //use this as per your needs just an example how to use
        if(IsPostBack)
        {
            TextBox1.Text = (string)ViewState["TextBoxVal"];
        }
    }

and once it is assigned value to the TexBox clear the session or it will keep assigning the same value.. do it like this

Session["TextBoxVal"] = null;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Textbox value from dynamic ul on button click event

From Dev

In aspx how to trigger button click event when press "Enter" on a textbox while the button click event defined in source cs file

From Dev

Cant update screen (textbox) on button click event for simple calculator application

From Dev

Why would a button click event cause site to reload in a Bootstrap form?

From Dev

Using a Button_Click event to change textbox content using MVVM

From Dev

How to clear textbox after click of cancel button in confirm message box?

From Dev

Clear / Erase TextBox Content With Button Click Event

From Dev

How to clear textbox on click button

From Dev

Javascript click Event only Triggers on Page Reload then does not work

From Dev

Button click event fires on page reload

From Dev

Need to reload page after click on link button

From Dev

Textbox value from dynamic ul on button click event

From Dev

UIPageControl - reload page on click of button

From Dev

Cant update screen (textbox) on button click event for simple calculator application

From Dev

Multiple textbox value addition using single button click event

From Dev

Clear textbox without refreshing the page

From Dev

Reload dataTables after button click

From Dev

Dynamic button not firing click event or page life cycle for button(not dynamic)

From Dev

how to reload the same page while click delete button in php - moodle

From Dev

button causing page to reload

From Dev

clear textbox on submit button without reloading the page

From Dev

Catch the control (button click) who raised the leave event on a textbox

From Dev

how to reload masonry on button click

From Dev

In Django, how to click button to call a view and then reload page

From Dev

Reload part of the page on button click, Refresh whole page on new URL

From Dev

stop reload of entire page with .click & .load event

From Dev

reload jsp page after logout on back button click

From Dev

jquery click event with reload

From Dev

Page Reload on button click in Framework 7 v2

Related Related

  1. 1

    Textbox value from dynamic ul on button click event

  2. 2

    In aspx how to trigger button click event when press "Enter" on a textbox while the button click event defined in source cs file

  3. 3

    Cant update screen (textbox) on button click event for simple calculator application

  4. 4

    Why would a button click event cause site to reload in a Bootstrap form?

  5. 5

    Using a Button_Click event to change textbox content using MVVM

  6. 6

    How to clear textbox after click of cancel button in confirm message box?

  7. 7

    Clear / Erase TextBox Content With Button Click Event

  8. 8

    How to clear textbox on click button

  9. 9

    Javascript click Event only Triggers on Page Reload then does not work

  10. 10

    Button click event fires on page reload

  11. 11

    Need to reload page after click on link button

  12. 12

    Textbox value from dynamic ul on button click event

  13. 13

    UIPageControl - reload page on click of button

  14. 14

    Cant update screen (textbox) on button click event for simple calculator application

  15. 15

    Multiple textbox value addition using single button click event

  16. 16

    Clear textbox without refreshing the page

  17. 17

    Reload dataTables after button click

  18. 18

    Dynamic button not firing click event or page life cycle for button(not dynamic)

  19. 19

    how to reload the same page while click delete button in php - moodle

  20. 20

    button causing page to reload

  21. 21

    clear textbox on submit button without reloading the page

  22. 22

    Catch the control (button click) who raised the leave event on a textbox

  23. 23

    how to reload masonry on button click

  24. 24

    In Django, how to click button to call a view and then reload page

  25. 25

    Reload part of the page on button click, Refresh whole page on new URL

  26. 26

    stop reload of entire page with .click & .load event

  27. 27

    reload jsp page after logout on back button click

  28. 28

    jquery click event with reload

  29. 29

    Page Reload on button click in Framework 7 v2

HotTag

Archive