469,160 Members | 1,877 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,160 developers. It's quick & easy.

Change the textbox value of a usercontrol from the principal page

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("Text Box1")).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.
Nov 18 '05 #1
9 1966
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.

Nov 18 '05 #2
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.

Nov 18 '05 #3
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" <ma******@fitzme.com> wrote in message
news:ey**************@TK2MSFTNGP14.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.


Nov 18 '05 #4
Marina, I can't understand very well.
How did you imagine the method?

Thanks.

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

"Marina" <so*****@nospam.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.


Nov 18 '05 #5
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" <na**@seaforce.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Marina, I can't understand very well.
How did you imagine the method?

Thanks.

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

"Marina" <so*****@nospam.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.



Nov 18 '05 #6
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" <so*****@nospam.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:uU**************@TK2MSFTNGP10.phx.gbl...
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("Text Box1")).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.


Nov 18 '05 #7
And what the impact of I make all the controls public in user control?
"Marina" <so*****@nospam.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Marina, I can't understand very well.
How did you imagine the method?

Thanks.

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

"Marina" <so*****@nospam.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
> 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" <na**@seaforce.net> wrote in message
> news:uU**************@TK2MSFTNGP10.phx.gbl...
>> 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("Text Box1")).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.
>>
>>
>
>



Nov 18 '05 #8
The normal implications of being public - access to them is not restricted
to just within the user control.

"nail" <na**@seaforce.net> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
And what the impact of I make all the controls public in user control?
"Marina" <so*****@nospam.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
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" <na**@seaforce.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Marina, I can't understand very well.
How did you imagine the method?

Thanks.

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

"Marina" <so*****@nospam.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
> 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" <na**@seaforce.net> wrote in message
> news:uU**************@TK2MSFTNGP10.phx.gbl...
>> 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("Text Box1")).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.
>>
>>
>
>



Nov 18 '05 #9
Thanks Marina.
I will see what my boss think about it.

PS: Do you know anything about a way to do it using ::, like
WebForm::WebUserControl.Control
Is it exists?

"Marina" <so*****@nospam.com> wrote in message
news:OX**************@TK2MSFTNGP10.phx.gbl...
The normal implications of being public - access to them is not restricted
to just within the user control.

"nail" <na**@seaforce.net> wrote in message
news:eM**************@TK2MSFTNGP10.phx.gbl...
And what the impact of I make all the controls public in user control?
"Marina" <so*****@nospam.com> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
> 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" <na**@seaforce.net> wrote in message
> news:%2****************@TK2MSFTNGP14.phx.gbl...
>> Marina, I can't understand very well.
>> How did you imagine the method?
>>
>> Thanks.
>>
>> PS: Don't have any way like WebUserControl.Control??
>>
>> "Marina" <so*****@nospam.com> wrote in message
>> news:eF**************@TK2MSFTNGP09.phx.gbl...
>> > 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" <na**@seaforce.net> wrote in message
>> > news:uU**************@TK2MSFTNGP10.phx.gbl...
>> >> 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("Text Box1")).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.
>> >>
>> >>
>> >
>> >
>>
>>
>
>



Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Lisa Calla | last post: by
6 posts views Thread by Marc Robitaille | last post: by
4 posts views Thread by Jeff | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.