Check Form controls have changed

M

magister

Hello, I have a asp.net page with a form with 15 textboxes and a
couple of dropdownlists....I want to know if their is a way
(...serverside please...) of checking if any change has been made to
any of these controls before I send and update to the database....I
would rather not have a OnTextChanged & OnSelectedItemChanged with
postback set to false for every control on the page...

I have been trying to implement the IPostBackEventHandler in the page
System.Web.UI.Page, IPostBackEventHandler

and then override methods in it, but I think this is mostly for
customcontrols

public override void RaisePostBackEvent( IPostBackEventHandler
sourceControl, string eventArgument)
{
Response.Write( "<b>This is the RaisePostBackEvent event.</b><br>" );
}

public virtual void RaisePostDataChangedEvent()
{
Response.Write( "<b>This is the RaisePostDataChangedEvent");
}

public virtual bool LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
string presentValue = _text;
string postedValue = postCollection[postDataKey];

if (!presentValue.Equals(postedValue))
{
_text = postedValue;
return true;
}
return false;
}
 
Y

yurps

Thanks for the recommendation....perhaps a custom attribute for the
whole form, maybe a comma delimited string of previous values...

However I do have a multiline textbox, so there could be alot of data
to append.

This seems so obvious that there should be ControlCollection.isDirty or
..Changed...

I don't know how to get to it as RaiseChangedEvents is private....

Maybe I will go apeshit and disassembly the System.Web.UI dll and make
that method overrideable....

hmmm...ideas...ideas....performance-wise unknown..

You could save the original value as a custom attribute and later retrieve
it to compare with what was posted back.
Hope this helps.
--
Gopal Rangaswamy
Microsoft Certified Solutions Developer
FMS, Inc.
<http://www.fmsinc.com/consulting>
<http://www.fmsinc.com/dotnet/SourceBook/>

magister said:
Hello, I have a asp.net page with a form with 15 textboxes and a
couple of dropdownlists....I want to know if their is a way
(...serverside please...) of checking if any change has been made to
any of these controls before I send and update to the database....I
would rather not have a OnTextChanged & OnSelectedItemChanged with
postback set to false for every control on the page...

I have been trying to implement the IPostBackEventHandler in the page
System.Web.UI.Page, IPostBackEventHandler

and then override methods in it, but I think this is mostly for
customcontrols

public override void RaisePostBackEvent( IPostBackEventHandler
sourceControl, string eventArgument)
{
Response.Write( "<b>This is the RaisePostBackEvent event.</b><br>" );
}

public virtual void RaisePostDataChangedEvent()
{
Response.Write( "<b>This is the RaisePostDataChangedEvent");
}

public virtual bool LoadPostData(string postDataKey,
NameValueCollection postCollection)
{
string presentValue = _text;
string postedValue = postCollection[postDataKey];

if (!presentValue.Equals(postedValue))
{
_text = postedValue;
return true;
}
return false;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top