zoukankan      html  css  js  c++  java
  • c#web中定义全局变量,传递变量

    c# web开发中,定义全局变量是经常用到的.我的做法是

    1\在一个webform 中,

    public static int aaa; 

    public static string bbb; //最简单的定义全局变量的方法

    如果想在各个web form  用到传递 全局变量,则在 类文件中定义变量

    public static int  abc; //最简单的定义全局变量的方法

    记得使用的时候就这样 class1.abc,哈哈,我真聪明啊。

    这样就可以了.

    2\另外,还可以利用session,常见的是在登陆窗口验证 login.aspx.cs中,登陆

    if (name.Value ==us_name&& password.Value == pwd)
            {
                Session["admin"] = "admin_login";//定义了Session的值,如果编译有警告,则不需要理会
                Response.Redirect("admin.aspx");//转向后台管理页面
            }

    在admin.aspx.cs页面中,则需要有这个验证

    protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["admin"]!= "admin_login")
            {
                Response.Redirect ("login.aspx");
            }
        }

    3\还有些常用情况是用 Request对象来传递到下个页面

    例如(dotnet系统中news_list.aspx):mi_child[j].NavigateUrl = "news_list.aspx?inf_type=" + mi_child[j].Text;在下一个页面可以 string sql = "select * from news where inf_type='" + Request.QueryString["inf_type"] + "' order by news_no desc";

    或者:(dotnet系统中view_news.aspx)用GridView绑定数据表时,其中绑定到navigateurl的属性字段如news_id之类,则在下一个页面可以

    string title = dbcen.accGetDataSet("select * from news where news_no = " + int.Parse(Request.QueryString["news_no"].ToString()) + "").Tables[0].Rows[0]["news_title"].ToString();  //如何获得标题

    当然,随着学习视野的拓展,还有很多方法,希望大家给我提出更多简单实用的方法。

  • 相关阅读:
    spring boot多数据源配置示例
    Java 8 Concurrency Tutorial--转
    ibatis annotations 注解方式返回刚插入的自增长主键ID的值--转
    mysql 字符串的处理
    How To Do @Async in Spring--转
    Resolving Problems installing the Java JCE Unlimited Strength Jurisdiction Policy Files package--转
    mysql导入数据,涉及到时间转换,乱码问题解决
    @Query Annotation in Spring Data JPA--转
    hive表信息查询:查看表结构、表操作等--转
    python时间戳
  • 原文地址:https://www.cnblogs.com/pyman/p/1355737.html
Copyright © 2011-2022 走看看