Hello,
I have a Textbox whose value is been changed using ServerSide code (AJAX based - Partial postback) and now I want to access that changed value in JavaScript. Please suggest me that how can I access that value.
document.getElementByID is displaying old value.
Things work fine with full postback but are creating above issue with Partial Postback.
Thanks, in Advance....
Please Mark as Answer if the post helps you.
My BLOG
Yes my Textbox is within an Updatepanel. And I have changed the value of Textbox behind a Button press event (Button is also within the Updatepanel). Lets us say the initial Text of Textbox (ID=txtTest) was "Initial Text" and I did the following behing the
button press
Now I want this new value "New Text" in a Javascript function but when I access the Textbox in JavaScript using "document.getElementById" then it either displays older value or display "Undefined". But when I remove Update Panel then it works perfectly that
is I get the "New Text" in my Javascript function
Please Mark as Answer if the post helps you.
My BLOG
The problem is with the javascript i think... when you put the textbox inside a updatepanel it will be rendered as a control with different id... i think you are missing that...
//The problem is with the javascript i think... when you put the textbox inside a updatepanel it will be rendered as a control with different id... i think you are missing that...//
I don't think so :S as control is accessible with same ID in "Source" and also ID get changed within some Control or in case of MasterPages. Am I missing something?
Please Mark as Answer if the post helps you.
My BLOG
iGulfam
Contributor
4794 Points
947 Posts
How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 06:32 AM|LINK
Hello,
I have a Textbox whose value is been changed using ServerSide code (AJAX based - Partial postback) and now I want to access that changed value in JavaScript. Please suggest me that how can I access that value.
document.getElementByID is displaying old value.
Things work fine with full postback but are creating above issue with Partial Postback.
Thanks, in Advance....
My BLOG
chenthil_it
Participant
1490 Points
290 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 09:53 AM|LINK
Even it is partial postback the value will be rendered with the new one if you are rendering the control back...
Vinija
Contributor
2460 Points
402 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 09:54 AM|LINK
What do you mean by "Partial postback" ? Is it an update panel? Do you call service web methode?
Is your new value displayed on screen after the partial postback?
Blog
iGulfam
Contributor
4794 Points
947 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:01 AM|LINK
Yes my Textbox is within an Updatepanel. And I have changed the value of Textbox behind a Button press event (Button is also within the Updatepanel). Lets us say the initial Text of Textbox (ID=txtTest) was "Initial Text" and I did the following behing the button press
protected void btnTest_Click(object sender, EventArgs e)
{
txtTest.Text = "New Text";
}
Now I want this new value "New Text" in a Javascript function but when I access the Textbox in JavaScript using "document.getElementById" then it either displays older value or display "Undefined". But when I remove Update Panel then it works perfectly that is I get the "New Text" in my Javascript function
My BLOG
iGulfam
Contributor
4794 Points
947 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:03 AM|LINK
//Even it is partial postback the value will be rendered with the new one if you are rendering the control back... //
I am using AJAX toolkit and not doing anything by myself.
My BLOG
chenthil_it
Participant
1490 Points
290 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:06 AM|LINK
The problem is with the javascript i think... when you put the textbox inside a updatepanel it will be rendered as a control with different id... i think you are missing that...
iGulfam
Contributor
4794 Points
947 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:09 AM|LINK
//The problem is with the javascript i think... when you put the textbox inside a updatepanel it will be rendered as a control with different id... i think you are missing that...//
I don't think so :S as control is accessible with same ID in "Source" and also ID get changed within some Control or in case of MasterPages. Am I missing something?
My BLOG
chenthil_it
Participant
1490 Points
290 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:12 AM|LINK
Can you update me with the javascript code???
iGulfam
Contributor
4794 Points
947 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:16 AM|LINK
//Can you update me with the javascript code???//
Javascript code is very much simple right now and that is
alert(document.getElementById('txtTest).value);
PS: If I don't use UpdatePanel then above alert displays correct value. But with Update panel it don't
My BLOG
chenthil_it
Participant
1490 Points
290 Posts
Re: How to access ServerSide control Value in Javascript changed by Ajax
Oct 13, 2008 10:21 AM|LINK
alert(document.getElementById('<%=txtTest.Id%>').value);