我有一个打开模态弹出窗口的按钮,但在打开模态弹出窗口之前,我想要我的" OnClick" " btnSaveAndScheduleTask"按钮开火。我使用的是ASP.NET 4.5 / Visual Studio 2012 / HTML5 / CSS3
我的aspx(snipet):
如何为我的" btnSaveAndScheduleTask"获取代码隐藏OnClick事件?按钮开火?如果整个代码有助于解决问题,请告诉我,但我可能遗漏了一些简单的东西(请记住,我希望能够从C#代码隐藏中查看我的所有asp控件):
<asp:Button ID="btnSaveAndScheduleTask" runat="server" CausesValidation="true"
OnClientClick="javascript:return validatePage();" OnClick="btnSaveAndScheduleTask_Click"
Font-Bold="true" Text="Schedule Task" />
<ajaxToolkit:ModalPopupExtender ID="mpeScheduleTask" runat="server" ValidateRequestMode="Enabled"
BackgroundCssClass="modalBackground" CancelControlID="btnCancSchedule"
PopupControlID="pnlScheduleTask" TargetControlID="btnSaveAndScheduleTask" DropShadow="true" >
</ajaxToolkit:ModalPopupExtender>
<div id="divScheduleTask" runat="server">
<asp:Panel ID="pnlScheduleTask" Height="310" Width="690" BackColor="#ece4e1" ForeColor="Black" runat="server" >
<asp:UpdatePanel runat="server" ID="udpScheduleTask" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTaskSch" Visible="false" Font-Bold="true" Text="Task Scheduling: " runat="server" />
<asp:Button ID="btnSaveSchedule" runat="server" OnClick="btnSaveSchedule_Click" Text="Save Schedule" />
</div><asp:Button ID="btnCancSchedule" runat="server" Text="Canc" />
</ContentTemplate></asp:UpdatePanel></asp:Panel></div>
我遗漏了大部分小组,因为它很大......这是我的validatePage()Javascript:
<script type="text/javascript">
function validatePage() {
//Executes all the validation controls associated with group1 validaiton Group1.
var flag = window.Page_ClientValidate('vTask');
if (flag)
//Executes all the validation controls which are not associated with any validation group.
flag = window.Page_ClientValidate();
if (!Page_IsValid) {
$find('mpeScheduleTask').hide();
}
return flag;
}
</script>
我的aspx.cs代码背后:
protected void btnSaveAndScheduleTask_Click(object sender, EventArgs e)
{
//do stuff
}
答案 0 :(得分:2)
删除TargetControlID =“btnSaveAndScheduleTask”,给出其他虚拟控件的ID 因此,当按钮点击时,单击将把用户带到服务器,在后面的代码中你需要手动打开弹出窗口。
这里给出了...... !!!!
http://www.codeproject.com/Tips/215040/ModalPopupExtender-from-Server-Side-Code
答案 1 :(得分:1)
我会在你的按钮点击后面的代码中调用javascript。
protected void btnSaveAndScheduleTask_Click(object sender, EventArgs e)
{
// do stuff.
Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "validatePage();", true);
}
这就是我最常做的事情。希望这可以帮助。
你的ASP看起来应该是......
<asp:Button ID="btnSaveAndScheduleTask" runat="server" CausesValidation="true" OnClick="btnSaveAndScheduleTask_Click" Font-Bold="true" Text="Schedule Task" />