zoukankan      html  css  js  c++  java
  • 回调示例

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    namespace ControlLib
    {
        [DefaultProperty("Text")]
        [ToolboxData("<{0}:CallBackTextBox runat=server></{0}:CallBackTextBox>")]
        public class CallBackTextBox : WebControl,ICallbackEventHandler
        {
            //命名空间.资源文件夹.资源文件名
            public const string JSFile = "ControlLib.Resources.TextBox.js";
           
            [Bindable(true)]
            [Category("Appearance")]
            [DefaultValue("")]
            [Localizable(true)]
            public string Text
            {
                get
                {
                    String s = (String)ViewState["Text"];
                    return ((s == null) ? String.Empty : s);
                }

                set
                {
                    ViewState["Text"] = value;
                }
            }

            public bool IsValid
            {
                get
                {
                    String s = (String)ViewState["IsValid"];
                    return ((s == null) ? false : Convert.ToBoolean(s));
                }

                set
                {
                    ViewState["IsValid"] = true;
                }
            }

            protected override HtmlTextWriterTag TagKey
            {
                get
                {
                    return HtmlTextWriterTag.Input;
                }
            }

            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
                Page.ClientScript.RegisterStartupScript(this.GetType(), "FocusText", "document.getElementById('" + this.ClientID + "').focus();", true);
                string js_file = Page.ClientScript.GetWebResourceUrl(this.GetType(), JSFile);
                Page.ClientScript.RegisterClientScriptInclude("ValidateText", js_file);

            }

            protected override void Render(HtmlTextWriter writer)
            {
                base.Render(writer);

                writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID + "_div");
                writer.RenderBeginTag(HtmlTextWriterTag.Div);
                writer.RenderEndTag();
            }

            protected override void AddAttributesToRender(HtmlTextWriter writer)
            {
                base.AddAttributesToRender(writer);
                writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
                writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
                writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
                writer.AddAttribute("OnBlur", Page.ClientScript.GetCallbackEventReference(this,Text,"CallBackHandler",null));
            }

            #region ICallbackEventHandler 成员

            public string GetCallbackResult()
            {
                return IsValid.ToString();
            }

            public void RaiseCallbackEvent(string eventArgument)
            {
                OnUserNameChanged(EventArgs.Empty);
            }


            public event EventHandler UserNameChanged;
            protected virtual void OnUserNameChanged(EventArgs e)
            {
                if (UserNameChanged != null)
                {
                    UserNameChanged(this, e);
                }
            }

            #endregion
        }
    }

  • 相关阅读:
    ZH奶酪:PHP 使用DOMDocument抓取网页
    PHP Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity,
    ZH奶酪:PHP 执行时间Fatal error: Maximum execution time of...
    ZH奶酪:PHP (爬虫)下载图片
    ZH奶酪:PHP的cURL库
    PHP 字符串编码的转换
    PHP http_build_query()方法
    ZH奶酪:使用PHP调用REST API
    PHP全局变量
    HTML页面跳转的5种方式
  • 原文地址:https://www.cnblogs.com/huanhuan86/p/2364835.html
Copyright © 2011-2022 走看看