惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
Y
Y Combinator Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
C
Check Point Blog
IT之家
IT之家
MyScale Blog
MyScale Blog
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
Last Week in AI
Last Week in AI
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
B
Blog
T
The Blog of Author Tim Ferriss
H
Help Net Security
云风的 BLOG
云风的 BLOG

博客园 - Ekin.S.Sun

document.execCommand Web文件ContentType类型大全 ArcGIS符号库制作过程说明 JavaScript中的一些重要却容易被忽视的东西 AJAX and the ASP.NET 2.0 Callback Framework My heart hurt:( Working with the ArcGIS Server ArcObjects API : ArcObjects API Js网页打印处理 MapInfo格式到ArcGIS格式的转换方法 ArcGIS Server 9.2建立的web Application实现打印的一篇文章。 .net学习站点推荐 AJAX .Net组件用户指南(译文&原文) New characteristic of Visual Studio 2005 ASP.NET中常用发送邮件功能代码总结 C#常用正则表达式 ASP.NET系统用户权限设计与实现 how to use Form Authentication in ASP.NET. web.config文件详解 [转] 软件测试的一些认识
c#和js的交互(转)
Ekin.S.Sun · 2007-09-12 · via 博客园 - Ekin.S.Sun

 c#和js的交互(转)

如何在 C#中访问 JavaScript函数?
答案如下:

c#
代码中执行 javaScript函数:
方法一:1Page.RegisterStartupScript("ggg","<script>SetVisible(1);</script>");
方法二:使用 Literal类,然后

private void Button2_Click(object sender, System.EventArgs e)
{
 string str;
 str="<script language='javascript'>";
 str+="selectRange()";
 str+="</script>";
 / teral1.Visible=true;
 Literal1.Text=str;
}


JavaScript访问C#变量?
答案如下:

方法一:1、通过页面上隐藏域访问<input id="xx" type="hidden" runat="server">
方法二:1、如后台定义了 PUBLIC STRING N;前台 js中引用该变量的格式为'<%=n%>'
"+<%=n%>+"
方法三:1、或者你可以在服务器端变量赋值后在页面注册一段脚本

           "<script language='javascript'>var temp=" + tmp + "</script>"
           tmp
是后台变量,然后 js中可以直接访问 temp获得值。


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

答案如下:

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

方法二:可以用 cookie session


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()%>可以调用

          
前台脚本
           <script language=javascript>
           var a = "<%=ss()%>";
           alert(a);
           </script>
方法三:1<script language="javascript">
           <!- -
           function __doPostBack(eventTarget, eventArgument)
           {
              var theForm = document.Form1;     //
runat=server
form
              theForm.__EVENTTARGET.value = eventTarget;
              theFrom.__EVENTARGUMENT.value = eventArgument;
              theForm.submit();
           }
           -->
           </script>
           <input id="Button1" type="button" name="Button1" value="
按钮
" onclick="javascript:__doPostBack('Button1','')">
       
方法四:
<script language="javascript">
function SubmitKeyClick()
{
    if (event.keyCode == 13)
    {
        event.cancelBubble = true;
        event.returnValue = false;
        document.all.FunName.value="
你要调用的函数名"

        document.form[0].submit();
    }
}
</script>

<INPUT onkeypress="SubmitKeyClick()" id="aaa" type="text">
<input type="hidden" name="FunName">
〈!--用来存储你要调用的函数 --

.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()

{

//……比如计算某值

}