How To Move .NET PlaceHolder Control From Page Controls Collection To Custom Control's Output

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


Similar Messages:

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

Custom Server Controls :: Property Collections Not Persisted When Control Inside Update Panel And Content Placeholder

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

Custom Server Controls :: Add This Control To The Page,an Alert To Check The Text Value Of The Custom Control?

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

AJAX :: Web User Control Loaded Into PlaceHolder Control Causing Full Postback On Parent Page?

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

Adding To Page Control Collection From Inside A User Control?

Feb 12, 2011

I have an asp.net usercontrol which represents a "popup" dialog. Basically, it's a wrapper for the jQuery UI dialog which can be subclassed to easily make dialogs.

As part of this control, I need to inject a div into the page the control is used on, either at the very top or very bottom of the form so that when the popup is instantiated, it's parent is changed to this div. This allows "nested" popups without the child popup being trapped inside the parent popup. The trouble is, I can't find a safe way to inject this div into the page. A usercontrol doesn't have a preinit event, so I can't do it there, and calling Page.Form.Controls.Add(...) in Init, Load or PreRender causes the standard exception "The control collection cannot be modified during DataBind, Init, Load, PreRender or Unload phases."

I thought I had found a solution by using...

ScriptManager.RegisterClientScriptBlock(Page, Me.GetType, UniqueID + "_Dialog_Div", containerDiv, False)

... which seemed to work well normally, but recently a coworker tried putting an UpdatePanel inside the dialog and now she's getting the error "The script tag registered for type 'ASP.controls_order_viewzips_ascx' and key 'ctl00$ContentBody$OViewZips_Dialog_Div' has invalid characters outside of the script tags: . Only properly formatted script tags can be registered."

How are you supposed to add controls to the pages control collection from inside a user control?

View 2 Replies

C# - Give A Custom Control Ability To Parse XML Markup To A Collection?

Apr 1, 2010

I'm writing a custom ASP.NET webcontrol and would like it to have a collection of custom items which can also be specified in the XML markup. Something like this:

class MyControl: WebControl
{
public IList<MyItemType> MyItems { get; private set; }
}

And in the markup:

<asd:MyControl runat="server" id="mc1">
<MyItems>
<MyDerivedCustomItem asd="dsa"/>
<MyOtherDerivedCustomItem asd="dsa"/>
</MyItems>
</asd:MyControl>

How do I do this? I though this was all about implementing some interface on the collection or adding some special attributes to the property, but nothing I do seems to work.

View 2 Replies

Custom Templated Control - To Modify Where Databound Data Is Output To?

Aug 31, 2010

Basically, I have a custom templated control with a custom data container class. When a developer adds an instance of my control to a page, they can define the controls in the LayoutTemplate however they like, as follows:

<ml:MyControl id="MyControl1" runat="server">
<LayoutTemplate>
<span><%#Container.ErrorMessage%></span>[code]...

I would like my control to automatically move the "ml_errormessage" (databound content from Container.ErrorMessage - hard coded token in the property) to be a class of its containing element to make it easier for jQuery to use a selector to find the element and dynamically insert the error message client side. More importantly, I would like it moved out of the way so the class name doesn't get replaced by the content and jQuery can find it as many times as it needs to during the page lifecycle. In other words, I would like the output to look like this without the developer changing the input template or resort to using custom controls in the template:

<span id="MyControl1"><span>
<span class="ml_errormessage"></span>
</span></span>

I would like to move the value using the controls collection rather than resorting to string parsing of the output, if possible. However, when I interrogate the collection in an override of OnPreRender, the control in the template looks like this in the debugger:

{System.Web.UI.DataBoundLiteralControl}
System.Web.UI.DataBoundLiteralControl: {System.Web.UI.DataBoundLiteralControl} [code]...

As you can see the "ml_errormessage" value is nowhere to be found. Upon analysis of the DataBind event of the Control class using Reflector, I see that it delegates the binding behavior to each control. In other words, each control handles its own databinding. However, since I have no way of knowing in advance what control types will be in the template, how can this change be done?

Note: an acceptable alternative would be to add a new HtmlGenericControl (span) in the exact spot where the "ml_errormessage" is and add it as a class to this new control.On a side note, is there an easy way to get the control's output to indent for easy reading during debugging?

