页面上有个<asp:Button ID="btnShowMess" Text="弹出提示框" runat="server" OnClick="btnShowMess_Click" />
后台代码
public void btnShowMess_Click(object sender, EventArgs e)
{
//.......
}
要求在页面上弹出一个提示框,页面不刷新。
ClientScript.RegisterStartupScript(GetType(), "", "alert('提示');", true);
Response.Write("<script>alert('提示');history.go(-1);</script>");
按钮.Attributes. ...
调用前台JS
统统试过不行。
分不多了,30分裸发,谢谢大大们了,结束我纠结的日子吧。
后台代码
public void btnShowMess_Click(object sender, EventArgs e)
{
//.......
}
要求在页面上弹出一个提示框,页面不刷新。
ClientScript.RegisterStartupScript(GetType(), "", "alert('提示');", true);
Response.Write("<script>alert('提示');history.go(-1);</script>");
按钮.Attributes. ...
调用前台JS
统统试过不行。
分不多了,30分裸发,谢谢大大们了,结束我纠结的日子吧。
解决方案 »
- c# win 父窗口 随 子窗口 最小最大化变化而变化
- DevExpress的ASPxTreeList导出xls的问题
- 一个水晶报表的问题
- 大家帮我看看这个循环修改DataTable的代码
- C#中,序列化 可为空枚举 为XML属性 问题?
- (100分求解)通过GetManifestResourceStream方法加载资源文件的问题
- 我一个界面有两个TextBox为什么不能同时绑定日期控件?
- 来来来,初学者问个小问题,一个小时就结了
- 未能找到类型或命名空间名称“User”(是否缺少 using 指令或程序集引用?)
- C#和VBScript结合问题
- 关于SocketAsyncEventArgs
- C#编程:关于“输入字符串的格式不正确”问题
如confirm
我要用asp控件提交数据,出错时前台弹出提示,这种情况下,不是仅仅用前台的一个JS
Response.Write 这个肯定是要刷新的.
Attributes , 这个可以. 他应该不刷新, 让他调用前台JS. 还有一个办法 就是, 走事前前 先走前台判断下. 写法下面
onsubmit="CheckData(); 写在前台from 意思说所有buteen 安扭都走这个方法, 然后你判断
function CheckData()
{ // Button2 按纽ID名
if(document.activeElement.id== "Button2")
{
document.all("txtLoginID").focus();
alert("用户名不能为空,请重新输入!");
event.returnValue=false; //结束事件
return; //停下
}}
<asp:Button ID="btnShowMess" Text="弹出提示框" runat="server" OnClientClick="return test()" />在页面加一个Button隐藏之,用于在弹出框上按确定时执行的后台代码,代码:
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" style="display:none;" />js:
<script type="text/javascript">
function test() {
if (confirm("是否"))
document.getElementById("Button2").click();//执行Button2_Click事件下
else
return false;//不回发
}
</script>
UpdatePanel的话我就不用了,这地方不适合。至于aJax方法我坦言真的不会,百度、谷歌也没找到例子,就差问警察叔叔了。谢谢你了O(∩_∩)O~
<html>
<head>
<title></title> <script type="text/javascript" language="javascript">
function sAlert(str){
var msgw,msgh,bordercolor;
msgw=400;//提示窗口的宽度
msgh=100;//提示窗口的高度
titleheight=25 //提示窗口标题高度
bordercolor="#c51100";//提示窗口的边框颜色
titlecolor="#c51100";//提示窗口的标题颜色
var sWidth,sHeight;
sWidth=screen.width;
sHeight=screen.height;
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#cccccc";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
//建的新层
var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
//右上角的关闭按钮
var title=document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.innerHTML="关闭";
title.onclick=function(){
document.body.removeChild(bgObj);
document.getElementById("msgDiv").removeChild(title);
document.body.removeChild(msgObj);
}
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(title);
var txt=document.createElement("p");
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.innerHTML=str;
document.getElementById("msgDiv").appendChild(txt);
}
</script></head>
<body>
<br />
<br />
<input type="button" value="点击这里" onclick="sAlert('test弹窗效果');" />
</body>
</html>
<head>
<title></title>
<script type="text/javascript" language="javascript">
function sAlert(str){
var msgw,msgh,bordercolor;
msgw=400;//提示窗口的宽度
msgh=100;//提示窗口的高度
titleheight=25 //提示窗口标题高度
bordercolor="#c51100";//提示窗口的边框颜色
titlecolor="#c51100";//提示窗口的标题颜色
var sWidth,sHeight;
sWidth=screen.width;
sHeight=screen.height;
var bgObj=document.createElement("div");
bgObj.setAttribute('id','bgDiv');
bgObj.style.position="absolute";
bgObj.style.top="0";
bgObj.style.background="#cccccc";
bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
bgObj.style.opacity="0.6";
bgObj.style.left="0";
bgObj.style.width=sWidth + "px";
bgObj.style.height=sHeight + "px";
bgObj.style.zIndex = "10000";
document.body.appendChild(bgObj);
//建的新层
var msgObj=document.createElement("div")
msgObj.setAttribute("id","msgDiv");
msgObj.setAttribute("align","center");
msgObj.style.background="white";
msgObj.style.border="1px solid " + bordercolor;
msgObj.style.position = "absolute";
msgObj.style.left = "50%";
msgObj.style.top = "50%";
msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
msgObj.style.marginLeft = "-225px" ;
msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
msgObj.style.width = msgw + "px";
msgObj.style.height =msgh + "px";
msgObj.style.textAlign = "center";
msgObj.style.lineHeight ="25px";
msgObj.style.zIndex = "10001";
//右上角的关闭按钮
var title=document.createElement("h4");
title.setAttribute("id","msgTitle");
title.setAttribute("align","right");
title.style.margin="0";
title.style.padding="3px";
title.style.background=bordercolor;
title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
title.style.opacity="0.75";
title.style.border="1px solid " + bordercolor;
title.style.height="18px";
title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
title.style.color="white";
title.style.cursor="pointer";
title.innerHTML="关闭";
title.onclick=function(){
document.body.removeChild(bgObj);
document.getElementById("msgDiv").removeChild(title);
document.body.removeChild(msgObj);
}
document.body.appendChild(msgObj);
document.getElementById("msgDiv").appendChild(title);
var txt=document.createElement("p");
txt.style.margin="1em 0"
txt.setAttribute("id","msgTxt");
txt.innerHTML=str;
document.getElementById("msgDiv").appendChild(txt);
}
</script></head>
<body>
<br />
<br />
<input type="button" value="点击这里" onclick="sAlert('test弹窗效果');" />
</body>
</html>
public static void Alert(string msg, Page webPage)
{
string strScript = "";
strScript = ("<script language=javascript>");
strScript += ("alert('" + MessageCue + "');");
strScript += ("</script>");
webPage.ClientScript.RegisterStartupScript(webPage.GetType(), "MsgBox", strScript)
}
上AJAX骗眼睛吧!
O(∩_∩)O~
O(∩_∩)O~
一定要学会使用 ajax 才行啊。
[align=center]********************************************************
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
[/align]
看下教程
可以直接通过ajax调用后台的方法,一切就OK了啊
本内容用 CSDN小秘书 回复
每天回帖即可获得10分可用分!
********************************************************
真的假的呀。饿