服务器端怎样触发客户端事件

xumingit 2007-04-16 09:44:22
服务器端怎样触发客户端事件?
我在服务器端要同过,选择的值来判断出发哪个弹出窗口。
应该怎么做。
例如:我通过选择是学生or老师
来分别触发:xuesheng()和laoshi()这两个弹出窗口。
...全文
229 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
chfzhb 2007-04-16
  • 打赏
  • 举报
回复
回发就行, 我用过n次了。
jxdyzwh 2007-04-16
  • 打赏
  • 举报
回复
delBttn.Attributes.Add("onclick","javascript:return confirm('确定删除?');");
sos110 2007-04-16
  • 打赏
  • 举报
回复
先回答你的第一个问题,服务器是不可能触发客户端事件的,因为http协议是通过请求,响应来实现的,只有你客户请求,服务器才能响应,他不请求,服务器根本都不知道客户的存在,又怎么能触发事件呢?微软把这个过程隐藏的太不容易发现了。
你想实现这样的功能,可以用客户端的脚本来实现。比如js,当你在页面选择后,js来打开窗口,甚至是请求服务器
=============================================================================
.net技术交流群 QQ:8793209,欢迎职业的程序员加入讨论交流!
jimu8130 2007-04-16
  • 打赏
  • 举报
回复
public static void popUpWindow(System.Web.UI.Page mypage,string YesURL,int Width,int Height)
{
string windowAttribs;
windowAttribs = "dialogHeight: "+Height.ToString()+"px; dialogWidth: "+Width.ToString()+"px;edge: Raised; center: Yes; help: No; resizable: No; status: No; scroll:No;";
string strscript="<script language='javascript'>\n";
strscript += "window.showModalDialog('"+YesURL+"','','"+windowAttribs+"');\n";
strscript += "</script>";
if(!mypage.IsStartupScriptRegistered("ConfirmMsg"))
mypage.RegisterStartupScript("ConfirmMsg", strscript);
}

public static void OpenPopUp(System.Web.UI.WebControls.WebControl opener,string PagePath,string windowName,int Top,int Left,int width,int height)
{
string clientScript;
string windowAttribs;
windowAttribs = "left=" + Left.ToString() + "px," +
"top=" + Top.ToString() + "px," +
"width=" + width.ToString() + "px," +
"height=" + height.ToString() + "px," +
"left='+((screen.width -" + width.ToString()+ ") / 2)+',";
clientScript = "window.open('"+PagePath+ "','"+
windowName + "','"+ windowAttribs + "');return false;";
opener.Attributes.Add("onClick", clientScript);
}
public static void OpenPopUp(System.Web.UI.Page mypage,string PagePath,string windowName,int Top,int Left,int width,int height)
{
string clientScript;
string windowAttribs;
windowAttribs = "left=" + Left.ToString() + "px," +
"top=" + Top.ToString() + "px," +
"width=" + width.ToString() + "px," +
"height=" + height.ToString() + "px," +
"left='+((screen.width -" + width.ToString()+ ") / 2)+',";
clientScript = "<script language='javascript'> window.open('"+PagePath+ "','"+
windowName + "','"+ windowAttribs + "');</script>";
if(!mypage.IsStartupScriptRegistered("PopupWin"))
mypage.RegisterStartupScript("PopupWin", clientScript);
}
chfzhb 2007-04-16
  • 打赏
  • 举报
回复
你用回发啊,用回发不可以吗?
在你的事件上写上
ClientScript.RegisterStartupScript(Me.GetType(), "", "<script language='javascript'>if (confirm('确定??')){document.getElementById('" + Me.EditBtn.ClientID + "').click();} ; </script>")

EditBtn 为客户端的Button, 让它的runnat=server.
然后再EditBtn 的事件上写你要做的事件。
confei 2007-04-16
  • 打赏
  • 举报
回复
建议使用这种方法
kind2.Attributes.Add("onchange", "save_data(this.options[this.selectedIndex].value)")
然后用js实现其他
避免了回发
hstom 2007-04-16
  • 打赏
  • 举报
回复
楼上的说得没错,不过你要在pageload的时候就要添加进去~~~
babyrockxray 2007-04-16
  • 打赏
  • 举报
回复
if(选择学生)
Page.RegisterStartupScript("xuesheng","<script>xuesheng();</script>");
else if(选择老师)
Page.RegisterStartupScript("laoshi","<script>laoshi();</script>");
jolinkyo 2007-04-16
  • 打赏
  • 举报
回复
Button2.Attributes.Add("onclick", "return confirm('你是否确定删除?');")
kind2.Attributes.Add("onchange", "save_data(this.options[this.selectedIndex].value)")

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