Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
I want to open ModalPopUp on button click

My code is
ASP.NET
                       <asp:Button runat="server" ID="btnAdd"  Text="Add"
                           CausesValidation="false" AutoPostBack="True" OnClick="btnAdd_Click" />
                       <ajaxToolkit:ModalPopupExtender Enabled="false"  runat="server" ID="MPEAddNew" TargetControlID="btnAdd"
                           CancelControlID="btncancel" BackgroundCssClass="modalBackground" PopupControlID="popUpPanel">
                       </ajaxToolkit:ModalPopupExtender>
                       <br />
                       <asp:Panel ID="popUpPanel" runat="server" CssClass="modalPopup" Visible="false">
                           <table width="100%" border="1">
                               <tr>
                                   <td colspan="2">
                                       <div class="dvTitle">
                                           Modal Pop Up</div>
                                   </td>
                               </tr>
                               <tr>
                                   <td align="left">
                                       <div  style="height: auto">
                                           <table>

                                               <tr>
                                                   <td style="text-align: left">
                                                       <asp:Label ID="Label2" runat="server" Text="Bank" /><asp:Label runat="server" ForeColor="Red">*</asp:Label>
                                                   </td>
                                                   <td style="text-align: left">
                                                       <asp:UpdatePanel runat="server" ID="udpddlBank" >
                                                           <ContentTemplate>
                                                               <asp:DropDownList runat="server" ID="ddlBank"
                                                                   AutoPostBack="true">
                                                               </asp:DropDownList>
                                                               <asp:RequiredFieldValidator ID="rfvBank" runat="server" ControlToValidate="ddlBank"
                                                                   ValidationGroup="frmDFSOInfo" ErrorMessage="Bank Required" CssClass="fa text-red"
                                                                   SetFocusOnError="True" InitialValue="0" Display="Dynamic"></asp:RequiredFieldValidator>
                                                          </ContentTemplate>

                                                       </asp:UpdatePanel>
                                                   </td>
                                               </tr>
<tr>

                                                   <td>
                                                       <asp:Button ID="btncancel" runat="server"  Text="Cancel"
                                                           />
                                                   </td>
                                               </tr>
                                           </table>
                                       </div>
                                   </td>
                               </tr>

                           </table>
                       </asp:Panel>
                   </ContentTemplate>

               </asp:UpdatePanel>


c#

After page load when I click on Add button first it bind ddlBank.
And then I select bank and click on cancel button further click on Add button (Here event does not fire)

What I have tried:

C#
protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {        
           
            ddlBank.Items.Add(new ListItem("SELECT ONE","0"));
            ddlBank.Items.Add(new ListItem("INDIAN OVER SEAS BANK","1"));
            ddlBank.Items.Add(new ListItem("STATE BANK OF INDIA","2"));
            MPEAddNew.Show();
            MPEAddNew.Enabled = true;
            popUpPanel.Visible = true;
}
Posted
Updated 17-Apr-16 19:32pm
v2
Comments
[no name] 13-Apr-16 6:36am    
Can you elaborate more. your question is not clear.
Member 7909353 13-Apr-16 6:41am    
when I click Add button first time it shows modalpopup and Bind Items to drop down list and then I hide modalpopup by clicking on cancel button it hide.
After above steps I click on add button it does fire event
[no name] 13-Apr-16 6:51am    
What code you have write on the cancel button?
Is it $('#modal').hide() or $('#modal').modal('hide');
Member 7909353 13-Apr-16 7:19am    
No! I specify in ModalPopUp CancelControlID="btncancel"
Rojalin Sahoo 13-Apr-16 8:11am    
did your modalpopupControl is within update panel? You could use style="display:none;" for PopupPanel instead of visible attribute, so that popUpPanel.Visible = true; will not be needed on code-behind.

1 solution

On calncle button click

C#
            MPEAddNew.Hide();
            MPEAddNew.Enabled = false;
            popUpPanel.Visible = false;
// and clear all fields
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900