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 |
![]() |
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 |
![]() |
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 |
![]() |
ReadOnly will work whereas Enabled=false will not.
NC...
![]() |
0 |
![]() |
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 |
![]() |
Actually the "fromDate" textbox is both set
Enabled=true and readonly=true........so that no one can edit it.........is this a problem.........??
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |
Excellent work this is the best workaround!!! A genieus doesnt know what a probelm is!!
Mathew
![]() |
0 |
![]() |