The value set to controls at client side donot persist for each page load, else it is again set to the default value...??

 I am trying to set date to the textbox field using javascript (Client side), the function is as follows.

 function From_calendarPicker()
{
              
                var    sDPath = "../Calender.aspx";
                var    oWin = window.showModalDialog(sDPath, null, "dialogWidth:300px;dialogHeight:250px;help:0;status:0;scroll:0;center:1");
                if (oWin != null)
                {
                    document.getElementById('fromDate').value=oWin;
                }
}

after calling this function the values reflects at the textbox , but when the page loads by clicking on another server control the set value to textbox disappears and again the default value is seen to the textbox.

 

Why does this kind of thing happen, at client side it works perfectly, but at each page load or server side it is again set to the default value...??

I tried using Hidden field it worked fine, but the issue is like it is hectic to manage the hidden filed for all the controls and keep a check on their values.

So can anybody suggest any better option for it.

I would be thankful for any kind of help from you all.
 

 



 

 

0
ashmah24
4/8/2008 11:09:30 AM
asp.net.client-side 24353 articles. 2 followers. Follow

9 Replies
1468 Views

Similar Articles

[PageSpeed] 48
Get it on Google Play
Get it on Apple App Store

How is the element "fromDate" declared? If it is disabled (CodeBehind: fromDate.Enabled = false Client-side: fromDate.disabled = true), that would be the problem as values do not persist on disabled controls. Use the ReadOnly property of the TextBox instead. If that is not the case, I would say that you have to be resetting the TextBox somewhere when the PostBack happens.

NC...

0
NC01
4/8/2008 11:22:59 AM
If your textbox is set to ReadOnly it might explain the problem. If it is, check out this post which explains the issue and how to fix it.

"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
0
ramblor
4/8/2008 11:24:28 AM

ReadOnly will work whereas Enabled=false will not.

NC...

 

0
NC01
4/8/2008 11:28:42 AM
But in .Net 2.0 if the value of a readonly textbox is updated on the client it won't be preserved after a postback either...

"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
0
ramblor
4/8/2008 11:32:45 AM

Actually the "fromDate" textbox is both set

Enabled=true and readonly=true........so that no one can edit it.........is this a problem.........?? 

0
ashmah24
4/8/2008 11:35:55 AM
It's fine that the textbox is enabled and readonly, but if you change the value of a readonly textbox on the client-side it won't be preserved after a postback. This seems to be the problem you are having. Read the article I posted earlier and see if it helps you.

"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
0
ramblor
4/8/2008 11:39:15 AM

 Thanx ramblor

the post helped

"The moral of this blog post is that if you have read-only data you can use either disabled or read-only form fields, it really doesn't matter whether or not you receive back the value of the form field in the form's submissions"

This is true for ASP.NET 2.0.......


 

0
ashmah24
4/8/2008 11:49:04 AM

ramblor:
But in .Net 2.0 if the value of a readonly textbox is updated on the client it won't be preserved after a postback either...

You are right I forgot about that. This will work however.

<form id="form1" runat="server">
 <div>
  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <input type="button" onclick="onButtonClick();" value="Alter TextBox" />
  <asp:button id="postBackButton" runat="server" text="Post Back"></asp:button>
 </div>
</form>

<script type="text/javascript">
<!--
window.onload = function ()
{
 document.getElementById('<%=  TextBox1.ClientID %>').readOnly = true;
}
function onButtonClick()
{
 document.getElementById('<%=  TextBox1.ClientID %>').value = 'Some new value';
}
// -->
</script>

Press the "Alter TextBox" first to change the TextBox's value and then press the "Post Back" to see the value persisted over a PostBack. That would probably also work with the disabled attribute, though I didn't try it.

NC...

0
NC01
4/8/2008 11:50:13 AM

Excellent work this is the best workaround!!! A genieus doesnt know what a probelm is!!

Mathew

0
mp_lights
6/12/2008 2:42:24 PM
Reply:

Similar Artilces:

How can I set client side values as server side values?
Hi, Can anyone tell me how I can get client side values such as document.referrer, navigator.appName etc... into server side scripts? There are some client side values I'd like to set as session vars and insert into the db? How do I go about this? Thanks for any pointers Davlon PS (I'm using powersite 7.1.0.300) Pass them as page parameters, e.g., http://myserver/myurl?document.referrer=whatever&navigator.appName=yadayada Then, in your server-side script, just loop through the document.value array and get these values. -- pbm_hopethishelps, Roy Kie...

How to set the value to the hidden control in the child page from the client-side of the parent page
Hi All,     I need to set the value in the hidden input control (which i have used in the child page) from the parent page. I don't want to use session, since i want to set it from the client-side of the parent page and i have to access the value in the server-side of the child page. I tried using javascript but the value didnt get set. I'm in need of a solution urgently. Thanks & Regards Aishwaria hello my friend, My suggestion is using querystring to send the value to the child page code sample parent page    <input id="Button1" type="button" v...

textbox value set on client side, is not visible on server side or, on the source of the page.
hi, I have a textbox on my webform. the first time I load my page I fill this textbox with  "name" on the server side. once the page is loaded I set the value of the textbox to "thisIsme" with client side code. I even see a different text in the texbox. client side:document.all('txtnameInput').value =  'thisIsme'; server side:Me.txtnaam.Text 'is stil "name" and not "thisIsme" Why is this happening? on the webpage I see the text "thisIsme", but when I look at the source of the webpage I still see the old value in it. it's very odd... I am NOT setting the value back to "name...

