[英]JavaScript confirm from code behind C#
我在aspx頁面上有一個按鈕。 我要使用javascript確認,然后單擊該按鈕繼續執行。 如果我在aspx頁面本身中編寫javascript,則可以輕松實現。 但是我的問題是每次確認消息可能都不同。 我需要檢查各種條件以生成適當的確認消息。
我可以在我的代碼后面調用確認,以便從那里構造確認消息嗎?
我正在嘗試的是:
protected void Button1_Click(object sender, EventArgs e)
{
//just the algorithm given here
string message=constructMessage(); \\ its just a function to construct the confirm message
if(confirm(message)) // i know i cant use javascript in code behind direct. How can i do this
{
//do something
}
else
{
// do nothing
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string message=
"if(confirm("+message+"))
{
//do something
}
else
{
// do nothing
}";
this.ClientScriptManager.RegisterStartupScript(typeof(this.Page), "warning", message, true);
//Prints out your client script with <script> tags
}
有關ClientScriptManager的更多參考
我剛得到這個鏈接,它描述了調用javascript的不同方法
可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.