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

How to set a property in a user control

J-T
I have a aspx page which loaded different user contols based on the users'
entries.In one of my child user controls I have a property like below:

public String PostID
{
get
{
return (String) ViewState["PostID"];
}
set
{
ViewState["PostID"] = value;
}
}

Now from my aspx page (parent page) ,I'd like to se this propert so I can
maintain the PostID across multiple postbacks of my user control.How can I
do that?
Here is the way I load the child user control in my aspx page (parent page):

Control dynamicUC = null;

dynamicUC= LoadControl("~/PageControls/GetPostDetails.ascx");

dynamicUC.EnableViewState=true;

ViewState["PostID"]=postID;

Thanks a lot

Nov 19 '05 #1
3 1279
You need to cast your dynamicUC to the specific type of the user control
(not shown below, so I have no idea)

((MyUserControlType)dynamicUC).PostID = postId;

since this is only one of multiple user controls and the only one to expose
the PostID field, you might want to make the userControl fetch the value
from a public property of the page (ie, go fetch it instead of setting it).

PostID = ((PageType)Page).PostID;

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"J-T" <Ra*****@microsoft.com> wrote in message
news:uK****************@tk2msftngp13.phx.gbl...
I have a aspx page which loaded different user contols based on the users'
entries.In one of my child user controls I have a property like below:

public String PostID
{
get
{
return (String) ViewState["PostID"];
}
set
{
ViewState["PostID"] = value;
}
}

Now from my aspx page (parent page) ,I'd like to se this propert so I can
maintain the PostID across multiple postbacks of my user control.How can I
do that?
Here is the way I load the child user control in my aspx page (parent
page):

Control dynamicUC = null;

dynamicUC= LoadControl("~/PageControls/GetPostDetails.ascx");

dynamicUC.EnableViewState=true;

ViewState["PostID"]=postID;

Thanks a lot


Nov 19 '05 #2
J-T
I didn;t get the second part.What do you mean by "Page" in PostID =
((PageType)Page).PostID;?? do you mean the Parent page or the userControl
page (child )).

Thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Ot**************@TK2MSFTNGP10.phx.gbl...
You need to cast your dynamicUC to the specific type of the user control
(not shown below, so I have no idea)

((MyUserControlType)dynamicUC).PostID = postId;

since this is only one of multiple user controls and the only one to
expose the PostID field, you might want to make the userControl fetch the
value from a public property of the page (ie, go fetch it instead of
setting it).

PostID = ((PageType)Page).PostID;

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"J-T" <Ra*****@microsoft.com> wrote in message
news:uK****************@tk2msftngp13.phx.gbl...
I have a aspx page which loaded different user contols based on the users'
entries.In one of my child user controls I have a property like below:

public String PostID
{
get
{
return (String) ViewState["PostID"];
}
set
{
ViewState["PostID"] = value;
}
}

Now from my aspx page (parent page) ,I'd like to se this propert so I can
maintain the PostID across multiple postbacks of my user control.How can
I do that?
Here is the way I load the child user control in my aspx page (parent
page):

Control dynamicUC = null;

dynamicUC= LoadControl("~/PageControls/GetPostDetails.ascx");

dynamicUC.EnableViewState=true;

ViewState["PostID"]=postID;

Thanks a lot



Nov 19 '05 #3
Check out:
http://openmymind.net/index.aspx?documentId=9#3.1

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"J-T" <J-*@nospam.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
I didn;t get the second part.What do you mean by "Page" in PostID =
((PageType)Page).PostID;?? do you mean the Parent page or the userControl
page (child )).

Thanks

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Ot**************@TK2MSFTNGP10.phx.gbl...
You need to cast your dynamicUC to the specific type of the user control
(not shown below, so I have no idea)

((MyUserControlType)dynamicUC).PostID = postId;

since this is only one of multiple user controls and the only one to
expose the PostID field, you might want to make the userControl fetch the
value from a public property of the page (ie, go fetch it instead of
setting it).

PostID = ((PageType)Page).PostID;

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"J-T" <Ra*****@microsoft.com> wrote in message
news:uK****************@tk2msftngp13.phx.gbl...
I have a aspx page which loaded different user contols based on the
users' entries.In one of my child user controls I have a property like
below:

public String PostID
{
get
{
return (String) ViewState["PostID"];
}
set
{
ViewState["PostID"] = value;
}
}

Now from my aspx page (parent page) ,I'd like to se this propert so I
can maintain the PostID across multiple postbacks of my user control.How
can I do that?
Here is the way I load the child user control in my aspx page (parent
page):

Control dynamicUC = null;

dynamicUC= LoadControl("~/PageControls/GetPostDetails.ascx");

dynamicUC.EnableViewState=true;

ViewState["PostID"]=postID;

Thanks a lot




Nov 19 '05 #4

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

Similar topics

3
by: Job Lot | last post by:
I have added a ProgressBar control to StatusBar control and created a custom property as below, to show the properties of the ProgressBar in Property Window of StatusBar. <Browsable(True)> _...
1
by: Steven.Xu | last post by:
Hi, everyone. I am writting an user control. There has some properties on it. At the design time, the properties will disply on the property windows and user could change it's value after selected...
3
by: Karl Lang | last post by:
Hi, I'm trying to set a property of a user control that is part of another user control. So I have a control A which contains control B, and I'm trying to set a property in B from within the...
15
by: Mark Goldin | last post by:
I have main aspx page with a number of user controls. How can I create a global property that will be visible in every user control? Thanks
1
by: Nathan Sokalski | last post by:
I have a problem that is driving me crazy. I have a User Control composed of three DropDownLists that will be used to select a date. I have everything working except for one thing. When I select a...
6
by: active | last post by:
In VB6 I could invoke a tool ( don't remember how right now) that would enable me to create properties in my user control that passed through properties of components on the user control. I...
1
by: Will Gillen | last post by:
I know this has probably been asked before, but I can't seem to find a solid answer in any of the archives. First, before my question, please forgive my limited knowledge of the event lifecycle...
1
by: shapper | last post by:
Hello, I am creating a user control where an Asp.Net control is used. It can be either a button, an image button or a label. I am trying to "expose" the Asp.Net control properties and events...
2
by: Benton | last post by:
Hi there, I'm creating a custom server control, inheriting from TextBox. It has this AsDateTime property that returns the textbox contents converted to the nullable DateTime data type, as...
18
by: Academia | last post by:
I let the use modify the text of a combobox and then I replace the selected item with the new text (in Keyup event). But if he sets the Text property to an empty string ("") that sets the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
0
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...

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.