Solved

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

Posted on 2008-10-20
3
1,311 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net Markup for Sub Menu 2 41
links not working 2 26
Video Tutorial help 2 38
close pop up windows when logout or main window closes 17 48
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

756 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