我正在扩展一个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);
}
}发布于 2012-12-12 14:59:03
正如我在我的评论中所说的,如果你需要处理你的事件,TextBox默认会在AutoPostBack = "True"上发布。假设您的TextBox名为TextBox1:
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
string str = TextBox1.Text;
}去掉handleLostFocus(),或者让它成为TextBox控件的处理程序。
祝你好运,伙计。
https://stackoverflow.com/questions/13834101
复制相似问题