Problem with addhandler and updatepanel dinamicly

Last post 07-05-2009 6:59 AM by stevew1975. 1 replies.

Sort Posts:

  • Problem with addhandler and updatepanel dinamicly

    07-04-2009, 8:12 AM
    • Member
      point Member
    • davideciarmi
    • Member since 07-04-2009, 12:01 PM
    • Posts 1

    Hi at all! I'm italian, and i'm new in this forum...

    i use Asp.net 3.5 and have an question with update panel and insert of button in it dinamicly.

    I have 2 updatePanel, in Panel1 i have an button.

    on click of this button i would add in Panel2 an new button, with an function associated, but all my tests not works!


    this is my html:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server" Text="Button" />
            </ContentTemplate>
        </asp:UpdatePanel>
    
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                
            </ContentTemplate>
        </asp:UpdatePanel>
    
    
    
    
    this is the VB code:
    
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim x As New Button
            x.ID = "bnTemporaneo"
            x.Text = "temporaneo"
            AddHandler x.Click, AddressOf Me.Mess
            UpdatePanel4.ContentTemplateContainer.Controls.Add(x)
            UpdatePanel4.Update()
            ScriptManager1.RegisterAsyncPostBackControl(x)
            UpdatePanel4.Update()
        End Sub
    
    Public Sub Mess()
            MsgBox("msg temp")
    End Function



    But not work! button show, but if i click, it not call the function, and it will hide.

    There are an solution at my problem? thanks very much!

  • Re: Problem with addhandler and updatepanel dinamicly

    07-05-2009, 6:59 AM
    Answer
    • Participant
      1,066 point Participant
    • stevew1975
    • Member since 05-29-2009, 10:51 AM
    • Bristol, UK
    • Posts 189

    I do not think it is possible the way you have done this, i will try and explain what is happening.

    When you click on the button it will post back, then add the second button  dynamically which is fine. 

    This dynamic button will not be in the viewstate.  When you click the dynamic button, the page will postback, but when reloading it is not in the viewstate so is not know about.  This then means that the button is not visible as you are seeing.

    You will need to add any dynamic buttons within your page load.  I would then set the visible of the second button to false.  when you click the first button set the visible value of the second button to true.


    Hope this helps.




    Please mark this post as answered if it helped you!
Page 1 of 1 (2 items)