How To Get The Text From In Code-behind?
I have two fields in an aspx file: The idea is to use text from text
Solution 1:
In the main Page_Load procedure I put tbName.Value = hfName.Value; This is the only place where I try to use value from hidden field hfName.Value. tbName is not modified after it and should show the text from hidden field hfName. It doesn't.
when page loading nothing set as textbox text, so tbName and hfName values are empty.
you can test this by set default values to both hidden and text fields
<inputtype="text"id="tbName" runat="server" value ="txtVal"/>
<inputtype="hidden"id="hfName" runat="server" value ="hftVal"/>
now on page load you can get non empty values of both controls
protectedvoidPage_Load(object sender, EventArgs e)
{
var txtVal = tbName.Value;
var hfVal = hfName.Value;
}
Solution 2:
In your JavaScript part you write the value from tbName to hfName, in the code behind from hfName to tbName.
hfName.Value = tbName.Value;
With jQuery you could solve the client side part like
$("#<%= hfName.ClientID %>").val($("#<%= tbName.ClientID %>").val());
alert($("#<%= hfName.ClientID %>").val());
Post a Comment for "How To Get The Text From In Code-behind?"