473,692 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt = "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 2120
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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt = "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.Te xt = value;}
}

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"nail" <na**@seaforce. net> wrote in message
news:uU******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =
"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******@fitzm e.com> wrote in message
news:ey******** ******@TK2MSFTN GP14.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.Te xt = value;}
}

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"nail" <na**@seaforce. net> wrote in message
news:uU******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =
"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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =

"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******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =

"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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
{
((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =

"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******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
>> {
>> ((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =
> "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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
>> {
>> ((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =
> "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::WebUse rControl.Contro l
Is it exists?

"Marina" <so*****@nospam .com> wrote in message
news:OX******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP14.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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.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(ob ject sender, EventArgs e)
>> >> {
>> >> ((TextBox)this. WebUserControl2 _1.FindControl( "TextBox1")).Te xt =
>> > "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
18153
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 PromoCode which is a field required for each company which registers. I want to programatically set the value of this PromoCode in the host web-form's Page_Load method, but I can't seem to do it. My user control is "RegisterInfo.ascx" (On the...
2
8391
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 submitting the form to update the database. The server doesn't have the client side value any more. It seems to me that as I begin to write the client side javacript code for form validation and client side editing capabilities in order to save...
1
1425
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 Please Help Regards, Moid Iqbal
1
3381
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
1590
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, but I get the following error when trying to run a page with the control on it. wc is the name of my class, and exp is the name of my project. Parser Error Message: 'exp.wc' is not a valid base class because it does not extend class...
3
9222
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") = txtToelichting.Tag but what's wrong with my code?
6
9169
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 the three controls. The only property which functions well is the one for the button. The two others, even if I do: UserControl.TextboxVisible = True or UserControl.ComboboxVisible = True, the textbox or the combobox remain invisible. I placed a...
4
1324
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, then nothing is saved.... I've debugged and discovered that the TextBox.Text = "", but I typed in a value in that TextBox...
7
11797
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 style look of my form. How can i change the colour that control assumed when it's disabled? Thanks! Gary-
0
9079
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8794
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8796
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4322
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4555
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1955
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.