Efficient way to initialize controls within a Custom Server Control.

Hi,

Im writting a CompositeControl and Im wandering if I its recommended to use Application in the initialization of controls (in the Controls collection)  in 

CreateChildControls() function (by checking if  its a postback)

How can I avoid  naming conflicts? (if the hosting web form defines Application variables with the same names I define in my CompositeControl).

Thanks,

Tal88

0
tal88
11/29/2007 11:13:09 AM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

10 Replies
761 Views

Similar Articles

[PageSpeed] 58

CompositeControl implements INamingContainer which ensures that your control and its child controls will get unique ids.  as far as CreateChildControl, be sure to set ChildControlCreated to true after creating your control collection.  EnsureChildControls will check if that property and determine whether to call CreateChildControl again

0
trung
11/29/2007 11:33:01 PM

Hi,

Thanks for your reply, do you have a reference for this, or a simple example for that?

(Im not sure I understand where to set that property...)

Thanks,

Tal88

 

0
tal88
12/2/2007 11:05:36 AM

Hi,

do you have a reference for this, or a simple example for that?

From reference, you may visit the following link:
http://msdn2.microsoft.com/en-us/library/system.web.ui.inamingcontainer(VS.71).aspx

For samples, you may visit the following link:
http://www.dotnetjunkies.com/quickstart/aspplus/doc/webctrlauthoring.aspx

Thanks.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
12/3/2007 3:09:13 AM

Hi,

What about HTTP application variables (also session variables and Cache variables) waht if I set a new key in the Application dictionary

that is in conflict with an existing entry in the hosting web application?

(the application that uses my CompositeControl)

Thanks,

Tal88 

 

 

0
tal88
12/9/2007 8:07:58 AM

hi

you can use ViewState instead ,

what is the value that you want to store?

make sure its serializable so that you can put this value in Viewstate...


 


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
12/9/2007 11:48:06 AM

Hi,

Thanks for your reply.

I prefer using the asp.net Application object to store a DataTable  since I have read that its not so efficient to store large data in ViewState.

in another custom control I need to store a DataTable in the Cache object since it needs to be initilized once a day.

Thanks,

Tal88

0
tal88
12/9/2007 1:38:21 PM

Hi

well , i think building a userControl will be more flexible in these situations , because the control depends on a datasources,

and the controls is used just for the current application .

tal88:

I prefer using the asp.net Application object to store a DataTable  since I have read that its not so efficient to store large data in ViewState.

in another custom control I need to store a DataTable in the Cache object since it needs to be initilized once a day.

yes , if you want to store a datatable , you can't use viewState , because its not Serializable ,also its not recommened to store these complex objects....

 

tal88:

How can I avoid  naming conflicts? (if the hosting web form defines Application variables with the same names I define in my CompositeControl).

Thanks,

tal88:

What about HTTP application variables (also session variables and Cache variables) waht if I set a new key in the Application dictionary

that is in conflict with an existing entry in the hosting web application?

(the application that uses my CompositeControl)

 well, the solution i  see here is to use the UniqueId or the ID property of the Composite control as a part of the control  Cache key .

eg: CacheKey= "_Composite_" + this.UniqueID

HttpRuntime.Cache(CacheKey)=DataTable

Hope This Help

 


Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
12/9/2007 1:53:39 PM

Hi,

Thanks a lot for the quick reply, sounds like a good solution.

Do you think that I can use the web.config file to read variable names dynamically? (the clients of my CompositeControl will add a section

to there web.config and there they will write the names they expect my control to use for some purposes).

(for cases that my custom control will use Application / Session/ Cache variables that the hosting application may use for the same reason).

I think I will use your solution , just want to know what you think about using the web.config as a solution?

Thanks,

Tal

0
tal88
12/9/2007 2:30:23 PM

tal88:

Do you think that I can use the web.config file to read variable names dynamically? (the clients of my CompositeControl will add a section

to there web.config and there they will write the names they expect my control to use for some purposes).

yes you can , but it think its recommened to store a Key Format in the web.config file like this:

 

<add key="CompositeKeyFormat" value="_cache_Composite_{0}"/>

  then you can build the key like this:

 ' get _cache_Composite_{0}
        Dim ControlKeyFroamt As String = ConfigurationManager.AppSettings("CompositeKeyFormat")
        ' this will replace {0} with Control UniqueId
        Dim ControlKey As String = String.Format(ControlKeyFroamt, UniqueID)
 
