zoukankan      html  css  js  c++  java
  • WebForm(Application,ViewState,Repeater的Command操作)

    一、AppliCation:

    1、存储在服务器端,占用服务器内存

    2、生命周期:永久

    3、所有人都可访问的共有对象,一般用作服务器缓存

    4、赋值:Application["key"]=变量

    5、取值:Application["key"]

    二、ViewState

    网页具有无页面状态性,任意操作后都会刷新页面,利用ViewState记录网页当期状态,使服务器可返回之前页面

    作用:

    1. ViewState就是用来存储数据的

     2. ViewState可以跟踪值的变化

    3. 序列化和反序列化(SERIALIZATION AND DESERIALIZATION )

     三、继承关系

    aspx继承自ashx,

    ashx继承自IHttpHandler

    ashx,是html后台,从html提交需用表单action=“”;method="get/post";

    get--有返回值,可见传值,post相反

    四、Repeater的Command操作

    Repeater在ItemTemplate循环中id自动改变,不能获取id进行添加点击事件因此需Command操作。

    1、事件:(1)ItemCommand

    后台创建:在Page_Load中  Repeater1.ItemCommand +=  ,然后双击Tab键

    2、点击操作:

    获取操作对象:

    按钮中加属性:Commandname=“”;

    操作:if(e.commandname=“”)

    {

    操作

    }

    3、取值:e.CommandArgument

    (2)ItemCreate内容创建时发生

    (3)ItemDataBound数据绑定时发生

           protected void Page_Load(object sender, EventArgs e)
        {
            Repeater1.ItemCommand += Repeater1_ItemCommand;
            Repeater1.ItemCreated += Repeater1_ItemCreated;
            Repeater1.ItemDataBound += Repeater1_ItemDataBound;
      
    if (!IsPostBack)
            {
                Repeater1.DataSource = new UsersData().SelectAll();
                Repeater1.DataBind();
            }
        }
    
        void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem ri = e.Item;
            Users u = ri.DataItem as Users;
    
            if (u.Sex)
            {
                ri.Visible = false;
            }
        }
    
        void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
        {
            Label1.Text += "1";
        }
    
        void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Update")
            {
                Label1.Text += "修改" + e.CommandArgument;
            }
            else if (e.CommandName == "Delete")
            {
                Label1.Text += "删除" + e.CommandArgument;
            }
        }
    }
  • 相关阅读:
    java处理数据库date类型数据
    in与exist , not in与not exist 的区别
    Eclipse的调试功能的10个小窍门
    关于Synchornized,Lock,AtomicBoolean和volatile的区别介绍
    推荐使用concurrent包中的Atomic类
    深入 Java 调试体系: 第 1 部分,JPDA 体系概览
    dom 绘制正方形
    dom 拖拽div
    dom 按着shift多选
    dom select选单
  • 原文地址:https://www.cnblogs.com/hclyz/p/6891260.html
Copyright © 2011-2022 走看看