zoukankan      html  css  js  c++  java
  • 前台获取后台c#代码

    1.在前台html控件调用c#后台变量。
    在后台的类代码里定义一个字符串。如
    public partial class Index : System.Web.UI.Page
    {
        public string o_value = "";
    }
    然后可以写方法改变此字符串的值。
    前台调用也很简单:
    <input id="Text1" type="text" value="<%=o_value %>"/>
    2.在前台html调用c#后台方法
    后台有一个方法:
    public string test()
        {
            return "fdfdfdfdsf";
        }
    前台代码:
    <input id="Text2" type="text" value="<%=test()%>"/>
    3.在前台js里调用c#后台变量
    后台代码:
    public partial class Index : System.Web.UI.Page
    {
        public string o_value = "";
    }
    前台代码:
       <script>alert("<%=o_value %>");</script>
    4.在前台js里调用c#后台变量
    后台有一个方法:
    public string test()
        {
            return "fdfdfdfdsf";
        }
    前台代码:
    <script>alert("<%=test() %>");</script>
    5,前台js里调用后台带参数的方法
    public string test(string a)
        {
            return a+",我是参数传进来的";
        }
    <script>alert("<%=test("fengjian") %>");</script>
    6,前台js里调用后台带参数的方法
     //商品信息
            function getProInfo(t) {
                var result = "";
                    result = MallPowerSite.order.ChangeOrderEdit.GetProductInfo(t).value;//后台的方法,注意这里不用双引号
                return result;
            }

    要注意个问题:
    要在js中调用C#的变量和函数返回的结果,js代码必须写在页面的<script>...</script>中,而不能写在独立的*.js文件中,这样会js会将*.js的C#代码作为字符串处理,而不是变量或者方法。 

    http://blog.sina.com.cn/s/blog_69e8baad0100m458.html 

  • 相关阅读:
    poj 1789 Truck History(最小生成树)
    POJ 3096 Surprising Strings(STL map string set vector)
    hdu 1412 (STL list)
    POJ 1552 Doubles (C++ STL set使用)
    poj 水题系列
    洛谷P4859 已经没有什么好害怕的了
    CF1228E Another Filling the Grid
    二项式反演
    AT [ABC177F] I hate Shortest Path Problem
    [NOI2020]制作菜品
  • 原文地址:https://www.cnblogs.com/chen110xi/p/2419994.html
Copyright © 2011-2022 走看看