我原的按键加了一个确认窗口:
string strPrompt = ...;
btnApply.Attributes.Add("onclick","return confirm('" + strPrompt + "');"); btnApply服务器按钮还有服务器端的ON CLICK事件后来,我为了防止多次按下,改成了
btnApply.Attributes.Add("onclick","window.document.all('btnApply').disabled=true;if(confirm('" + strPrompt + "')){return true;} else{window.document.all('btnApply').disabled=false; return false;}");为什么我这个按键的服务器端的ONCLICK事件激发不了了?
多谢!
string strPrompt = ...;
btnApply.Attributes.Add("onclick","return confirm('" + strPrompt + "');"); btnApply服务器按钮还有服务器端的ON CLICK事件后来,我为了防止多次按下,改成了
btnApply.Attributes.Add("onclick","window.document.all('btnApply').disabled=true;if(confirm('" + strPrompt + "')){return true;} else{window.document.all('btnApply').disabled=false; return false;}");为什么我这个按键的服务器端的ONCLICK事件激发不了了?
多谢!
解决方案 »
- 怎么整合别人写好的留言本到自己的网站中??
- 请问怎样隐藏iframe的滚动条,并且iframe的高度随子页面的高度增减而增减
- 如何在动态库中调用ClientScript.RegisterStartupScript
- 白白的问题
- DataBind问题
- 有没有aspnet与access,显示,修改,删除,添加,分页的例子或者是dll应用的公共类啊?
- asp.net 数据绑定
- asp.net中的Newtonsoft.Json.dll 是干什么的呀
- 請問水晶報表中﹐報表標題是怎么給值的
- 分不多了,求脚本控制输入数字的写法
- 关于Windows服务的问题??????????
- 关于TreeView不能正常显示的问题
string strPrompt = "...";
if (!IsPostBack)
{
btnApply.Attributes.Add("onclick","return _confirm(" + strPrompt + ");");
}客户端:
<script language="javascript">
function _confirm(str)
{
window.document.all('btnApply').disabled = true;
if (confirm(str))
{
return true;
}
else
{
window.document.all('btnApply').disabled = false;
return false;
}
return false;
}
</script>
和我原先的一样,
如果点击取消,则被禁止的按钮又还原了,但点击确认后,按钮是被禁用了,可是我服务器端的点击代码btnApply_Click没有被触发? 真是晕~~
但我的提交按钮是服务器的控件,不是HTML的submit按钮
所以现在提交到SERVER时只能进入Page Load, 进不到我的btnApply_Click
请问怎么提交服务器端的按钮呢?
<input type="hidden" name="__EVENTTARGET">
<input type="hidden" name="__EVENTARGUMENT">2、javascript追加以下方法:
function __doPostBack(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
{
theform = document.forms["Form1"];
}
else
{
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}请确认以上内容是否已经存在,如果存在,就不用再追加了。把submit改为:
__doPostBack("btnApply","");
aspx:function __doPostBack(eventTarget, eventArgument)
{
var theform;
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
{
theform = document.forms["Form1"];
}
else
{
theform = document.Form1;
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
function _confirm(str)
{
window.document.all('btnApply').disabled = true;
if (confirm(str))
{
// document.Form1.submit();
document.Form1.__doPostBack("btnApply","");
return true;
}
else
{
window.document.all('btnApply').disabled = false;
return false;
}
} <INPUT style="Z-INDEX: 107; LEFT: 0px; WIDTH: 48px; POSITION: absolute; TOP: 512px; HEIGHT: 24px" type="hidden" value="Button" name="__EVENTTARGET">
<INPUT style="Z-INDEX: 108; LEFT: 48px; WIDTH: 48px; POSITION: absolute; TOP: 512px; HEIGHT: 24px" type="hidden" value="Button" name="__EVENTARGUMENT">
aspx.cs:btnApply.Attributes.Add("onclick", "return _confirm('" + strPrompt + "');");连page load也进不去了:(
改为:
__doPostBack("btnApply","");
<INPUT style="Z-INDEX: 108; LEFT: 48px; WIDTH: 48px; POSITION: absolute; TOP: 512px; HEIGHT: 24px" type="hidden" value="Button" name="__EVENTARGUMENT">改为:
放在form中:
<input type="hidden" name="__EVENTTARGET">
<input type="hidden" name="__EVENTARGUMENT">
使用警告、提示和确认
可以使用警告、确认和提示消息框来获得用户的输入。这些消息框是 window 对象的接口方法。由于 window 对象位于对象层次的顶层,因此实际应用中不必使用这些消息框的全名(例如 "window.alert()"),不过采用全名是一个好注意,这样有助于您记住这些消息框属于哪个对象。警告消息框
alert 方法有一个参数,即希望对用户显示的文本字符串。该字符串不是 HTML 格式。该消息框提供了一个“确定”按钮让用户关闭该消息框,并且该消息框是模式对话框,也就是说,用户必须先关闭该消息框然后才能继续进行操作。 window.alert("欢迎!请按“确定”继续。");
确认消息框
使用确认消息框可向用户问一个“是-或-否”问题,并且用户可以选择单击“确定”按钮或者单击“取消”按钮。confirm 方法的返回值为 true 或 false。该消息框也是模式对话框:用户必须在响应该对话框(单击一个按钮)将其关闭后,才能进行下一步操作。 var truthBeTold = window.confirm("单击“确定”继续。单击“取消”停止。");
if (truthBeTold) {
window.alert("欢迎访问我们的 Web 页!");
} else window.alert("再见啦!");
提示消息框
提示消息框提供了一个文本字段,用户可以在此字段输入一个答案来响应您的提示。该消息框有一个“确定”按钮和一个“取消”按钮。如果您提供了一个辅助字符串参数,则提示消息框将在文本字段显示该辅助字符串作为默认响应。否则,默认文本为 "<undefined>"。 与alert( ) 和 confirm( ) 方法类似,prompt 方法也将显示一个模式消息框。用户在继续操作之前必须先关闭该消息框 var theResponse = window.prompt("欢迎?","请在此输入您的姓名。");
进不了我的
private void btnApply_Click(object sender, System.EventArgs e)
真是好奇怪~
<form id="Form1" method="post" runat="server">
<input type="hidden" name="__EVENTTARGET">
<input type="hidden" name="__EVENTARGUMENT">
...
</from>2、确认form的id是否和function __doPostBack(eventTarget, eventArgument) 中的一致:
if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
{
theform = document.forms["Form1是form的id"];
}
else
{
theform = document.Form1是form的id;
}
<form id="Form1" method="post" runat="server">
...
</form>
btnApply.Attributes.Add("onclick", "return _confirm('" + strPrompt + "');");
为
btnApply.Attributes.Add("onclick", "_confirm('" + strPrompt + "');");修改_confirm(str)方法为:
function _confirm(str)
{
window.document.all('btnApply').disabled = true;
if (confirm(str))
{
__doPostBack("btnApply","");
}
else
{
window.document.all('btnApply').disabled = false;
}
}