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
        }
    }

  • 相关阅读:
    DataGridView 移动行
    DataGridView 显示提示信息
    模块和类的区别
    C# 流总结
    很口语I'm on my way
    读书笔记_Effective_C++_条款二十三:宁以nonmember、nonfriend替换member函数
    PDB文件:每个开发人员都必须知道的
    qq农场,数据抓包分析,实现源码,图片讲解
    连连看外挂消去算法分析
    关于“服务器提交了协议冲突. Section=ResponseStatusLine"问题请
  • 原文地址:https://www.cnblogs.com/huanhuan86/p/2364835.html
Copyright © 2011-2022 走看看