Reputation: 1
I have an ASPX webform that takes some data and just sends an email. It has worked for years but I just added a new field and I can't get the Text value to transfer to the c# code that writes the email.
The difference is that the new field is populated through jQuery/JSON look-up and it is read-only. The jQuery portion is working fine.
TextBox in question:
<asp:TextBox ID="autoRegion" Width="30" ReadOnly="true" onfocus="this.blur();" TabIndex="-1" CssClass="disabledInput" Value="" runat="server" />
Working TextBoxes:
<asp:TextBox ID="FName" MaxLength="40" TabIndex="1" runat="server" />
<asp:TextBox ID="LName" MaxLength="40" TabIndex="3" runat="server" />
C# variable for email body content:
objMM.Body += "<table><tr><td>" +
LName.Text + "</td><td>" + FName.Text.ToUpper() + "</td><td>" +
streetAddress1.Text + "</td><td>" + city.Text.ToUpper() + "</td><td>" +
state.SelectedItem.Text + "</td><td>" + zip.Text + "</td><td>" + autoRegion.Text +
"</td></tr></table>";
All other fields are working but autoRegion.Text
is not.
I have also tried filling a variable with Request.Form["autoRegion"]
and using that variable in place of autoRegion.Text
but that did not work either.
Any help would be appreciated.
Upvotes: 0
Views: 1358
Reputation: 59
Your should do some changes
remove read only property in textbox as given below
Upvotes: 0
Reputation: 4392
Mark Fitzpatrick is right, the problem is you are setting that TextBox to ReadOnly, which means its value is not persisted in ViewState.
Here is a potential workaround: Disabled textbox losses viewstate
Edit: Also Strange behavior using HTML 'readonly="readonly"' vs. JavaScript 'element.readOnly = true;'
Upvotes: 0
Reputation: 2691
Check out this link: ASP.NET textbox losing value after postback when value is changed client-side via javascript. It appears that the postback only pushes the ViewState data for a TextBox that is either Disabled or ReadOnly. Because you are loading the value via client-side, there is nothing in the ViewState for your TextBox.
There are several different work-around, but I would attempting the answer to this question:
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("readonly", "readonly");
}
In addition to applying this code, you would need to remove the ReadOnly="true" property from the TextBox on the aspx page.
Upvotes: 1
Reputation: 1624
If I remember correctly, read only items do not have their values posted back to the server since there would be no reason since they cannot be changed.
Upvotes: 1