zoukankan      html  css  js  c++  java
  • .net 中 前台aspx页面调用后台.cs文件中的变量

    定义全局变量
    在Page_load上面写
    public string Url;

    后台代码:

    public partial class WebForm2 : System.Web.UI.Page
       {
           public string GetVariableStr;//注意变量的修饰符
           protected void Page_Load(object sender, EventArgs e)
           {
               if (!IsPostBack)
               {
                   GetVariableStr = "hello world from variable";
               }
           }
           protected string GetFunctionStr()//注意返回值的修饰符
           {
               return "hello world from Function";
           }
       }
    

      前台代码:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript">
            function fun() {
    
                var str = '<%= DateTime.Now %>';
                //前台位置1,绑定的是第三种变量类型(也是第二种方式,?因为Now是个属性)
                alert(str);
            }
        </script>
    </head>
    <body onload="fun()">
        <form id="form1" runat="server">   
            <div>
                 <input type="text" value="<%= GetVariableStr %>" />
                                                      <%--前台位置2,绑定的是成员变量--%>
                 "<%= GetFunctionStr() %>"
                                                      <%--前台位置3,绑定的是一个方法的返回值>--%>
            </div>
        </form>
    </body>
    </html>
    
  • 相关阅读:
    css--盒子模型
    目标爬取社会信用码
    KFC-位置分页爬虫
    百度翻译-爬虫
    网页采集器-UA伪装
    python模块2
    python模块
    go入门
    python垃圾回收机制
    Python高级用法
  • 原文地址:https://www.cnblogs.com/y0umer/p/3839240.html
Copyright © 2011-2022 走看看