textbox value change not being reflected in code behind c#

非 Y 不嫁゛ 提交于 2019-12-08 06:47:54

问题


I am using .NET framework 1.1 with C#. My problem description is given below.

  1. I have server side textbox control with id:= txtFromDate. view state is enabled and its readonly.
  2. when page loaded for the first time i am setting current date value in above textbox.
  3. after that I change the value of textbox with jQuery.
  4. then posting back the page using jQuery with some __EVENTTARGET parameters.
  5. I am using this changed textbox value in my code behind.

I have developed code in window XP machine 32 bit with 1.1 framework. But now I have put entire site on windows server 2008 R2 edition (64bit) in .NET 2.0 application pool

Problem: it works fine on development machine. but in windows server 2008 change in textbox value by jQuery is not being reflected in code behind. it retains old value which I assign when page gets loaded first time.

I want to run this application as it runs on my development machine. In short I want to get changed value of textbox in codebehind on windows server 2008 machine too.

Thanks.


回答1:


Instead of using txtFromDate.Text I used Request.Form[txtFromDate.ClientID] and problem got solved.




回答2:


Although you can always use set get method to store the values from java script ... But here is some simple way to solve it...

case 1 - If control is just for storing purpose , put display : none in it's style and make visible = true in the attribute of the control.

case 2 - if control is to be displayed but in disabled mode put ReadOnly="true" instead of Enabled = true

eg..

<asp:textbox runat="server" ID="textbox1" Enabled="false"></asp:textbox> will not work

<asp:textbox runat="server" ID="textbox2" ReadOnly="true"></asp:textbox> will work



回答3:


clientIDMode="Static" 

will work perfectly.




回答4:


changes you make to the controls on client side are not accessible to the code behind at the server, unless those changes are made to the values of input controls. so, youu can also use hiddenfield along with label which youu want to change in javascript/ Jquery then, store the new label value in hiddenfield as well then, instead of reading value from label in codebehind, read it from hiddenfield.

<asp:hiddenfied id="hdnLblValue" runat="server"/>


来源:https://stackoverflow.com/questions/14847635/textbox-value-change-not-being-reflected-in-code-behind-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!