Solved

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

Posted on 2008-10-20
3
1,318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

687 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