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.
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.
Comments