加载父页面时,会自动调用用户控件中的按钮单击事件吗?

时间:2013-04-17 03:23:26

标签: c# asp.net

我有一个页面parent.aspx,其中包含一个用户控件csForm.ascx。这个用户控件只是一个简单的表单,最后有一个发送按钮。我还使用Modal Popup Extender中的AjaxToolKit来显示表单。

Parent.aspx

<asp:ScriptManager runat="server" ID="scmg" />
<ajaxToolkit:ModalPopupExtender ID="mdlPopup" runat="server" 
TargetControlID="btnCS" PopupControlID="csForm$pnlPopup"
BackgroundCssClass="modalBackground" OkControlID="csForm$btnSend" 
CancelControlID="csForm$imgBtnClose" PopupDragHandleControlID="csForm$pnlPopup" 
Drag="true" DropShadow="true" />

csForm.ascx.cs

protected void btnSend_Click(object sender, EventArgs e)
{
    sendEmail(); //this gets automatically called when parent page is loaded. 
}

我遇到的问题是在加载parent.aspx页面时会自动调用sendEmail()。有办法阻止吗?我只想在点击Send按钮时调用它。

1 个答案:

答案 0 :(得分:0)

protected void btnSend_Click(object sender, EventArgs e)
{
    if(IsPostBack)
    {
        sendEmail(); //this gets automatically called when parent page is loaded. 
    }
}

这不是正确的解决方案,但会解决这个问题。