View 1 Replies

Forms Data Controls :: Finding A Control From A Control Collection?

Aug 24, 2010

I'm trying to write a bit of code that will format all the numeric values in lables in my gridview. here's what i am doing right now:On the RowDataBound Event, i create a row object for the row that is currently being bound.then i go use the FindControl method to grab each label by name.Problem is there's too many columns in this table and i really dont wnat to have to type it all out. Here's an example of what i am currently doing

[Code]....

Can i use myRow.Controls to grab a list of all the controls and then somehow get a list of all labels in the collection and then use a for loop to go through and format each label?

View 2 Replies

Custom Server Controls :: Custom Control's Constructor / User To Set That variable In The Properties Window After They Drag The Control Onto A Form?

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

Custom Server Controls :: Paging And Sorting Gridview Custom Control Inside Of A Wizard Control?

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

To Create A Custom Control That Adds Other Controls Visible To The Page Hosting My Custom ?

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

Custom Server Controls :: Unable To Convert User Control To Custom Control

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

Control Collection Iteration For Master Page?

Mar 22, 2010

I have made an asp.net website which is using master page in it.

my programming language is c#. I want to iterate through content page controls but i m not able to do it. I have searched a lot on internet but of no avail.

View 1 Replies

C# - Add Reference To Method In Custom Control To A Child Control Created In That Same Custom Control

Feb 3, 2010

I have a custom control that is based off the gridview control located at: here The control is basically a gridview that automatically creates a column of checkboxes that can be used to "check" individual rows in the gridview. During the gridview's "CreateColumns" event, the "checkboxcolumn" is created dynamically. The checkboxcolumn also contains another checkbox in the header that is used to "select/deselect all" checkboxes in the column. Since the gridview does not automatically remember the state of the checkboxes in the checkboxcolumn on postback, I added a method to the control called "SaveCheckBoxState" which stores the indexes of the checked rows in Viewstate, and then I modified the "OnRowDataBound" event to check the Viewstate and reset the checkboxes based on the Viewstate.

I then added a call to "SaveCheckBoxState" in the gridview's OnSorting and OnPageIndexChanging events. This works great so long as I'm sorting or changing pages. However, I need it to update the viewstate everytime someone clicks or unclicks one of the checkboxes. At this time, the checkboxes are rendered with an onclick event that calls some javascript to highlight the row, or in the case of the checkbox in the header, to select/deselect all checkboxes. I need to call the "SaveCheckBoxState" method from the javascript used by the customcontrol, or I need to find a way to modify viewstate from javascript and perform the same action as "SaveCheckBoxState".

I've tried adding the "SaveCheckBoxState" to the onclick event declaration in the checkboxes, but when run, it simply tells me that the method is undefined. It doesn't exist in the parent page, and I don't think I should have to make an event for the parent page to pass the click to. It seems to me this should be all self contained within the custom control. Does anyone know how I can acheive this? Here is the code for the gridview OnPreRender event where the onclick event of the checkbox is set:

protected override void OnPreRender(EventArgs e)
{
// Do as usual
base.OnPreRender(e);
// Adjust each data row
foreach (GridViewRow r in Rows)
{
// Get the appropriate style object for the row
TableItemStyle style = GetRowStyleFromState(r.RowState);
// Retrieve the reference to the checkbox
CheckBox cb = (CheckBox)r.FindControl(InputCheckBoxField.CheckBoxID);
// Build the ID of the checkbox in the header
string headerCheckBoxID = String.Format(CheckBoxColumHeaderID, ClientID);
// Add script code to enable selection
cb.Attributes["onclick"] = String.Format("ApplyStyle(this, '{0}', '{1}', '{2}')",
SelectedRowStyle.CssClass,
style.CssClass,
headerCheckBoxID);
// Update the style of the checkbox if checked
if (cb.Checked)
{
r.BackColor = SelectedRowStyle.BackColor;
r.ForeColor = SelectedRowStyle.ForeColor;
r.Font.Bold = SelectedRowStyle.Font.Bold;
}
else
{
r.BackColor = style.BackColor;
r.ForeColor = style.ForeColor;
r.Font.Bold = style.Font.Bold;
}
}
}

View 1 Replies

