0

我正在扩展 Web 控件。我需要在控件而不是 javascript 触发的每个事件上调用服务器方法。

public partial class MyTextBox : RadTextBox, IScriptControl
{
    public MyTextBox()
    {
        Attributes.Add("onBlur", "handleLostFocus();");
        Attributes.Add("runat", "server");
    }

    public void handleLostFocus()
    {
        MyObject obj = new MyObject();
        obj.someproperty = this.Text; //or somehow get the user entered text.

        MyService1 service = new MyService1();
        service.sendRequest(obj);
    }
}
4

1 回答 1

1

正如我在评论中所说,如果AutoPostBack = "True"您需要处理您的事件,则默认情况下 TextBox 会发布。假设您的 TextBox 名为 TextBox1:

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    string str = TextBox1.Text;
}

摆脱handleLostFocus()或让它成为您的 TextBox 控件的处理程序。

祝你好运朋友。

于 2012-12-12T06:59:02.847 回答