AJAX UpdatePanel dynamic controls and RegisterStartUpScript click twice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsdev
    New Member
    • Jul 2007
    • 149

    AJAX UpdatePanel dynamic controls and RegisterStartUpScript click twice

    Hi,

    I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help!

    I have a gridview in an updatepanel (AJAX control toolkit) and because paging/sorting aren't supported I've added my own custom paging. I have dynamically loaded LinkButtons in the updatepanel to change the page but they only fire on the second click. I have also attached javascript to the rows so that they can be selected when you click. Again only the second click works.

    I have DataBind in the event handlers and I only DataBind the first time when the page is loaded. When I debug the click events only fire the second time??

    Any ideas?

    Thanks in advance
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by rsdev
    Hi,

    I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help!

    I have a gridview in an updatepanel (AJAX control toolkit) and because paging/sorting aren't supported I've added my own custom paging. I have dynamically loaded LinkButtons in the updatepanel to change the page but they only fire on the second click. I have also attached javascript to the rows so that they can be selected when you click. Again only the second click works.

    I have DataBind in the event handlers and I only DataBind the first time when the page is loaded. When I debug the click events only fire the second time??

    Any ideas?

    Thanks in advance
    I'd suggest taking the GridView out of the UpdatePanel.
    Is there any reason why it has to be there?


    Have you attempted moving the paging LinkButtons outside of the GridView (place them above or below or something).

    Comment

    • rsdev
      New Member
      • Jul 2007
      • 149

      #3
      Hi Frinavale,

      Thanks for responding!

      I want the gridview in the updatepanel to create a seemles WYSIWYG CMS.

      Once I've finished the demo I plan to open source the project and invite other developers to help improve it like a updated AJAX WYSIWYG version of DOTNETNUKE.

      Anyway, the LinkButtons are outside the gridview they are dynamically created in placeholder below the gridview. But the javascript is obviously attached to each row of the gridview. So it must be a simple error on my part because both of these don't re-act on the first click. The updatepanel is in conditional mode with ChildTriggers set to true. I've read that I should create dynamic triggers for each of the dynamic controls but that doesn't explain why the javascript rows aren't working either.

      I'm really stumped on this one!

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by rsdev
        Hi Frinavale,

        Thanks for responding!

        I want the gridview in the updatepanel to create a seemles WYSIWYG CMS.

        Once I've finished the demo I plan to open source the project and invite other developers to help improve it like a updated AJAX WYSIWYG version of DOTNETNUKE.

        Anyway, the LinkButtons are outside the gridview they are dynamically created in placeholder below the gridview. But the javascript is obviously attached to each row of the gridview. So it must be a simple error on my part because both of these don't re-act on the first click. The updatepanel is in conditional mode with ChildTriggers set to true. I've read that I should create dynamic triggers for each of the dynamic controls but that doesn't explain why the javascript rows aren't working either.

        I'm really stumped on this one!
        I remember a while ago having the same problem (having to click twice)...but I can't remember how I got around it.

        Let me see if I can't help you find something online regarding the issue.

        -Frinny

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Do me a favour and try to link buttons that are not dynamically generated for your paging....does that fix anything?

          And can you post the JavaScript responsible for selecting so that I can make sure there's nothing wrong here?

          Just double checking before I get into looking up the event firing stuffs.

          Comment

          • rsdev
            New Member
            • Jul 2007
            • 149

            #6
            Hi Frinny,

            Thanks for sticking with this!

            I've just tried adding a LinkButton (great suggestion) and have the same problem, nothing (response.write ) on the first click. It's like the first click isn't getting through to the server... somehow!

            Here's the serverside added javascript;

            Code:
            protected void linksView_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                        if (e.Row.RowType == DataControlRowType.DataRow)
                        {
                            e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";
                            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
                            e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(this.linksView, "Select$" + e.Row.RowIndex);
                        }
            }
            Thanks again!

            Comment

            • rsdev
              New Member
              • Jul 2007
              • 149

              #7
              So in order to trace what was happening to the clicks, I decided to get a hardcore debugger. The Web Development Helper is very cool!

              Now when I load the gridview in the updatepanel I checked the pages DOM and get a table with ID ...CMSControl_1 _linksView. When I click the button first time around the ID changes to CMSControl_ct10 4_linksView, then it remains the same. This has got to be the issue!!

              Comment

              • rsdev
                New Member
                • Jul 2007
                • 149

                #8
                In fact it gets worse because all the javascript: __doPostBack code has used '$' instead of '_' for the ID's.

                So how do I stop the gridivew table from changing ID and how do change the '$' for '_'?

                Comment

                • rsdev
                  New Member
                  • Jul 2007
                  • 149

                  #9
                  Don't worry about the '$' versus '_'. I've found out that doesn't make a difference.

                  But I still have the problem where I create the LinkButtons in Page_Load in a placeholder then the placeholder changes id after the first click so the event is never found or fired.

                  Comment

                  • rsdev
                    New Member
                    • Jul 2007
                    • 149

                    #10
                    So now I'm stuck not knowing how to make the LinkButton __DoPostBack the correct id??

                    Would ParseControl work better?

                    Comment

                    • rsdev
                      New Member
                      • Jul 2007
                      • 149

                      #11
                      I think it's time to re-post this thread with a more appropriate heading.

                      Comment

                      • Frinavale
                        Recognized Expert Expert
                        • Oct 2006
                        • 9749

                        #12
                        Originally posted by rsdev
                        I think it's time to re-post this thread with a more appropriate heading.
                        Don't repost...I'll change the title.
                        What would you like it to be?

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Just try one more thing for me...try taking the GridView out of the update panel...

                          Comment

                          • rsdev
                            New Member
                            • Jul 2007
                            • 149

                            #14
                            Hi Frinny,

                            Sorry I created another post already!

                            But it would be great to continue and try to get to the bottom of this.

                            Unfortunately I can't take the gridview out of the updatepanel as I am dynamically loading it in there. The gridview is inside a user control, which is loaded into the updatepanel. I know this creates complexity but the finish result will be a seemless user experience.

                            The selectable rows are now working. But the paging dynamic LinkButtons are not. When they first load into the updatepanel they have a strange ID, then on the first click the ID becomes correct and they work fine.

                            Is there anyway to solve this?

                            Comment

                            • Frinavale
                              Recognized Expert Expert
                              • Oct 2006
                              • 9749

                              #15
                              Originally posted by rsdev
                              Hi Frinny,

                              Sorry I created another post already!

                              But it would be great to continue and try to get to the bottom of this.

                              Unfortunately I can't take the gridview out of the updatepanel as I am dynamically loading it in there. The gridview is inside a user control, which is loaded into the updatepanel. I know this creates complexity but the finish result will be a seemless user experience.

                              The selectable rows are now working. But the paging dynamic LinkButtons are not. When they first load into the updatepanel they have a strange ID, then on the first click the ID becomes correct and they work fine.

                              Is there anyway to solve this?
                              I know you were explaining this ID problem earlier.
                              Could you post a snippet/example of the "strange" ID and "regular" ID please?

                              Comment

                              Working...