zoukankan      html  css  js  c++  java
  • GetPostBackEventReference加RaisePostBackEvent实现自定义控件中回调传参

    RaisePostBackEvent(string eventArgument)
    说明:回调方法
    参数:eventArgument,返回客户端回调参数值

    Page.ClientScript.GetPostBackEventReference(control,string)
    说明:客户端指定页面control控件中使用string字符串,以便回调回服务器
    参数:control,实现PostBackOptions类,如控件,一般用this
         string,指定字符串值

    示例:
    类文件:
    using System;
    using System.Web.UI;
    using System.Collections;
    using System.Collections.Specialized;

    namespace CustomControls
    {

        
    public class MyButton : Control, IPostBackEventHandler
        {
            
    private int i = 0;

            
    //回调函数,回调参数值:eventArgument
            public void RaisePostBackEvent(string eventArgument)
            {
                Context.Response.Write(
    ""+eventArgument+"次点击");
                i 
    = int.Parse(eventArgument);
            }

            
    //控件呈现,Control类重写,传送参数至客户端
            protected override void Render(HtmlTextWriter output)
            {
                output.Write(
    "<input type="button" name = " + this.UniqueID +
                   
    " Value = 'Click Me' onclick="javascript:"+Page.ClientScript.GetPostBackEventReference(this,(i+1).ToString())+""/>");
            }
        }
    }
    调用控件页面:

    <%@ Register TagPrefix="CustomControl" Namespace="CustomControls" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        
    <title>无标题页</title>
    </head>
    <body>
        
    <form id="form1" runat="server">
        
    <div>
        
    <CustomControl:MyButton runat="server" ID="Button">
        
    </CustomControl:MyButton>
        
    </div>
        
    </form>
    </body>
    </html>

    注:
    当UseSubmitBehavior 属性为 false 时,GetPostBackEventReference方法可以与Button控件一起使用
    <%@ Register TagPrefix="CustomControl" Namespace="CustomControls" %>
    注册使用自定义控件,TagPrefix指定控件前缀,Namespace指定控件所在命名空间
    调用自定义控件则如下

    <TagPrefix指定名称:自定义控件类名></TagPrefix指定名称:自定义控件类名>

    地址

    http://www.cnblogs.com/ywkpl/archive/2007/12/14/995592.html 

  • 相关阅读:
    (转)AS3中实现卡马克卷轴算法
    (转)flash位图缓存cacheAsBitmap
    (转)addFrameScript函数的纠结
    (转)flash安全策略文件
    (转)脏矩形技术学习
    (转)stopImmediatePropagation 和stopPropagation的区别
    (转)flash对象池技术
    揭开嵌入式C面试题背后的玄机
    一次遍历找链表倒数第n个节点
    N!的尾部连续0的个数
  • 原文地址:https://www.cnblogs.com/baozhu/p/5223397.html
Copyright © 2011-2022 走看看