All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
在.NET,2.0框架下动态创建Access数据库和表_[Asp.Net教程]
飘浮广告的显示脚本类(VBS,JS双版)_JavaScript技术_编程技术
C#中PerformanceCounter组件应用实例
MS-SQL数据库开发常用汇总_[SQL,Server教程]
数据库的一些常用知识_[SQL Server教程]
asp.net2.0服务器控件之CheckBox控件
Asp.net,备份和还原SQL,Server及压缩Access数据库_.net资料_编程技术
成为PHP高手,学会懒惰地用PHP编程_php资料_编程技术
在C#中动态调用native,dll的导出函数_[Asp.Net教程]
XML字符串和XML DOCUMENT的相互转换_[XML教程]
Reading number is top 10 pictures
Household design of gorgeous series
The money of more than 100 countries and regions17
Sora aoi on twitter3
Sell the barbecue as says father du breul5
Is said to be a Chinese female artist fame explicit pictures before2
女人化妆前后的对比
Fat bird to fly
The little girl with long hair3
这年头,找个靠谱的妹子太难了
The real super beauty1
Download software ranking
VeryCD电驴(EasyMule) V1.1.9 Build09081
Unix video tutorial3
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Kung fu panda - the secret of the teacher
The hero
Tram sex maniac 2 (H) rar bag17
White deer villiage
C#高级编程(第4版)
实战黑客不求人
C++编程教程第三版
delv published in(发表于) 2014/1/27 6:45:16 Edit(编辑)
.net中前台javascript与后台c#相互调用_[Asp.Net教程]

.net中前台javascript与后台c#相互调用_[Asp.Net教程]

.net中前台javascript与后台c#相互调用_[Asp.Net教程]























  .net中C#代码与javaScript函数的相互调用问题。




  问:




  1.如何在JavaScript访问C#函数?




  2.如何在JavaScript访问C#变量?




  3.如何在C#中访问JavaScript的已有变量?




  4.如何在C#中访问JavaScript函数?




  问题1答案如下:




  javaScript函数中执行C#代码中的函数:




  方法一:1、首先建立一个按钮,在后台将调用或处理的内容写入button_click中;




  2、在前台写一个js函数,内容为document.getElementById("btn1").click();




  3、在前台或后台调用js函数,激发click事件,等于访问后台c#函数;




  方法二:1、函数声明为public




  后台代码(把public改成protected也可以)




public string ss()
  {
  return("a");
  }




  2、在html里用<%=fucntion()%>可以调用




  前台脚本







  方法三:1、






  onclick="javascript:__doPostBack('Button1','')">




  方法四:





  function SubmitKeyClick()




  {




  if (event.keyCode == 13)




  {




  event.cancelBubble = true;




  event.returnValue = false;




  document.all.FunName.value="你要调用的函数名";




  document.form[0].submit();




  }




  }




  







  onkeypress="SubmitKeyClick()" id="aaa" type="text">

   〈!--用来存储你要调用的函数 --〉




  在.CS里有:




public Page_OnLoad()
  {
  if (!Page.IsPost())
  {
  string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:"";
  //根据传回来的值决定调用哪个函数
  switch(strFunName)
  {
  case "enter()":
  enter() ; //调用该函数
  break;
  case "其他":
  //调用其他函数
  break;
  default:
  //调用默认函数
  break;
  }
  }
  }
  public void enter()
  {
  //……比如计算某值
  }




  问题2.如何在JavaScript访问C#变量?




  答案如下:




  方法一:1、通过页面上隐藏域访问







  方法二:1、如后台定义了PUBLIC STRING N; 前台js中引用该变量的格式为'<%=n%>'或"+<%=n%>+"




  方法三:1、或者你可以在服务器端变量赋值后在页面注册一段脚本




""




  tmp是后台变量,然后js中可以直接访问temp获得值。




  问题3.如何在C#中访问JavaScript的已有变量?




  答案如下:




  方法一:1、前台使用静态文本控件隐藏域,将js变量值写入其中;2、后台用request["id"]来获取值;




  方法二:可以用cookie或session




  问题4.如何在C#中访问JavaScript函数?




  答案如下:




  c#代码中执行javaScript函数:




  方法一:1、




Page.RegisterStartupScript("ggg"," ");




  方法二:使用Literal类,然后




private void Button2_Click(object sender, System.EventArgs e)
  {
  string str;
  str=" ";
  //Literal1.Visible=true;
  Literal1.Text=str;
  }


本文由设计家园 收集整理











































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.