In my task i have to create ModalPopupExtender dynamically, and add an .ascx control to it. This is the code:
Test.aspx page:
<
asp:ScriptManagerProxyrunat="server"ID="proxy"/><
asp:UpdatePanelrunat="server"ID="ajaxPanel"RenderMode="Inline"UpdateMode="Conditional"><ContentTemplate><asp:Panelrunat="server"ID="panel"><asp:Buttonrunat="server"ID="btn2"Text="Show Control"OnClick="btn2_Click"/></asp:Panel><%
--<asp:Button runat="server" ID="btn1" Text="test1" OnClick="btn1_Click" />--%></ContentTemplate></asp:UpdatePanel>
test.ascx control:
<
asp:ScriptManagerProxyrunat="server"ID="proxy"/><
asp:UpdatePanelrunat="server"ID="ajaxPanel2"RenderMode="Inline"UpdateMode="Always"><ContentTemplate> <asp:Buttonrunat="server"ID="btnTest2"Text="test2"OnClick="btnTest2_Click"/></ContentTemplate></asp:UpdatePanel><asp:Buttonrunat="server"UseSubmitBehavior="false"ID="btnTest"Text="Close OK"OnClick="btnTest_Click"/><asp:Buttonrunat="server"UseSubmitBehavior="false"ID="btnTestClose"Text="Close"OnClick="btnTest_Click"/>
In aspx page:
protected
overridevoid OnInit(EventArgs e){
base.OnInit(e);Control c = LoadControl("~/test.ascx");c.ID =
"customModalControl";Panel p =newPanel();p.Width = 300;
p.Height = 200;
p.CssClass =
"modalPopup";p.ID =
"modalPanel_";_modalPopup =newModalPopupExtender();_modalPopup.ID =
"modalPopup";_modalPopup.DropShadow =
true;_modalPopup.BackgroundCssClass ="modalBackground";
_modalPopup.PopupControlID = p.ID;
_modalPopup.TargetControlID = btn2.ID;
Control c2 = c.FindControl("btnTest");
_modalPopup.OkControlID = c2.ClientID;
c2 = c.FindControl("btnTestClose");
_modalPopup.CancelControlID = c2.ClientID;
p.Controls.Add(c);panel.Controls.Add(_modalPopup);
panel.Controls.Add(p);
}
protectedvoid btn1_Click(object sender,EventArgs e){
}
protectedvoid btn2_Click(object sender,EventArgs e)
{
_modalPopup.Show();
}
onInit event, i create ModalPopupExtender and a panel for ascx control. All works fine, but is one problem, when i click btnTest2 on ModalPopup, rises postback for the page, but ascx control didn't receive btnTest2 _OnClick event. Maybe someone know where is a problem. Thank you.
Try to change change some of your codes to specify asynchronous post back.<asp:UpdatePanel runat="server" ID="ajaxPanel2" RenderMode="Inline" UpdateMode="Always">
<ContentTemplate>
??????<asp:Button runat="server" ID="btnTest2" Text="test2" OnClick="btnTest2_Click"/>
</ContentTemplate>
<triggers>
????<asp:AsyncPostBackTrigger ControlID="btnTest2" EventName="Click"/>
</triggers>
</asp:UpdatePanel>
Wish this can help you.
No comments:
Post a Comment