javascript - Open modal Popup on pageload event from server side using c# -
i want show modal popup on certain condition on page load event working.
this modalpopup:
<script type="text/javascript"> function openmodal(message, header, url) { $('#mymodal').modal('show'); $('#lblmastermessage').html(header); $('#lblmasterbodymessage').html(message); $('#mymodal').on('hidden.bs.modal', function(e) { if (url != '') { window.location = url; } }); } </script> <asp:content id="content2" contentplaceholderid="bodycontentplaceholder" runat="server"> <div class="modal fade" id="mymodal" runat="server"> <div class="modal-dialog"> <div class="modal-content" style="width: 400px; margin: 0 auto;"> <div class="modal-header" runat="server"> <button type="button" class="close" data-dismiss="modal" aria-label="close"> <span aria-hidden="true">×</span></button> <h4 class="modal-title"> <label id="lblmastermessage"></label> </h4> </div> <div class="modal-body"> <label id="lblmasterbodymessage"></label> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" data-dismiss="modal" runat="server">close</button> </div> </div> </div> </div> </asp:content> calling modal popup backend:
protected void page_load(object sender, eventargs e) { if (dt.rows.count > 0) { bindgrid(); } else { string message = "files not generated!"; string header = "info"; scriptmanager.registerstartupscript(this, this.gettype(), "popup","openmodal('" + message + "','" + header + "','memberhomepage.aspx');", true); //scriptmanager.registerstartupscript(this, this.gettype(), "popup", "alert('business operation files not generated!'); window.location ='memberhomepage.aspx';", true); } } i not able show popup when condition satisfied. appreciated.
div represents modal runs on server, asp.net generate it's id. means that, when page rendered, modal's id not mymodal ctl00_content2_mymodal.
because of that, jquery cannont find div on line
$('#mymodal').modal('show'); change line
$('#<%= mymodal.clientid %>').modal('show'); or try access div class name, $(".modal")
edit: you'll have same problem other controls you're trying find id, such lblmastermessage, lblmasterbodymessage etc.
Comments
Post a Comment