0
我的網頁上有一個OnClick事件按鈕。在C中的按鈕OnClick事件之間調用javascript
<asp:TextBox ID="tbMailID" runat="server" Width="250px"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" OnClick="btnSubmit_Click" Text="Submit" />
C#代碼:
protected void btnSubmit_Click(object sender, EventArgs e)
{
bool IsGmail = CheckMailId(tbMailID.Text);
if(!IsGmail)
{
string strScript = "confirm('Mail id is not from gmail, do you still want to continue?');";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);
}
SendMail();
}
頁接受文本郵件ID並提交發送郵件。 但是,如果mail-id不是gmail id(由CheckMailId驗證),我想根據Yes/No clicked來向用戶顯示一個確認框,確定他/她是否想要獲得郵件。
但是,在提交提交事件併發送郵件後,javascript將會調用。 如果我添加一個返回的SendMail()將永遠不會調用
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "strScript", strScript, true);
return;
什麼能在這裏一個可能的解決方案?
注意:所發佈的代碼是我真正用例的簡化版本。 CheckMailId - 僅僅是一個顯示的名字,它調用了很多其他的函數,並且做了很少的db進程。因此,在JavaScript中,我想避免。
這不會調用服務器端'CheckMailId()' – Rhumborl 2014-11-21 11:54:56
您可以檢查它在Javascript的功能太... – yash 2014-11-21 11:56:18
我已編輯我的答案... @Rhumborl – yash 2014-11-21 12:01:26