473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 2101
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robbie | last post by:
I have a Web Form with some tailored logos and artwork. The web form also has a user control that has typical registration info on it (Name, Company Name, etc.) One of the fields, a TextBox, is a...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
1
by: moid | last post by:
im not able to get textbox value from the datagrid that is in the usercontrol. usercontrol is created dynamically on the page. i want to delete some values if textbox in the datagrid is 0 ...
1
by: rodrigo | last post by:
This is what I am doing public class GridCustomPaging : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DgSearch;
3
by: Lisa Calla | last post by:
Hi, I'm trying to control the foreground and background colors of a textbox. I hate that light gray foreground when the textbox.enabled=false. I've tried to derive a control from the textbox,...
3
by: Mike Dole | last post by:
I experimented with a usercontrol (TagedTextbox), I added a tag property. The tag value however is not persisted on postback (text value's fine)? I worked around it with: Me.ViewState("tag")...
6
by: Marc Robitaille | last post by:
Hello, Hello, I developed a UserControl. It has funny behavior. It is composed of three controls. A texbox, a combobox and a button. There are three properties to indicate the visibility of...
4
by: Jeff | last post by:
Hey asp.net 2.0 I have a UserControl which contain many TextBoxes. When I from the webpage (the webpage containing this UserControl) click on a button to start save the text in the textBoxes,...
7
by: garyusenet | last post by:
I'm using krypton toolkit which has allowed me to make a cool looking form. However, when I set my textbox to disabled it is 'greyed' out. The grey colour isn't in keeping with the office 2007...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.