Control Handler

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am adding an undefined number of Text Boxes to page.

I say undefined because the number of Text Boxes added is defined by a
property of my custom control.

All Text Boxes have the same properties values less two.

I would like to use one function to handle the Init event of all these
TextBoxes and pass to the function those two different properties
values for each Text Box.

Is this possible? And is this the right way to do it?

Remember that I am doing it this way because the number of TextBoxes
is "undefined"

Thanks,

Miguel
 
u can loop inner controls of your custom control (assuming textboxes
is direct children of the control)

let's say you your custom control is X

to loop, u just do

if X.HasControl
For Each C as Control in X.Controls
if Typeof C is TextBox then
do something
end if
Next

for your other questions on "pass functions" "two less", i don't get
it
 
Hi Miguel,

you can get each textbox to call the same function as follows:

<asp:TextBox OnInit="TextBoxInit" runat="server" ID="txt1" />
<asp:TextBox OnInit="TextBoxInit" runat="server" ID="txt2" />
<asp:TextBox OnInit="TextBoxInit" runat="server" ID="txt3" />

Codebehind:

protected void TextBoxInit(object sender, EventArgs e)
{
TextBox txtSender = sender as TextBox;
}

From there you can use txtSender to get the 2 control-specific properties
you're after.

Best Regards,
Andrew
 
Back
Top