.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification