揭露,然后用OnTextChange事件处理 [英] Exposing and then using OnTextChange Event handler

查看:183
本文介绍了揭露,然后用OnTextChange事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题:<一href=\"http://stackoverflow.com/questions/7580987/adding-custom-ontextchange-event-handler-on-custom-textbox\">Adding自定义文本框自定义OnTextChange事件处理

在相关的问题,我问我怎么能在我的自定义文本框控件暴露OnTextChange,我们通过解决它:

In the related question I asked how I could expose OnTextChange in my custom textbox control and we resolved it by:

public event EventHandler TextChanged
{
    add { customTextBox.TextChanged += value; }
    remove { customTextBox.TextChanged -= value; }
}

我试图用TextChanged事件这样当控制实现:

I am trying use TextChanged event like this when the control is implemented:

    <uc:CustomTextBox ID="customTextBox"
                      runat="server"
                      OnTextChanged="CustomTextBox_OnTextChanged">
    </uc:CustomTextBox>

这似乎永远不会打以下运行时:

This never seems to hit the following when running:

    protected void CustomTextBox_OnTextChanged(System.EventArgs e)
    {
     // Do something here
    }

或按

    protected void CustomTextBox_OnTextChanged(object sender, EventArgs e)
    {
     // Do something here
    }

我是什么做错了,我丢失了,这是最好的方式还是常见的做法的方式做,我想在这里做的一切?

What am I doing wrong, what am I missing out and is this the best way or common practice way to do everything I am trying to do here?

推荐答案

您需要设置的AutoPostBack =真文本框的属性。

You need to set AutoPostBack=True property of TextBox.

如果你正在设计一个web用户控件然后简单地界定公共属性设置 CustomTextBox 的真/假价值在用户控件的code-背后:

If you are designing a web user control then simply define public property to set True/False value of CustomTextBox in user control's code-behind:

public   bool AutoPostBack
    {
        get
        {
            return CustomTextBox.AutoPostBack;
        }
        set
        {
            CustomTextbox.AutoPostBack = value;
        }
    }

如果你正在开发一个自定义的Web控件,那么你可以来覆盖定制的的AutoPostBack 属性。如果你不希望自定义的AutoPostBack 属性,则不会覆盖它。

If you are developing a custom web control then you can to override the AutoPostBack property for the customization. If you don't want to customize AutoPostBack property then don't override it.

如果你覆盖AutoPostBack属性,请调用父类的缺省实现。

In case you override AutoPostBack property, please invoke the super class's default implementation.

public override  bool AutoPostBack
    {
        get
        {
            return base.AutoPostBack;
        }
        set
        {
            base.AutoPostBack = value;
        }
    }

这篇关于揭露,然后用OnTextChange事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