locked
How to trigger change event on server set hidden field?

    Question

  • Im trying to improve performace on a page by setting link on hyperlink by javascript to improve performance. I was looking for the right forum and i ended up here.

    <form id="form1" runat="server">    
        <asp:HiddenField ID="HiddenFieldLocation" runat="server" /> 
       <script type="text/javascript">
           $(document).ready(function () {
               //$(window).load(function () {
               //$("#HiddenFieldLocation").trigger('change');
               $("#HiddenFieldLocation").load("Location.aspx");
               $("#HiddenFieldLocation").change(function () {
               //$("#HiddenFieldLocation").load("Location.aspx").change(function () {
                   $("#ShowOnMap").attr("href", $("#HiddenFieldLocation").html());
               });
               //});
               $("#HiddenFieldLocation").load("Location.aspx");
           });
    </script>

    i tryed with this code:

    if i use document ready event the href is not set because the script is executed before the hiddenfield is set with the url.

    if i use window load event same thing happens. So the last thing i tryed was setting change event on hidden fields value this event gets never triggered, maybe because im using .load(). So im out of ideas.

    If you still dont understand my problem i will shorten. To load the page takes 2 seconds. To generate the link takes maybe 5sec. So the idea is to set the url on the hyperlink when the value is set in the hiddenfield. This will improve the load time but the link would be set when it is generated from the server side.

    Thank you in advance...:)

    Friday, April 19, 2013 7:31 PM

Answers

  • This forum is about Windows Store Apps (Windows 8 Apps) with HTML5 and JavaScript. So it's probably the wrong place for your question.  Anyway, regarding your question:

    Instead of using the change event of your hidden field, you can use a callback, like this (untested!):

     $("#HiddenFieldLocation").load("Location.aspx",
    function(response){
        ("#ShowOnMap").attr("href", response);
    });
               
               

    for more information have a look at the jquery api docs

    • Marked as answer by Simpa151 Friday, April 19, 2013 10:06 PM
    Friday, April 19, 2013 9:45 PM

All replies

  • This forum is about Windows Store Apps (Windows 8 Apps) with HTML5 and JavaScript. So it's probably the wrong place for your question.  Anyway, regarding your question:

    Instead of using the change event of your hidden field, you can use a callback, like this (untested!):

     $("#HiddenFieldLocation").load("Location.aspx",
    function(response){
        ("#ShowOnMap").attr("href", response);
    });
               
               

    for more information have a look at the jquery api docs

    • Marked as answer by Simpa151 Friday, April 19, 2013 10:06 PM
    Friday, April 19, 2013 9:45 PM
  • That worked thank you...:)

     $("#HiddenFieldLocation").load("Location.aspx", function () {
                   $("#ShowOnMap").attr("href", $("#HiddenFieldLocation").html());
                });

    Friday, April 19, 2013 10:06 PM