I have a asp.net page like “default.aspx” containing:
<form id="form1" runat="server" >
<asp:Textbox id="Textbox1" runat="server" />
<asp:Button id="Button1" runat="server" onClick="Button1_Click" text="submit" />
</form>
What I want is keeping text value in textbox field while user returned from other subpages.
So in .cs file I try this:
protected void Button1_Click(object sender, EventArgs e){
Session["Data"] = Textbox1.Text;
}
public string Data{get{return Session["Data"].ToString();}}
and in.aspx:
<asp:Textbox id="Textbox1" runat="server" text="<%# Data %>" />
but it do not work, the textbox field gets blank.
How to implement this without javascript?
The
#works only in databinding expressions. So you need (e.g. inPage_Init)for this to work
otherwise this might also work
inline asp.net tags… sorting them all out (<%$, <%=, <%, <%#, etc.)
As already commented, in general it’s better to use the codebehind since you have compile time checking then.