Change the textbox value of a usercontrol from the principal page
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.aspnet.

Post a new message to this list...

nail
Hi.
So I have a default.aspx page and 3 WebUserControls
In the WebUserControl1, I have on TexBox, and in the default.aspx page I
have a Button control.
On the click event of the default.aspx page I need to change the
TextBox.Text value, but not user the FindControl Method because I think this
methos very slow.

So, I want this, but not with findcontrol:

void Button_Click(object sender, EventArgs e)
{
((TextBox)this.WebUserControl2_1.FindControl("TextBox1")).Text = "Principal
page button clicked";
}

Anybody has any idea how can I do that?
My boss said the findcontrol method use reflection and is too slow.
Understand now why I can't use findcontrol? :)

Thanks ind advance.

nail.

Reply to this message...
 
    
Marina
Add a public method to the usercontrol that sets its textbox's text to a
given value. Then call this method from your page and pass it the new text.

"nail" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
nail
Marina, now I understant.
But is the same problem of Mark solution.

I need to do a public method for any control I put in the usercontrol.

Thanks.

"Marina" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
nail
Marina, I can't understand very well.
How did you imagine the method?

Thanks.

PS: Don't have any way like WebUserControl.Control??

"Marina" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Marina
Pretty much as the other user suggested with a property - since a property
is syntactic sugar for 2 methods.

If you want a generic solution, where you need to refer to each textbox by a
string - then I don't see any way other then to use reflection.

If you don't need to refer to the textbox by a string held in a variable,
you could make all the textboxes in the user control public, and then you
could access them directly.

"nail" <Click here to reveal e-mail address> wrote in message
news:%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Mark Fitzpatrick
You can expose the textbox, or the Text value of the textbox as a property.

Try something like the following in the web user control

public string TheText
{
get{return TextBox1.Text;}
set{TextBox1.Text = value;}
}

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"nail" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
nail
Ok Mark.
But if I have a lot of controls, I need to create a lot of properties.
Very hard to maintenance this, don't think?

It's an idea, but I guess my boss will discard too.
But thanks.

"Mark Fitzpatrick" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.Web.UI.MobileControls.TextBox
System.Web.UI.WebControls.TextBox
System.Windows.Forms.TextBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com