C#中有没有类似showModalDialog的东西,或者说c#怎么和Javascript代码进行通信

yesman 2003-02-15 11:26:27
写了很多的东西,特效希望用Javascript来写
但是很多的数据是要从C#中提取的
我现在不会让他们进行通信
请教了
...全文
40 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
nmgrlt 2003-02-18
  • 打赏
  • 举报
回复
用类似以下代码就可以:

Page.RegisterStartupScript("MsgBox", "<script language=javascript> alert('你点击了按钮!')</script>");

格式:
Page.RegisterStartupScript(key, "<script language=javascript>
脚本代码 </script>");
congling 2003-02-17
  • 打赏
  • 举报
回复
1.如果希望结构化比较好(三层结构),可以采用WebService的方法,Ms出了一个WebService.htc,它可以解决你这个问题。但是这种方法你必须提供WebService的服务器段。

2.如果要简单,可以使用不可见的IFrame,有IFrame内的叶面负责数据载入工作。

这样两种方法主要考虑OnClick不会导致叶面重画。



ylm0101 2003-02-15
  • 打赏
  • 举报
回复
this.Response.Redirect("xxx.aspx");
yesman 2003-02-15
  • 打赏
  • 举报
回复
我提供的是一个服务器端的按钮
我希望电击他之后调用一段Javascript代码
并且把运行的结果返回给客户端
Javascript代码调用showModalDialog,谈出另一个叶面
在塔利便可以进行一些操作
congling 2003-02-15
  • 打赏
  • 举报
回复
你说的是客户端IE组件调用的还是ASP.NET的服务器调用?
yarshray 2003-02-15
  • 打赏
  • 举报
回复
<!-- File 1: ShowPopup.html --//>
<HTML>
<HEAD>
<TITLE>Test menus</TITLE>
<SCRIPT SRC="Popup.js"></SCRIPT>
<SCRIPT>
var myMenu = new menu("Test");
var item1 = new menuItem("Hello","http://au.yahoo.com");
var mySub = new menu("Sub menu");
var item2 = new menuItem("Item 2","http://au.yahoo.com");
mySub.addItem(item2);

myMenu.addItem(item1);
myMenu.addItem(mySub);
</SCRIPT>
<STYLE>
.menubuttonovr{
border-top: 1pt solid white;
border-left: 1pt solid white;
border-bottom: 1pt solid gray;
border-right: 1pt solid gray;
cursor: hand;
}

.menubutton{
border: 1pt solid #C0C0C0;
cursor: hand;
}
</STYLE>
</HEAD>
<BODY bgColor="#C0C0C0" onload="doIt()">
<SPAN onclick="myMenu.show(this.offsetLeft+2, this.offsetHeight + this.offsetTop)" CLASS="menubutton">Show It</SPAN>
</BODY>
</HTML>

<!-- File 2: Popup.js //-->
var theParent = null;
function doIt(){
if(document.parentWindow.parent.theParent){
theParent = document.parentWindow.parent.theParent;
}else{
theParent = window;
}
}
var oPopup = createPopup();
var cItem = null;

function menu(Caption){
this.caption = Caption;
this.menuItems = new Array();
this.addItem = addItem;
this.itemType = "MENU";
this.show = showIt;
}

function menuItem(Caption, action){
this.caption = Caption;
this.action = action;
this.itemType = "MENUITEM";
}

function addItem(itm){
this.menuItems[this.menuItems.length] = itm;
}

function unhilite(obj){
if(obj != null){
obj.style.background = "#C0C0C0";
obj.style.color = "black";
}
}

function unhiliteCItem(){
if(cItem != null){
cItem.style.background = "#C0C0C0";
cItem.style.color = "black";
}
}

function hilite(obj){
obj.style.background = "navy";
obj.style.color = "white";
}

function showIt(x,y){
var s = ""; js = "";
for(var i=0; i < this.menuItems.length; i++){
if(this.menuItems[i].itemType == "MENU"){
s += "<SPAN STYLE=\"width: 100%;\" onmouseover=\"oPopup.hide();unhiliteCItem();cItem=this;hilite(this);menu" + i + ".show(this.offsetWidth,this.offsetTop);\">" + this.menuItems[i].caption + "</SPAN>";
js += buildMenuJS(this.menuItems[i],"menu" + i);
}else{
s += "<SPAN STYLE=\"width: 100%;\" onmouseover=\"oPopup.hide();unhilite(cItem);cItem=this;hilite(this);\" onclick=\"theParent.document.location = ('" + this.menuItems[i].action + "')\">" + this.menuItems[i].caption + "</SPAN>";
}
}
oPopup.document.open();
oPopup.document.write("<HTML><HEAD><SCRIPT SRC=\"Popup.js\"></SCRIPT>");
oPopup.document.write("<SCRIPT>\n" + js + "\n</SCRIPT></HEAD>");
oPopup.document.write("<BODY onload=\"doIt()\">" + s + "</BODY></HTML>");
oPopup.document.close();
oPopup.document.body.scroll = "no";
oPopup.document.body.leftMargin = 2;
oPopup.document.body.topMargin = 2;
var theSty = oPopup.document.body.style;
theSty.background = "#C0C0C0";
theSty.borderLeft = "1pt solid white";
theSty.borderTop = "1pt solid white";
theSty.borderBottom = "1pt solid gray";
theSty.borderRight = "1pt solid gray";
oPopup.show(x,y,100,(20*this.menuItems.length)+4,document.body);
}

function buildMenuJS(theMenu, menuName){
var s = menuName + " = new menu('" + theMenu.caption + "');\n";
for(var i=0; i < theMenu.menuItems.length; i++){
if(theMenu.menuItems[i].itemType == "MENUITEM"){
s += menuName + ".addItem(new menuItem('" + theMenu.menuItems[i].caption + "','" + theMenu.menuItems[i].action + "'));\n";
}else{
s += buildMenuJS(theMenu.menuItems[i],menuName + "_" + i);
s += menuName + ".addItem(" + menuName + "_" + i + ");\n";
}
}
return s;
}


服务器端的按钮,可以进入html编辑区中,写onclick事件

这样就可以在客户端调用

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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