C# - Add Custom Control To A Placeholder All Controls
Jul 31, 2010
I've created a usercontrol in asp.net webforms (c#) called 'Article' which contains a general layout for an article and has a public property called datasource. the datasource will be populated by a subsonic (DAL) activerecord. In the controls pre-render event it will read the record and populates the labels. I think this is a flexible solution with easy maintenance. My problem however is that when I try to add the control to a placeholder all my controls like labels, literals and the like receive a null reference exception. I'm trying to spawn the controls as followed:
foreach (DAL.Article item in coll)
{
p7.Controls.General.Article.Article article = new p7.Controls.General.Article.Article();
article.datasource = item;
phContent.Controls.Add(article);
}
Is there something I've completely missed? It's driving me crazy heheh! Another question is do you guys know if this method will have a big impact on performance. I'm only adding 10 of those article controls per page.
View 1 Replies
Similar Messages:
Feb 26, 2010
I am writing an ASP.NET custom control.In my custom control code, I find a PlaceHolder control in the page like so:this.myPlaceholder = Page.FindControl("placeholder1") as PlaceHolder Then, I render the placeholder as the output of the custom control:
protected override void Render(HtmlTextWriter output)
if (this.myPlaceholder != null)
this.myPlaceholder.RenderControl(output);
However, this causes the placeholder to be rendered in two places - in the custom control output (good) and in the original location in the page (bad).
View 1 Replies
Apr 13, 2010
I'm creating an ASP.NET Control which has a property collection for Columns which the user can edit in the Property Collection Editor..
In most circumstances this works fine, the collection can be edited in the designer and the appropriate tags are added inside the control in the ASPX file.
It works fine when
My control is added to the form
[Code]....
My control is added inside an Update Panel
[Code]....
[Code]....
However, if My control is inside a Content Placeholder which is inside an Update Panel, it fails to work as it should. In this scenario, when the Columns collection is edited in the designer, if you then switch back to Source view, the Columns collection is emptied. I have to save the aspx page before switching back to Source view for the changes to be kept.
[Code]....
how to get around this problem? Is there something I may have missed?
Here's the code for the Control
[Code]....
View 2 Replies
Jan 19, 2010
how to maintain state of placeholder. i have a placeholder in which i add many image controls dynamically but when my page get refresh all controls from placeholder gets removed from it. the enableViewstate of placeholder is set to true.
View 3 Replies
Mar 22, 2011
I am using list view to display the the data but i am getting an error like An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder". The item placeholder control must also specify runat="server.Even i have specified the itemplaceholder id but no use still same error.
[Code]....
View 1 Replies
Mar 4, 2010
I have a custom control which inherit from the Table class and in the constructor, it takes a an integer as an argument. There is no empty constructor.
Is there a way for the user to set that variable in the properties window after they drag the control onto a form.
I know some .NET controls, you can set the source for the parameter to different things like another control's property, QueryString using just the properties window.
Right now, I have to create the control dynamically. I read the query string and then created the object.
View 1 Replies
Aug 16, 2010
i want to add and access to placeholder in a repeater control. for example,
[Code]....
how can i acces to placeholder, on codebehind. i couldn't acces with it's id.
View 3 Replies
Dec 24, 2010
here's a situation and I would appreciate your response.
I have programmatically created the Wizard control:
Page_Load(obj s, evargs e)
{
Wizard ClaimDetailWizard = new Wizard();
foreach(int item in selectedItems)
{
//create new step
//added custom control to new step
//add step to wizard
}
//added wizard to a placeholder on a page
}
Based on List I get from Session i added new steps to my wizard To each step I had added a custom control
Each custom control in tern contains another custom Gridview Control in it.
So here's the problem when the page loads for example for two steps. All is good Wizard does what it's supposed to do.
But when I try to use sorting or paging in that custom Gridview. Somehow it displays the gridview I should see in the next step of the wizard.
Also what I'm noticing through debugging. Is that when I press next in the wizard I go back to the original page where I do all of the code specified above, and it recreates the wizzard. But it goes to the next step. Is this the way wizard supposed to work? Just doesn't seem very efficient.
View 1 Replies
Mar 22, 2011
I am trying to build a custom composite control, which allows me to add custom content to each child control. It's a similar concept to what you have with a GridView and TemplateColumn. The markup used to place the control on the page would end up being something like this:
[Code]....
I have the code below, which allows me to put that markup on the page without throwing any errors, and it renders all the correct HTML, except it doesn't render the contents of the ColumnTemplate. I have replaced the Render() code with a comment because it's quite long winded and doesn't add anything important here:
[Code]....
I have tried to follow examples on MSDN and other forums but I can't make this work. I think I'm missing the code to render the contents of the template, but I don't know how to hook that up.
View 1 Replies
Dec 20, 2010
created a Custom Textbox Control that is intended to be a "masked date" textbox, so that I can handle different ways a user might enter in a date and make it work no matter what.I did this by creating a custom control with 3 separate Textboxes one for month,one for day one for year,then do some handling for different things that could be entered and it would all work.
The problem I am having is,when I add this control to the page,if I do an alert to check the Text value of the custom control it just gives me "[ServerControl1]" even if I enter in a date.
I tried doing an AutoPostback after entering so that it would refesh the Viewstate to have the values of the textboxes but the control doesnt seem to actually postback, even though I have it enabled.accessing the Textbox value after someoen
has entered a date?first custom control I have created and have been using google.
My Server Control Code is as follows:
[Code]...
View 1 Replies
Oct 27, 2010
I have created a user control and am ready to convert it into a custom control. I am trying to follow:
[URL] the steps mentioned in the link.
I am not seeing Build / Publish Web Site option.
I am using VS 2008. I only see Publish User Control but it doesn't give all the settings mentioned below. When I do publish user control, it just copies the ascx file to the desired location. how can I convert the user control to custom control.
View 2 Replies
Jul 15, 2010
I add one or more textbox controls to a repeater itemtemplate during OnItemDataBound.
The textbox controls are instantiated and then added to a placeholder.
My problem is getting the user entered values from those dynamically added textboxes. They do not seem to exist in the repeater items collection.
[Code]....
[Code]....
View 9 Replies
Oct 12, 2010
I have 3 pages in each page there is a portion of page where it is common in all these three pages.Thought of making the common stuff as a separate control either User control/Custom control.Any suggestions on which one should i use custom/user control
View 2 Replies
Jan 3, 2011
Hope this is the correct forum for this question. I am using VWD 2010 an have a web project and get the following error upon execution:
Parser Error Message: Unknown server tag 'custom:AjaxValidator'.
My code is as follows in the .cs file:
[Code]....
[Code]....
View 1 Replies
Jun 1, 2010
In my default.aspx page I have a PlaceHolder control within an UpdatePanel. In this placeholder control I will dynamically load a web user control, which is just a form with a submit button. On this user control, I have the form within an update panel and I have the "Submit" button's Click Event added to the triggers.
When I submit the form, the UpdatePanel on the web user control nor the update panel on the default.aspx page are capturing the post back, thus causing a full post back which refreshes my page.
how to capture this post so its rendered in Ajax and not a full post back?
View 1 Replies
Aug 9, 2010
I have a site using eight (so far) custom web user controls and two of them have started misbehaving in design view. When designing the control itself some (in one control) or all (in the other) regular controls (labels, text boxes, etc.) disappear from the design view surface. They can still be seen in the source view and if the control is hosted on a regular .aspx page the control displays properly. The code window recognizes all controls in the objects dropdown list and I can write appropriate code. The controls run properly on their hosted pages.
If I switch to Split view and select controls in the source view panel a very small area od the design surface becomes selected (like one pixel for any of us who remember programming old DOS applications with 80-column screens) but no controls can be seen.
In short, the controls work in every respect except that I cannot see all or part of the design surface in Design view when editing the controls directly.
I've double-tripple checked the source code for anything that may be causing this and just don't see anything. (The controls aren't that complicated.)
View 2 Replies
Oct 22, 2010
I want to create a custom control where I define several specifically named DIV sections. The code-behind logic of the custom control will perform operations on these named DIV sections. The page where the custom control is hosted needs to be able to add named controls to the DIV sections and perform operations on these named controls added to the DIV sections.
Let me explain a little further. In the custom control, I want to have code behind logic that fires the following Page Event and uses a condition to make one or another specifically named DIV section visible or not:
< _
ToolboxData("<{0}:BaseDetails runat=""server""></{0}:BaseDetails>") _
> _
Public Class BaseDetails
[code]...
how can I create a custom control which is able to generate the named DIV sections "DetailsNameDiv1" and "DetailsNameDiv2" where my custom control can check a condition and make one or the other visible. Also, I need to be able to add controls to these named DIV sections when I host the custom control and the control that I add to the named DIV section needs to let me set values of these controls from the code behind logic of the page (or usercontrol) where the custom control is being hosted (in my example, I am adding TextBox controls that I want to set the Text property from a SQL Data Reader).
View 3 Replies
Feb 25, 2011
I have created a really simple custom control to render panels into a page. The code is below. When I use my control and add any webcontrol to it, after each page postback the contents of these child controls vanishes.
I must have missed something really simple but run the example to reproduce this. Can anyone please enlighten me as to why the controls are being 'emptied' of their contents, and how I stop this occuring?
Here is the code for the control
[Code]....
And here's how I am using it in a sample page:
[Code]....
[Code]....
View 16 Replies
Jul 8, 2010
I'm building an n-tier application, with the web client and the class library separate. I'm also using the factory pattern of development, using interfaces to act as containers for different objects they are associated with. The problem I'm expreriencing is that I declared a public interface class in the class library and I can create an instance of it in in my aspx pages but whenever I declare it in my custom control code-side, i get an error, like so:
Error 20 The type or namespace name 'IContentMaker' could not be found (are you missing a using directive or an assembly reference?)
notge that I have inherited the class library namespace using the 'using' keyword just in case you are wondering. My code is like so:
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using TQO_Classes ; //importing the class library project
public partial class PageContentMgr : System.Web.UI.UserControl
{
private IContentMaker _data; //this line throws the error, it works fine on aspx pages
View 1 Replies
Jun 15, 2010
I have an ASP.net web application project written in VB. Am trying to test a cobbed-together "MyTreeview" control put together from C# code that's been converted.
I think this will come "close" to what I'm trying to do - just get a treenode to have a CSS tag and render properly.
I have an App_LocalResources directory and a file called CustomTreeNode.vb. Inside that file is the following code:
[Code]....
[Code]....
[Code]....
View 1 Replies
Dec 31, 2010
I have a Custom Server Control with a Collapsible Panel Extender. I want to be able to keep the Collapsable state (open or closed) when doing a Post Back.
Here is my Custom Control's ASP code:
[Code]....
View 1 Replies
Sep 3, 2010
Iam developing a custom checkbox control deriving from the 'compositecontrol' which i need to use it for a composite control purpose.
public
class
TngCheckBox :
CompositeControl
{
i have written the required properties which are working fine except the "checked" property. here is my code for 'checked' property. i tried both the below ways (commented one and not commneted) . the problem is the 'checked' value is not setting the value at the get set part of the property.its assigning the value at the design time , but when i check and uncheck its not updating the property value.which is resulting me wrong .
[Code]....
View 2 Replies
Oct 15, 2010
Iam developing a custom checkbox control deriving from the 'compositecontrol' which i need to use it for a composite control purpose.
public
class
TngCheckBox :
CompositeControl
{
i have written the required properties which are working fine except the "checked" property. here is my code for 'checked' property. i tried both the below ways (commented one and not commneted) . the problem is the 'checked' value is not setting the value at the get set part of the property.its assigning the value at the design time , but when i check and uncheck its not updating the property value.which is resulting me wrong .
[Code]....
View 4 Replies
Dec 26, 2010
I have built a custom control. when i add this custom control in my page twice or more then the it write only one time of its render contest data.
View 4 Replies
Jul 6, 2010
I try to mak a custom textbox. Something pretty easy to do but I can't figure out one thing. When I write my textbox in designmode I have this <custom:Textbox runat="server" ID="Textbox1">Test</custom:Textbox> The problem is The textbox is a webcontrol I added to my class [Parsechildren(false)] like this [Parsechildren(false)]
public class Textbox : WebControl
{
}
now the problem is I want to able to write the Text from the textbox between the beginningtag and andingtag but I want to disable every other control in designmode. When I add < between the tags then you can see you can write all tags between it. disable all controls except literal between the tage in designmode?
View 4 Replies