Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now