19

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);
amphetamachine
  • 23,162
  • 10
  • 51
  • 68
Min Hong Tan
  • 536
  • 2
  • 14
  • Am sorry to say, but honestly not getting any picture of your problem!! **[This Link](http://www.encodedna.com/2014/07/programmatically-add-linkbutton-to-gridview-aspdotnet.htm)** might be helpful to you and also the answer mentioned **[here](http://stackoverflow.com/a/11167765/2065039)** and **[here](http://stackoverflow.com/a/11127064/2065039)** might be very useful to you!! – Guruprasad J Rao May 07 '15 at 06:52
  • 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 May 07 '15 at 09:22
  • but, the problem is i have lost the async postback. it become sync postback – Min Hong Tan May 07 '15 at 09:32
  • Ensure `UseSubmitBehavior` is set to `false`. – garryp May 07 '15 at 23:20
  • 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 May 08 '15 at 02:08
  • I think your actual problem "could" be that when you "Copy" html to your bootstrap Model, all javascript/jquery events attached to any element inside that html copied will be lost! The only way you can re-call/retain any events attached is when you Move/Append the elements from one object to another. So, what I would do is ONLY after you copy the HTML to the bootstrap model, you should then allocate EVENTS to specifically those elements inside the model. Let me know if that helps... – Morgs May 08 '15 at 09:53
  • Have you checked the position of the Modal? I did this exact same thing and found the Bootstrap modal was being appended to the body instead of being appended to the Form. If the controls are not in the Form for Asp.net, it won't postback and call the server side function. When I encountered this, I had to append the modal to the form as it was opened. – Daved May 08 '15 at 20:38
  • To piggy back and on my post and clear confusion: The events of a .NET server control are bound using attributes on the element. Thus, if you duplicate or move, copy, clone, or manipulate the DOM elements without specifically removing attributes, their default .NET behavior will apply. They are not like DOM elements bound with handlers using jQuery where the handler could be lost. – Daved May 08 '15 at 20:42
  • hi @Daved thanks. all the items are regenerate with different ID (Even postback, it use back the same unique ID. i have checked, the modal is inside the FORM. (remark: this is under updatepanel as well) – Min Hong Tan May 09 '15 at 06:17
  • For a test, have you tried disabling the Bootstrap modal and just having the modal content display in the bottom of the Updatepanel? This would at least enable to test the functionality of the Audit History content without the modal component to narrow it down. – Daved May 11 '15 at 15:09
  • yes @Daved working perfectly. but the problem is solved by using imagebutton/button instead of linkbutton. (FYI , no problem in normal layout inside updatepanel by using linkbutton). – Min Hong Tan May 12 '15 at 02:17
  • I've set all modal windows to post to a webservice rather than post back to resolve similar problems. – brendo234 Mar 02 '17 at 22:10

5 Answers5

1

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 :)

Tasos K.
  • 7,669
  • 7
  • 38
  • 57
prashantchalise
  • 321
  • 4
  • 11
0

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.

DaniDev
  • 2,060
  • 19
  • 28
0

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

Community
  • 1
  • 1
Zeeshan Umar
  • 492
  • 2
  • 6
  • 12
0

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>
RezaGhahari
  • 356
  • 2
  • 9
0

This the following inside pageload:

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