Hello John,
As for detecting value change on ASP.NET web page, if you want to avoid
server round trips, I think client-side script code is not avoidable. Also,
since we need to compare to the original value(so as to determine whether
the certain input has been changed), it is also necessary to maintain the
original value(for each input element you want to monitor) in page's
response so that the client-script can access. For the ViewState, ASP.NET
is rendering it in a encoded format(undocumented), therefore, we can not
directly get value from it at client-side.
I'm wondering what kind of input controls will you need to check the value
changing, Textbox? Currently, I have a suggestion about using the control's
"PreRender" event to add an additional property to its client-side html
tag( to store its old value). e.g.
#Actually you can consider create a custom Textbox class(derived from the
TextBox) and add the additional property, this provide more flexiblility
and reusability(in multiple pages or projects)
===========
Protected Sub TextBox1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.PreRender
TextBox1.Attributes("oldvalue") = TextBox1.Text
End Sub
==============
then, at client-side, the TexBox is rendered as below html code:
<input name="TextBox1" type="text" id="TextBox1" oldvalue=".............."
/>
And you can use script code to query it, e.g.
===========
var txt = document.getElementById("TextBox1");
alert(txt.oldvalue);
=============
In such cases, the old value will be automatically updated to the latest
value in the Prerender event. What left for us is use client-side code to
check the old value and compare it with lastest value. How do you think of
this?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.