Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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"/>

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
clientIDMode="Static" 

will work perfectly.

Need to Keep in Mind

  1. If any Server Control Example: TextBox. is Disabled or ReadOnly from Aspx Page or Code behind.

  2. It's value is being changed from JQuery or Javascipt.

  3. You try to get the changed value of this control from code behind then you will never get it.

  4. When you post back this control then server will validate the property (If it is Disabled or ReadOnly then server will not entertain this control's changed value.

  5. You Need to use hidden field and populate this hidden field with changed value of this control.

    <asp:HiddenField runat="server" ID="hdnTextBoxValue"/>

You need to set the changed value by JQuery or Javascript to hidden Field and get the value from Code behind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top