想实现这样的功能
protected void btnOK_Click(object sender, ImageClickEventArgs e)
{
...
if (b>0)
{
弹出yes,no对话框
选择yes-->转到另外一个页面}
选择no-->继续代码
}
...
}
可以实现吗?
发现用JS的框框实现不了这样的呀,你碰到是怎么做的
protected void btnOK_Click(object sender, ImageClickEventArgs e)
{
...
if (b>0)
{
弹出yes,no对话框
选择yes-->转到另外一个页面}
选择no-->继续代码
}
...
}
可以实现吗?
发现用JS的框框实现不了这样的呀,你碰到是怎么做的
建议还是将逻辑尽量写道javascript中,即在Aspx页来实现逻辑,
btnOK控件的onclientclick事件对应的return test()function test()
{
if(confirm("ok"))
{
//
}
else
{ }
}
//if (b>0)
估计此处变量b比较重要,因此,想办法将变量b的值,放到一个hidden控件当中,这样jacascript也能够读这个值了
如果要实现这种功能,只能模拟在btnOK的客户端函数中
if(b>0)// b可从服务器首次载入时取得(如果是动态,可用ajax)
{
if(confirm("aa"))
{
window.location = "另一个页面"
}else
{
document.getElementById("Button1").clcik();//提交页面,执行button1_click的代码}
}
是不是要抛弃系统的CONFIRM框,自己用DIV层去做一个
<script>
function alerts()
{
var b = document.getElementById("txtTest").value;
alert(b)
if(b>0)
{
if(window.confirm())
{
window.location.href="http://www.baidu.com"
}
else
{
window.location.href="http://www.google.com"
}
}
}
</script>
<input type="text" id="txtTest" />
<input type="button" onclick="alerts();" value="text" />
看错了。
以为客户端服务器端可以的protected void btnOK_Click(object sender, ImageClickEventArgs e)
{
//b = this.TextBox1.Text if (Convert.ToInt32(this.TextBox1.Text) > 0)
{
this.Page.ClientScript.RegisterStartupScript(typeof(string),"onclick", "<script>alerts();</script>");
}
else
{
return;
}
} 客户端JS function alerts()
{
if(window.confirm())
{
window.location.href="http://www.baidu.com"
}
else
{
window.location.href="http://www.google.com"
}
}测试成功
<script>
function alerts()
{
var b = document.getElementById("txtTest").value;
alert(b)
if(b>0)
{
if(window.confirm())
{
window.location.href="http://www.baidu.com"
}
else
{
window.location.href="http://www.google.com"
}
}
}
</script>
<input type="text" id="txtTest" />
<input type="button" onclick="alerts();" value="text" />
{
if (strCancelPage == null || strCancelPage.Length == 0)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ConfirmMessage", "<script language=javascript> if (confirm('" + strMessage + "')==true){location.href='" + strOkPage + "';}</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "ConfirmMessage", "<script language=javascript> if (confirm('" + strMessage + "')==true){location.href='" + strOkPage + "';}else{location.href='" + strCancelPage + "';}</script>");
}
}