Hi, having some problem...Plz help me out from this

I have problem in ModalPopupExtender. When I click on submit button of pop up it does not call the code behind code written for button click.. Here is my code-

<ajaxtoolkit:modalpopupextender id="ModalPopupExtender" runat="server"
cancelcontrolid="LinkButton1" dropshadow="false" okcontrolid="btnSubmit" X="200" Y="100" popupcontrolid="Panel1" targetcontrolid="imgSchedul">
<aspanel id=Panel1 runat="server" style="display:none;">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="SubmitData" ValidationGroup="MainValidation"/>
</aspanel>

protected void SubmitData(object sender, EventArgs e)
{
//code for submit data.
}

I have written onclick event for btnSubmit in code behind file. Now my problem is, this event is not firing when I click Submit Button on Panel.

Dani AI

Generated

your workaround (clicking a hidden server button from JS) will work, but you usually don’t need the extra indirection. When a ModalPopup button click does nothing, it’s almost always one of these:

  • Validation cancels the postback. Your submit has ValidationGroup="MainValidation". If any validator in that group (even outside the popup) is invalid, the click is blocked on the client and the server event never fires. Fix by giving the popup its own group (for example, ModalOnly) or set CausesValidation="false" on that button if you do not want validation there.
  • OkControlID suppresses your postback. If you set OkControlID on the extender and also have client script that returns false, or validation fails, the click only hides the popup. Easiest test: remove OkControlID and handle the server OnClick; after a successful save call mpe.Hide() in code-behind.
  • UpdatePanel wiring. If the popup lives inside an UpdatePanel with UpdateMode="Conditional", add an AsyncPostBackTrigger for the submit button (or ensure the button is inside the same panel). Also make sure there is exactly one <form runat="server"> and a ScriptManager on the page or master.

A minimal pattern that avoids the above:

<asp:UpdatePanel ID="upModal" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
    <asp:Panel ID="pnlModal" runat="server" Style="display:none">
      <!-- modal fields -->
      <asp:Button ID="btnModalSubmit" runat="server"
          Text="Submit"
          OnClick="ModalSubmit_Click"
          ValidationGroup="ModalOnly" />
    </asp:Panel>
  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="btnModalSubmit" EventName="Click" />
  </Triggers>
</asp:UpdatePanel>
<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server"
    TargetControlID="imgSchedul" PopupControlID="pnlModal" />
protected void ModalSubmit_Click(object sender, EventArgs e) {
    if (!Page.IsValid) { mpe.Show(); return; }  // keep popup open on errors
    // save...
    mpe.Hide();  // close after success
}

This keeps server events firing reliably without needing a client-only button.

hi got it...

The following code works , wherein I am calling button click of a server side button through client side code .

Check out this code :-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ParentPage.aspx.cs" Inherits="ParentPage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
    function pageLoad()
    {
        $addHandler($get('btn1') , 'click' , onClick);
    }

    function onClick() // this onclick event is for cleint side input button
    {
        $get('btn').click(); // here i am calling the server side click event of asp:button with id 'btn'
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="Script1"></asp:ScriptManager>
    <div>
    <asp:TextBox runat="server" ID="txtTrial"></asp:TextBox>
    <input type="button" id="btn1" runat="server" value="Client Button" />
    <asp:Button runat="server" ID="btn" Text="Server button" OnClick="btn_Click" />
    </div>
    </form>
</body>
</html>


protected void btn_Click(object sender, EventArgs e) // server side click event of asp button
    {
///ur code
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.