62,074
社区成员
发帖
与我相关
我的任务
分享
private void cmdOk_Click(object sender, System.EventArgs e)
{
string Script = "if (confirm(\"該導師在該班別開班這天: " + strsd + ", 有其它課程要上\")) {document.getElementById('hidcount').innerText='1';}"; //如果点确定,就把hidcount的值赋为1
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "DeleteData", Script, true);
if (hidcount.Value == "1") {
msgbox.Text = "1"; //为什么我按确定的时候,msgbox.Text不显示1,等到我再点击cmdOk,再postback一次后才看到msgbox.Text显示1?
}
else {
return;
}
}
还有什么更好的办法,在服务器端返回confirm返回的结果。然后根据这个结果去做一些事?
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
.............
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Button" Style="display: none" /></ContentTemplate>
</asp:UpdatePanel>
protected void Button1_Click(object sender, EventArgs e)
{
string Script = "if (confirm(\"該導師在該班別開班這天, 有其它課程要上\")) " +
ClientScript.GetPostBackEventReference(this.Button2, string.Empty) + ";";
ScriptManager.RegisterStartupScript(Button1, Button1.GetType(), "confirm", Script, true);
}
protected void Button2_Click(object sender, EventArgs e)
{
//继续处理接下来的任务
}
this.cmdOk.Attributes.Add("onclick", "return getconfirmvalue('" + strsd + "');");
function getconfirmvalue(strsd)
{
if (confirm(\"該導師在該班別開班這天: " + strsd + ", 有其它課程要上\"))
{
{document.getElementById('hidcount').innerText='1';}";
return true;
}
return false;
}