Regards,

Anas Ghanem.


Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

0
anas
12/9/2007 3:16:33 PM

Hi anas,

Thanks a lot excellent idea!

0
tal88
12/10/2007 9:16:22 AM
Reply:

Similar Artilces:

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Server Controls Within Server Controls
I'm a little new to server controls so this question may seem silly, but has anyone had trouble with events from custom server controls that are embedded in other custom server controls? I'm trying to create a composite control that creates a list of items and creates an instance of another composite control for each item. So for example the list could be a collection of addresses that has an editor composite control for each item. The editor composite control allows the user to edit the item and click on a save button. This works fine if it is on it's own (ie not part of the list ...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

How to Render controls within an UpdatePanel in a Custom Server Control
Hi,Im writting a CompositeControl that contains a few UpdatePanels (TabContainer with an UpdatePanel on each TabPanel to make Tab control panels load "on-demand"). I want to control the renderring of the controls within the UpdatePanel's ContentTemplateContainer.How should I implement the render method of my CompositeControl?Should I use a custom UpdatePanel (inherit from UpdatePanel and override the RenderContents method)? is there a simpler solution? (because I need a different "render" for each tab panel....)Thanks Tal88 Hi, I want to control the renderring o...

Proper way to add to Control collection from a custom server control?
Hi there,I'm creating a custom server control inheriting from TextBox. If a property ("IsRequired") indicates so, I want to add to a RequiredField validator to the mix. Below is what I am doing, though I get the exception "The control collection cannot be modified during DataBind, Init... etc."So how would be the proper way to do it?Thanks a lot, -Benton---------------------------------- using System;using System.Drawing;using System.Web.UI;using System.Web.UI.WebControls;using System.ComponentModel;using RequiredVal = Microsoft.Web.UI.Compatibility.RequiredFieldValidator;namespace...

How do you expose the event of a child server control from within a custom control?
I am trying to create a custom control that has a server control (dropdownlist) as a child.  I need to be able to expose the selectedindexchanged event from the dropdownlist at the page level.  How do you do this?  Here is a quick abbreviated example I wrote to show what I am trying to do:  My Custom Control1 Public Class MyCustomControl 2 Inherits Control 3 ' Variables 4 Protected WithEvents ddlServerControl As New DropDownList 5 ' Methods 6 Private Sub MyCustomControl_Load(ByVal sender As Object, ByVal e As System...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Web resources about - Efficient way to initialize controls within a Custom Server Control. - asp.net.custom-server-controls

Initialize preferences · 2e65248 · MizzleDK/Mizuu · GitHub
Mizuu - Popular media indexer app for Android.

MySQL 出現 Could not initialize master info structure 修復
於 MySQL 設定同步 Replication, 將下述命令拆成兩組輸入, 如下述:mysql> CHANGE MASTER TO MASTER_HOST=&#39;master.ex

//DRUCE C ASSIGNMENT 2 //initializes/defines the output pin of the LM35 tempera - Pastebin.com
PASTEBIN - #1 paste tool since 2002 create new paste tools api archive faq PASTEBIN create new paste trending pastes sign up login my alerts ...

App Store - Applause Karaoke - Rock Out to Your iTunes Library
Read reviews, get customer ratings, see screenshots, and learn more about Applause Karaoke - Rock Out to Your iTunes Library on the App Store. ...

JavaScript SDK - Facebook-Entwickler
Overview The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 325 ...

Floppy disk - Wikipedia, the free encyclopedia
A floppy disk is a disk storage medium composed of a disk of thin and flexible magnetic storage medium, sealed in a rectangular plastic carrier ...

Tyndale Chapel Podcast - Tyndale
myTyndale.ca - Tyndale A-Z Search this site: Visit Campus Request Info Apply Now Home Tyndale Home Tyndale Seminary Home About Tyndale Office ...


2ndQuadrant - PostgreSQL expertise from specialists with a source code level understanding of RDBMS ...
PostgreSQL expertise from specialists with a source code level understanding of RDBMS PostgreSQL Planets Gabriele’s PlanetPostgreSQL Gianni’s ...

Resources last updated: 12/1/2015 10:49:17 AM