Last post Jul 31, 2011 01:07 AM by jkirkerx
Jul 13, 2011 12:40 AM|andysujoto|LINK
I have created a custom Button (called BtCustom) that has a TargetControl to a TextBox. On OnLoad event of BtCustom , i register event handler Text Changed of TextBox
The Code on the OnLoad event of BtCustom and TargetControl Text Changed as follows:
protected override void OnLoad(EventArgs e)
TargetControl.TextChanged += new EventHandler(TargetControl_TextChanged);
TargetControl.AutoPostBack = true;
protected void TargetControl_TextChanged(object sender, EventArgs e)
// do something here (a)
On the webform, I add a TextBox (called Txt1) then a BtCustom and set TargetControl to Txt1. I run and test it, it's working as expected.
Now, back on the webform, i set OnTextChanged to Txt1 and the code as follows :
protected void Txt1_TextChanged(object sender, EventArgs e)
// do something here (b)
And on debugging, i found the sequence of execution will be Txt1_TextChanged first then TargetControl_TextChanged.
Now, how do i tell the program at webform :
- to execute TargetControl_TextChanged first then Txt1_TextChanged
- Not to execute TargetControl_TextChanged
Note : I have tried to used base.OnTextChanged, however, i can't find OnTextChanged after i type base.
Jul 14, 2011 09:28 PM|Decker Dong - MSFT|LINK
to execute TargetControl_TextChanged first then Txt1_TextChanged
As far as I see, To do this directly is hard. But we can have a trick to do with that.
1) Set a flag (boolean) in the class, and its initizalization value is false.
2) in the TargetControl_TextChanged, please set it to true, and in the TargetControl_TextChanged event, please raise the Txt1_TextChanged event.
3) in the Txt1_TextChanged , you should say:
//Do something ……
Not to execute TargetControl_TextChanged
To this problem, I think remove the event handler of TargetControl_TextChanged. Or just set a public property where there's a ViewState to contain a boolean value, which is used to indicate whether TargetControl_TextChanged is executed or not. Something
looks like this——
//Do what you like……
Jul 15, 2011 01:15 AM|andysujoto|LINK
Thanks Decker Dong for your help.
Point no. 2, the workaround should work.
Point no. 1, still can't get it. Both TargetControl_TextChanged and Txt1_TextChanged is actually the same control. What make them difference is, TargetControl_TextChanged declared through class, while Txt1_TextChanged through Webforms. Can you give me example?
Jul 31, 2011 01:07 AM|jkirkerx|LINK
no example code here, just a suggestion.