Set the value of a server control on client-side
I have tried many ways for a couple of days, but was not successful. I have a javascript that I register at startup (inside Page_Load method) and an input field running on server-side. I try from the javascript to set the value of the hidden input field like this: document.form1.HiddenField.value = 'true'; Every time I try to retrieve the value on server-side at Page_Load, it is empty even after postback (load the page again - not refresh). I even tried this: document.getElementById('HiddenField').value = 'true'; but still not working. What I am thinking is that maybe...

Issue obtaining values in server-side from dropdownlist when updating value using client-side script in master page
HiI got a page in a contentplaceholder of a master page. There is two pulldowns. I populate the first one using server side coding and then use client-side javascript. So far so good. The issue is that upon a postback I try to collect the select value of the second pulldown and there is no data in the pulldown and no selected item. I tried using control.selectedvalue (nothing) or searching the form controls Stringvariable = oForm.FindControl("Control")Thing is I've done this before in 1.1 outside of a master page and it works.Thanks in ad...

Setting the value of server side variable in javascript and wants to use that server side variable on page load.
Hi, I am trying to set the value of a server side variable in javascript and wants to use that variable on page load.  Here is my sample code. -------------------------- private string testVal = null;  private void registerScript(){ if (!this.Page.ClientScript.IsClientScriptBlockRegistered("RequestHeaderValidation")){ StringBuilder sb = new StringBuilder("" + Environment.NewLine);sb.Append(" var version = '2.0'; " + Environment.NewLine); sb.Append(" var isInstalled = Silverlight.isInstalled(version);" + Environment.NewLine)...

Set slider value on the client side
Hi there,  I'm looking to figure out how I might set the slider's value using client side javascript. I have tried to achieve this by setting the value of the bound and target text boxes but neither have the desired effect as the slider handle never moves. Could someone please point me in the right direction? Cheers, Andrew Nevermind I found it can be done using $find(<behaviour id>).set_Value(); One thing I noticed is that when the above command is used the client side valueChanged handling function is called twice. Is this a bug or have I done something incorrectl...

How to take value from client side control from server side code?
Hi all, I would like to know that, how to access client side control in server side code? Here is an example.. I am having the textBox in client side like <input type="text" id="textBoxUsername" name="textBoxUsername"/> I need to take the value from this textBox in button click event which is server side code. private void buttonShow(object sender, System.EventArgs e) { //I need to access this textBox here. } How to do that? Thanks R. eswaran. hi you need to make it run at server. <input type="text" id="textBoxUsername"...

server side control passing value of self in client side function
I have a server side dropdownlist control.It contains values as:"#00FFFF""#FF00FF""#FFFF00"When the selectedindex is changed by the client I want to assign the value of the dropdownlist to a <div id="example"></div> evelement.pseudo:document.getElementbyId('example').bgcolor=dropdownlist.valueHow can I do this? I think I somehow need to attach a function to my dropdownlist which passes its own value as a parameter to a function...any suggestions?Thanks!please mark answers as 'Answered' and post back solutions when you figure stuff out that isnt in the post already. You ...

to change value of Client Side Select html control from database value....
hello forum,  I have a select .. Demo.aspx <select id="DropAccType" name="DropAccType"> <option>Select</option> <option>Saving</option> <option >Current</option> <option>Regular</option> <option>Demat</option> </select> I want to set the value of select by fetching the data from daabase i.e. In my table if I have Value current then when i request the demo.aspx then in select Control the value Current should get selected..... Please help me to sort this out...   Thnx in advance.. Hi-I could be...

Accessing values on the server for controls whose values were changed client-side
Let's say that I have two server controls, a label and a textbox: <asp:Label ID="Label1" runat="server" Text="Old value"></asp:Label> <asp:TextBox ID="TextBox1" runat="server" Text="Old value"></asp:TextBox> Then I run some client-side code that changes their values: document.getElementById('Label1').innerHTML = 'New value'; document.getElementById('TextBox1').value = 'New value'; In the browser, they both visually have the value "New value".  Howev...

UpdatePanel resetting values set in client-side script
Hello everyone,  I have a LinkButton that shows a <div> when clicked.  The <div> contains server controls and some validation items, so it is in an UpdatePanel. In the OnClientClick event on the link button I call some javascript and set some properties on the div.  Here is the function:  function getPosition(thisDiv, obj) { var yPos = getTop(document.getElementById(obj)) - 50; var xPos = getLeft(document.getElementById(obj)) + 50;if (yPos <= 0) yPos = yPos + 100; document.getElementById(thisDiv).style.display= 'block';document.getElemen...

UpdatePanel resetting values set in client-side script
Hello everyone,  I have a LinkButton that shows a <div> when clicked.  The <div> contains server controls and some validation items, so it is in an UpdatePanel. In the OnClientClick event on the link button I call some javascript and set some properties on the div.  Here is the function:  function getPosition(thisDiv, obj) { var yPos = getTop(document.getElementById(obj)) - 50; var xPos = getLeft(document.getElementById(obj)) + 50;if (yPos <= 0) yPos = yPos + 100; document.getElementById(thisDiv).style.display= 'block';document.getElemen...

Setting Values in User Control Based on Session Vars Set After Page Load
Ok ... I have a web app that includes multiple custom user controls on each page. I would like to set values in my "header" control (first one loaded on page) based on session variables I set upon user events in the parent page. For example, the user would select a value from a dropdownlist that sets a session variable, say a certain account number, and I would like that value to appear in the header control on the post back. If I put code to check for the session variable in the page load of the control, it won't show up until a subsequent postback. Basically, I need to ...