Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2006, 7:53 PM   #1
Kami
Newbie
 
Join Date: Jan 2005
Posts: 21
Rep Power: 0 Kami is on a distinguished road
Variable in a User Control?

Quick question regarding user controls. If I am loading a user control, for example:

<Controls:Menu ID="MyMenu" Selected="0" runat="Server" />

where "selected" is a member variable in the user control ascx file, is it possible to use a variable for the value of "Selected"? I have variables configured in my code-behind page, which I am trying to set the selected variable to from my aspx page. Is this possible, and how is it done?

Thanks in advance for your help.
Kami is offline   Reply With Quote
Old Jun 21st, 2006, 12:49 PM   #2
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Yes it is. Create properties in your user control file. For example C#

Public System.Boolean Selected
{
get{ return this.selected; }
set{ this.selected = value; }
}

Now this property is available anywhere you use the user control. So say you place the user control on a webform and call it MyMenu. Now you can say

MyMenu.Selected = true;

I'm not sure if this is what you are looking for because it seems that you already have Selected as a property by the statement above. If it's not, please clarify.
hoffmandirt is offline   Reply With Quote
Old Aug 16th, 2006, 1:20 AM   #3
Bharathi
Programmer
 
Join Date: Apr 2005
Posts: 32
Rep Power: 0 Bharathi is on a distinguished road
Hi,

There are two ways to set the properties. We defined in the user control. Let's say we have written code for "header" property of a control. We will set the "header" property declaratively in the HTML that defines the control. Change the code in ...Control.aspx to the following
<p align"center"><uc1:address id="Address1" Header="Home Address" runat="server">>/uc1:address></p>

By inserting Header="Home Address", you set this property while calling the user control. This behaviour is similar to passing parameters to subroutines and functions.


Second, we will set propperties programmatically from the calling page's code-behind file.
When you use Visual Studio.net to create user controls, you can simply build them after you create or change them. When this is done, you can set a reference to them in the calling Web Forms code-behind file.

Here is the code that sets this reference:

Protected Address1 As Address

Private Sub btnAddress_Click(......)

User Controls properties are set
Address1.street=123 Forth Zv"
End Sub


Note:
Each user control used in a Web Forms page needs its own reference, even if the same user control is used over and over again. Each user control's ID must have a line of reference.

Regards
bhar
Books for ERP programming using .Net technologies
http://www.vkinfotek.com
Bharathi is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC