Control Handler

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
 
Z

zzzxtreme

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
 
A

Andrew

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top