Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > picking up value in code behind

Reply
Thread Tools

picking up value in code behind

 
 
Scott Collens
Guest
Posts: n/a
 
      08-07-2003
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
 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      08-08-2003
"Scott Collens" <> wrote in message news:Xns93D0D1997B0E8scottcollensnospamho@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



 
Reply With Quote
 
 
 
 
Carl Prothman [MVP]
Guest
Posts: n/a
 
      08-08-2003
"Scott Collens" <> wrote
> "Carl Prothman [MVP]" <> wrote
> > "Scott Collens" <> 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




 
Reply With Quote
 
Scott Collens
Guest
Posts: n/a
 
      08-13-2003
Thanks Carl, I'll give it a try.


"Carl Prothman [MVP]" <> wrote in
news::

> "Scott Collens" <> wrote
>> "Carl Prothman [MVP]" <> wrote
>> > "Scott Collens" <> 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
>
>
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulty picking up field value from second webform Jonathan ASP .Net 2 03-11-2008 10:06 AM
Non-code behind to code behind John ASP .Net 2 02-19-2007 07:08 PM
picking value of one attribute based on a child elements attribute? XPath? vjethava@gmail.com XML 2 03-06-2006 05:19 AM
Code-Behind Pain in the Behind! Daniel Manes ASP .Net 11 06-10-2005 09:47 PM
Re: Code Behind vs. no code behind: error Ben Miller [msft] ASP .Net 1 06-28-2003 01:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57