473,386 Members | 1,812 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,386 software developers and data experts.

picking up value in code behind

Hi there, does anyone know if it is possible to set a value in a user
control and pick it up in the code behind.

I'm trying to reuse the same user control and code behind for multiple
pages but I don't want to use a querystring param. Thanks for
listening...Scott
Nov 17 '05 #1
3 1447
"Scott Collens" <sc**********@nospam.hotmail.com> wrote in message news:Xn**********************************@207.46.2 48.16...
Hi there, does anyone know if it is possible to set a value in a user
control and pick it up in the code behind.


Scott,
Create a public Property for the User Control. Then in the WebForm's code-behind,
call the User Control's Property to get the value.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com

Nov 17 '05 #2
"Scott Collens" <sc**********@nospam.hotmail.com> wrote
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote
"Scott Collens" <sc**********@nospam.hotmail.com> wrote
Hi there, does anyone know if it is possible to set a value in a user
control and pick it up in the code behind.


Create a public Property for the User Control. Then in the WebForm's
code-behind, call the User Control's Property to get the value.


Thanks for the response, but I'm a little confused as to how this is picked
up in the code behind. Can you provide an example? Thanks again....Scott


Scott,
In the User Control, create a public property

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

Then in the code behind of the WebForm (which contains the User Control)
create a protected member variable for the User Control. In this case,
the C# project is called "myProject" and the User Control is called
"UserControlPropertyDemo"

protected myProject.UserControlPropertyDemo UserControlPropertyDemo1;

Then in some event handler, get or set the User Control's public property value

// Set the property value
UserControlPropertyDemo1.Username = "CarlProthman";

// Get the property value
string username = UserControlPropertyDemo1.Username;

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com


Nov 17 '05 #3
Thanks Carl, I'll give it a try.
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote in
news:OH**************@TK2MSFTNGP10.phx.gbl:
"Scott Collens" <sc**********@nospam.hotmail.com> wrote
"Carl Prothman [MVP]" <ca****@spamcop.net> wrote
> "Scott Collens" <sc**********@nospam.hotmail.com> wrote
> > Hi there, does anyone know if it is possible to set a value in a
> > user control and pick it up in the code behind.
>
> Create a public Property for the User Control. Then in the
> WebForm's code-behind, call the User Control's Property to get the
> value.


Thanks for the response, but I'm a little confused as to how this is
picked up in the code behind. Can you provide an example? Thanks
again....Scott


Scott,
In the User Control, create a public property

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

Then in the code behind of the WebForm (which contains the User
Control) create a protected member variable for the User Control. In
this case, the C# project is called "myProject" and the User Control
is called "UserControlPropertyDemo"

protected myProject.UserControlPropertyDemo
UserControlPropertyDemo1;

Then in some event handler, get or set the User Control's public
property value

// Set the property value
UserControlPropertyDemo1.Username = "CarlProthman";

// Get the property value
string username = UserControlPropertyDemo1.Username;

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.able-consulting.com



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Erik Max Francis | last post by:
I was interesting in adding selection and hit testing to ZOE, and was looking at the PyOpenGL wrappers' handling of selection and picking. I see glSelectBuffer to specify the size of the buffer,...
0
by: Henry | last post by:
Hi Is there any good ideas how to update form vb code always after some values are changed / added by vb (not user). I have some code behind subforms vb and there are calculations behind...
1
by: Pat | last post by:
All, What I want to do: ******************* Click on a hyperlink in the last column in a datagrid, have it grab a value in the fourth column in the same row and send it to the codehind into a...
7
by: Gene | last post by:
I have a number of aspx pages on which a single user control appears. All of the aspx pages and the user control make user of code-behind modules. I need for logic in the user control's code-behind...
2
by: Steven K | last post by:
Hello, I am trying to learn how to use Code Behind. Essentially, the example of Block 1 and Block 2 are the same. The difference is that in Block 1 I explicitly set the parameter value to...
1
by: xenophon | last post by:
I add a Hidden form field to my asp.net page in the codebehind, the Value peoperty is set to 0 and EnableViewState is set to true. Then I add a LiteralControl with JavaScript that says to set the...
8
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the...
0
by: Jonathan | last post by:
I have 3 webforms on 1 page each with Submit buttons. VB.net code activated by clicking the submit button in form 3 is not picking up the value of a field in form 2. It is just returning Null or...
6
by: Igor | last post by:
Hi How can I reference a specific control in a web user form from web form's (page) code behind. In other words: I have a page (a web form) that has a web user form in it. I want to read a value...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.