19
votes

I have added linkbutton inside html table dynamically and add into bootstrap modal's body. (linkbutton has coded linkbutton.click += new eventhandler(Eventclick1);)

enter image description here

but, when I click on select, it won't go to my function Eventclick1. It just refreshes the whole page. (it is already inside updatepanel). Anyways I can make the select button to postback? (I don't want to add client side click function like onclientclick = $('#otherbutton').click(); )

UPDATE

lnk_button.ID = this.ID + "AuditSelectedRow_" + Convert.ToString(l_loop); 
lnk_button.Click += new EventHandler(OnAuditRowSelected);
lnk_button.Text = "Select"; 
WebControl wc_tdSelect = new WebControl(HtmlTextWriterTag.Td); 
wc_tdSelect.Controls.Add(lnk_button);
5
Am sorry to say, but honestly not getting any picture of your problem!! This Link might be helpful to you and also the answer mentioned here and here might be very useful to you!! - Guruprasad J Rao
hi all, thanks for all. because this webcontrol i have been quite sometimes every use, therefore, i forgotten actually there is a function to check. if is that particular webcontrol postback, then will render the table (like the picture above), but due to don know what reason, it not detected as itself postback, therefore, it didn't re-render the table. and causing the postback not fire the event. i hav done some tuning to better identify is itself postback. - Min Hong Tan
but, the problem is i have lost the async postback. it become sync postback - Min Hong Tan
Ensure UseSubmitBehavior is set to false. - garryp
usesubmitbehavior is only for button webcontrol and usesubmithehavior will get sync postback. I have solve the problem by using button/imagebutton instead of linkbutton. - Min Hong Tan

5 Answers

1
votes

First make sure that your custom webcontrol inside Updatepanel still exist at the end of page life cycle. I assume you are calling a function where you are adding linkbutton to the webcontrol. something like this:

// Custom function Creating link buttons

private void CreateControls() {

// Create your link buttons here.

}

Now try calling the same function again inside page pre-init method which ensures that the control still exist at the time of button click event. something like this:

//Page Pre Init
protected void Page_PreInit(object sender, EventArgs e)
{
CreateControls();
}

Make sure you have your web control added to updatepanel inside the same function as listed above. Here is a sample code attaching webcontrol to the updatepanel.

yourUpdatePanel.ContentTemplateContainer.Controls.Add(wc_tdSelect);

I am sure you will have your desired result this time :)

0
votes

I have run into similar issue with modal pop-ups and the problem is basically (as stated similarly above), is the sequence of when the asp.net control is rendered verses when events and/or JS functions get registered.

One way to solve is to render an HTML control manually so that you can control it's name and when it gets rendered.

0
votes

Generally you should be avoiding the dynamic controls, you should add button in design time inside div and show/hide that div on client side for popup.

Have a look at this thread:-

stackoverflow

0
votes

You can use the ASP Button like in your example

   <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <!-- Modal -->
                    <asp:Label ID="Label1" runat="server" Text=""></asp:Label><br />
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                        aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        Modal title</h4>
                                </div>
                                <div class="modal-body">
                                    <asp:TextBox ID="TextBox1" runat="server" placeholder="First Name" class="form-control"></asp:TextBox><br />
                                    <asp:TextBox ID="TextBox2" runat="server" placeholder="Middle Name" class="form-control"></asp:TextBox><br />
                                    <asp:TextBox ID="TextBox3" runat="server" placeholder="Last Name" class="form-control"></asp:TextBox><br />
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        Close</button>
                                    <%--<button type="button"  class="btn btn-primary">
                                        Save changes</button>--%>
                                    <asp:Button Text="Save" OnClick="Submit" runat="server" />
                                </div>
                            </div>
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
0
votes

This the following inside pageload:

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.OnAuditRowSelected);