Solved

setting hidden field from code behind on a way that the onchange attivute will fire.

Posted on 2008-10-20
3
1,299 Views
Last Modified: 2012-05-05
I have an  <asp:textbox> on my form that I  set the value of when a user clicks a  submit button.   I have added an onchange attibute to this textbox .  

        this.txtNeedsVersion.Attributes.Add("onchange", "SaveVersion.globalChange = true;");

I have used ClientScript.RegisterOnSubmitStatement (...)  to ensure that when a change occurs that a flag is set  and I have

// Register the event.
window.onbeforeunload = function() {
    return SaveVersion.checkForChanges();

to ensure that some javascript will run  onbeforeunload    

As long as I  type a value into the textbox I added  everything works fine.  Unfortunately when I set the value in the code behind  the onchange is not fired or it is not capture  and as a result my onbeforeunload  script is not run.  

How can I get this to work?  
0
Comment
Question by:DylanJones1
3 Comments
 
LVL 16

Expert Comment

by:sh0e
ID: 22759280

window.onbeforeunload = function() {

    SaveVersion.globalChange = true;

    return SaveVersion.checkForChanges();

Open in new window

0
 
LVL 6

Accepted Solution

by:
AmarIs26 earned 500 total points
ID: 22759305
You can declare a string variable which you assign the value at onload. This value is the value of your textbox. Then when you get to prerender event you can compare the variable value to the current textbox.text value to find out if they have changed or not? If it is different then you can assume that the value has been changed by some method.
At this stage you can register some javascript which will set your
SaveVersion.globalChange = true;
This way the page is now loaded with the flag set which will fire your unload event handler on client side ;)
0
 

Author Closing Comment

by:DylanJones1
ID: 31507865
Thanks Amarls
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now