Maintain ViewState Of PlaceHolder / When Page Get Refresh All Controls From Placeholder Gets Removed From It?

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

Datasource With Parameter In ASPX Page To Move In User Control

Sep 2, 2010

I have a page with some datasources in it. I am doing reenginering of the page itself and would like to split some parts of the page in several user controls.

In my code I have an ObjectDataSource object with the following params

[code]....

This piece of code automatically bind the hidden field "txtAlbumId" to the datasource. In my revision this datasource should be moved to a user control.

View 2 Replies

VS 2010 - Move Control On Page / Change Position To Absolute

Jun 2, 2014

Just started using VS2010. I am not able to move controls, in the CSS styling I checked the "Change position to absolute...." and still I am not able to move controls. Some other set up I missed?

View 3 Replies

Custom Server Controls :: Use Custom Control/user Control?

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

Output Caching A Page Except A User Control In It?

Mar 4, 2011

I have a page which contains a user control. The structure of the page is as shown below:

Incase your not able to see the above image, check it at [URL] Now, apart from the contents of the UserControl, I'd like to cache the entire page. I tried using the OutputCache attribute in the .aspx page, however it caches the contents of the UserControl as well.

View 4 Replies

Custom Server Controls :: Extended GridView.Rows Collection Always = PageSize Even On Last Page?

Mar 22, 2010

Using VS2005, VB code behind,

I am extending the GridView control to include a custom pager for a custom paging scheme (only one page returned from the database at a time rather than all records). In my testing a discovered an issue - on my last page of data, the GridView's rows property always returns a collection of PageSize page, rather than the actual number of records on the page, with non-data fill records being empty rows.

For example, suppose I have 23 records in my database. Assuming a PageSize of 10, when I page to the last page of data the gridview it properly displays the last 3 recrods - but when I handle the GridView's CommandName="Select" event the GridView's Rows collection contains 10 records, the last seven of which are empty.

I set a break point in just before I call GridView.DataBind and verified that the DataTable used as the DataSource for the last page of data does in fact only contain the 3 expected records. But when I set a breakpoint on the Sub that handles the "Select" GridView command, the GridView.rows collection contains 10 records, the last 7 of which are empty.

This post[URL] and comments make note of the issue but the solution prescribed by the author does not seem to work.

Attached are some snippets of my extended GridView and the two methods from my page where I mentioned setting breakpoints above.

Snippets from my extended GrdiView

[Code]....

MyReport.aspx.vb:

[Code]....

View 1 Replies

Custom Server Controls :: How To Use A Custom Server Control That Is Defined In Inline Code In The Same Page

Oct 22, 2010

I have to use inline code for an aspx page and I need to use a custom server control that is defined in the same aspx page but the control does not get processed as a server control. it gets returned as is as static html tag.

View 3 Replies

Forms Data Controls :: How To Add And Access To Placeholder In A Repeater Control

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

AJAX :: Unknown Error When Open Page In Iframe + (AjaxToolKit) - Can't Move Focus To The Control

Jan 4, 2010

In my application i use iframe (to be more specific; Greybox tool). Sometimes i had an unkown error when i open page in iframe. Then i applied this fix : [URL] and that unknown error disseppeared. But i have another problem now:( I am using following script to focus to the first textbox whenever my input pages are opened in iframe.

aField = document.getElementById('txt_PID');setTimeout("aField.focus()", 50);
After i applied previous fix, i get this error when i load page in iframe for the first time :

Can't move focus to the control because it is invisible, not enabled, or of type that does not accept focus.
Here, txt_PID doesnt contain any ajaxtoolkit things. (also Enabled= true and Visible=true etc.) . Last thing, my current test page contains just 3 controls: txt_PID just plain Asp.TextBox ajaxHTMLEditor another textboxt with MaskedEditExtender. If i remove HTMLEditor from page; i dont get that error( Can't move focus...) and also i dont get first error which i applied that fix in toolkit.

View 2 Replies

Custom Server Controls :: User Control Page C#?

Mar 25, 2011

i have a user control page and only have , which i have <div> and a gridview inside <div>how can i add a scroll bar in user control page?the code like below in aspx:<@regrister url="user control page" tagname="xx" tagprefix="aa"><div><aa: id="xx"></div> <--to embed user control page.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved