Web Forms :: Add Children Controls Within A ServerControl Tags?
Nov 10, 2010
I'm working on a Navigation Menu. I've created below ServerControl and it works, but I want to allow users adding some standard ASP.NET controls within my ServerControl Tags like label, image and so on.
<MdsMenu:ServerControlMenu ID="ServerControlMenu1" runat="server">
<MdsMenu:animation AnimationSpeed="Normal" AnimationType="Opacity_Height" Delay="1000" DropShadow="true" />
<!-- HERE HAS TO HAVE SOME STANDARD ASP.NET CONTROLS -->
<!-- e.g <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> -->
</MdsMenu:MenuItem>
</MdsMenu:ServerControlMenu>
My problem is here that how I can get Child Controls within <MdsMenu:MenuItem> and show them like as they are in the output.
P.S:
I overwrite RenderContents method
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(OutPutStringBuilder.ToString());
}
View 2 Replies
Similar Messages:
Nov 10, 2010
I'm working on a Navigation Menu. I've created below ServerControl and it works, but I want to allow users adding some standard ASP.NET controls within my ServerControl Tags like label, image and so on.
<MdsMenu:ServerControlMenu ID="ServerControlMenu1" runat="server">
<MdsMenu:animation AnimationSpeed="Normal" AnimationType="Opacity_Height" Delay="1000" DropShadow="true" />
<!-- HERE HAS TO HAVE SOME STANDARD ASP.NET CONTROLS -->
<!-- e.g <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> -->
</MdsMenu:MenuItem>
</MdsMenu:ServerControlMenu>
My problem is here that how I can get Child Controls within <MdsMenu:MenuItem> and show them like as they are in the output. P.S: I overwrite RenderContents method
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(OutPutStringBuilder.ToString());
}
View 2 Replies
Nov 17, 2010
I'm working on a custom ServerControl, I've created it like below :
[ParseChildren(true), PersistChildren(true)]
[ToolboxData("<{0}:Menu runat="server"></{0}:Menu>")]
public class Menu : WebControl
{
.....
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public MenuItem MenuItems { get; set; }
}
[ParseChildren(true), PersistChildren(true)]
public class MenuItem : WebControl
{
......
[PersistenceMode(PersistenceMode.InnerProperty)]
public MenuItem SubMenuItems
{
get
{
if (_SubMenuItems == null) return new MenuItem();
return _SubMenuItems;
}
set
{
_SubMenuItems = value;
}
}
private MenuItem _SubMenuItems;
[TemplateContainer(typeof(MenuItem))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate Template { get; set; }
}
<%@ Register Assembly="JQueryMenu" Namespace="JQueryMenu" TagPrefix="MdsMenu" %>
<MdsMenu:Menu ID="Menu1" runat="server">
<AnimationItems AnimationSpeed="Fast" AnimationType="Opacity_Height" DropShadow="true"
Delay="1000" />
<MdsMenu:MenuItem ID="MenuItem1" runat="server" Text="MenuItem 01">
<MdsMenu:MenuItem runat="server">
<Template>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:CheckBox ID="CheckBox1" runat="server" />
</Template>
</MdsMenu:MenuItem>
</MdsMenu:MenuItem>
<MdsMenu:MenuItem ID="MenuItem2" runat="server" Text="MenuItem 01">
<MdsMenu:MenuItem ID="MenuItem3" runat="server">
<Template>
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:CheckBox ID="CheckBox2" runat="server" />
</Template>
<MdsMenu:MenuItem ID="MenuItem5" runat="server" Text="MenuItem 05">
</MdsMenu:MenuItem>
<MdsMenu:MenuItem ID="MenuItem6" runat="server" Text="MenuItem 06">
</MdsMenu:MenuItem>
<MdsMenu:MenuItem ID="MenuItem4" runat="server">
<Template>
<asp:Image ID="Image1" runat="server" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</Template>
</MdsMenu:MenuItem>
</MdsMenu:MenuItem>
</MdsMenu:MenuItem>
</MdsMenu:Menu>
Now, How can I Parse it and render it in RenderContent method ? !!!
The following method is always throw the first Exception, it means this.Controls is always empty !!! How can I do it and how I can access to the nested children in RenderControl method ?
public class Menu : WebControl
{
....
public override void RenderControl(HtmlTextWriter output)
{
if (!this.HasControls())
throw new Exception("Controls are empty");
....
}
}
View 1 Replies
Apr 30, 2010
How do you go about creating a complex servercontrol frontend?...I can't imagine you do Controls.Add() in the .cs files to add in divs, classes etc Can you embedd an ascx to make it easier to style?
View 5 Replies
Jan 25, 2011
I have a gridview that contains check box in first column for each row. I also have a check box outside the grid view called >>>>
<asp:CheckBox ID="chkSelectAll" runat="server" Text="Select All" AutoPostBack="true"
OnCheckedChanged="chkSelectAll_CheckedChanged" />
I either can select more than one checkboxes from gridview then click on a button to get the number of checkboxes selected OR I click on SelectAll checkbox ( which is outside the gridview ) which check all the checkboxes in the gridview and give me the number of checkedboxes. When I select inidividual checkboxes inside the gridview, th e count of number of checkboxes is correct ( displayed in a lable ) However;
When I click "SelectAll" check box, it give me total of all checkboxes chekced in the
gridview + 1 ( extra ) I am trying to get rid of this extra one by checking if this "Allcheckbox" is selected to so I subtract one from the total count .. like this
// java code ... code not shown does capture the total count into c variable
varAllChecked = document.getElementById('chkSelectAll');
if (varAllChecked.checked== true)
litCount.innerText = c - 1;
else
litCount.innerText = c;
View 5 Replies
Mar 1, 2010
I am not seeing the children controls on my web page when I hover over their parents. For example, I see the File, Edit and View menu items but I do not see the File->Open menu.
What am I doing wrong?
[Code]....
View 5 Replies
Nov 22, 2010
I'm working on a custom navigation menu, I've added the following property within my MenuItem class to allow users add them controls into it.
View 1 Replies
Nov 7, 2010
I'm gonna use JQuery files in my custom ServerControl , So I inserted jquery-1.4.3.min.js file into the Solution in JavaScriptFiles Folder. Now, I have to add below line within Head tag whenever a user use this ServerControl.
<script type="text/javascript" src="JavaScriptFiles/jquery-1.4.3.min.js"></script>
How can I do it in ServerControl with C#
View 4 Replies
Jun 4, 2010
I've been wracking my brains for a while. I have a master record that I want to add children to. In a database it's a one to many relationship with a foreign key in the child table.
I have a formview that I want to use to fill in all the master record info, and choose the child info from a dropdownlist, and click an add button, and have the add button add the child info to some control on a page. Then when the user clicks insert, the formview has an ItemInserting EventHandler that will handle all the logic for inserting the master, grabbing its primary Key.
So, I know what to do, I'm just not sure of what control to use, or what memory object etc., that I want to store the child info in until the master record gets created.
I'm sure this has been done a million times, but for all my searching, I couldn't find anything to help me. Does anybody have some advice or can anybody point me to an internet resource where this has been hashed out?
View 2 Replies
Dec 13, 2010
in ASPX, I set EVAL value on linkbutton,
<asp:LinkButton ID="LinkButton1" runat="server" Text='Show'
OnClientClick='myalerts(<%#Eval("RowId")%>);' />
but html code is:
<a onclick="myalerts(<%#Eval("RowId")%>);" id="LinkButton1">
how to correct set EVAL value on linkbutton,
ex:<a onclick="myalerts(1);" id="LinkButton1">
View 2 Replies
Mar 22, 2011
How do I stop the extender from providing shadows to a parent controls children?
I have a Panel (which the dropshadowextender is associated with), the panel contains a couple of labels. Currently the labels are shadowed.
View 1 Replies
Jan 19, 2010
I have a basic CMS which I'm adding to a site to display some downloads organised into groups. I have two tables, one for the groups and one for the downloads. I'm using a repeated to display the groups with another repeater inside to display the children. This works perfectly.
However some of my download groups may not have any downloads related to them and I'd like to handle this by filter the groups so that only those with a relate download record(s) are shown.
I'm trying to do this with the query which populates the top repeater based on some ideas I read but I must be going wrong with the syntax.
Here is what I'm using to try and only select downloads groups which have downloads linked to them by the download group ID.
[Code]....
Can anyone offer any thoughts on how I should construct the query to perform this?
View 1 Replies
Nov 14, 2010
I'm working on a ServerControl (SuperFish Menu).Below is my codes.Menu.cs
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[ParseChildren(true, "MenuItems")]
[code]...
View 1 Replies
Jun 26, 2010
i have created a aspx page with the script manager, update panels and so on. Now, when i use some jquery functions which are included inside the head tags, when the page is run, i find the script tags generated inside the body instead of the head tag. i'm using visual studio 2005 only.
View 2 Replies
Feb 24, 2011
I am building a forum and I want to use forum-style tags to let the users format their posts in a limited fashion.Currently I am using Regex to do this.As per this question:How to use C# regular expressions to emulate forum tags. The problem with this,is that the regex does not distinguish between nested tags.Here is a sample of how I implemented this method:
public static string MyExtensionMethod(this string text){return TransformTags(text);}
private static string TransformTags(string input)
{string regex = @"[([^=]+)[=x22']*(S*?)['x22]*](.+?)[/(1)]";
MatchCollection matches = new Regex(regex).Matches(input);
for (int i = 0; i < matches.Count; i++)
var tag = matches[i].Groups[1].Value;
var optionalValue = matches[i].Groups[2].Value;
var content = matches[i].Groups[3].Value;
Now,if I submit something like [quote] This user posted [quote] blah [/quote] [/quote] it does not properly detect the nested quote.Instead it takes the first opening quote tag and puts it with the first closing quote tag.Do you guys recommend any solutions?Can the regex be modified to grab nested tags?Maybe I shouldn't use regex for this?
View 3 Replies
Nov 7, 2010
I'm gonna use JQuery files in my custom ServerControl , thus I have to add below line within Head tag.
<script type="text/javascript" src="jquery-1.4.3.min.js"></script>
How can I do it in ServerControl with C#
View 1 Replies
Mar 30, 2010
I've written a ServerControl that contains a significant amount of javascript, and I'm using IScriptControl to pass parameters from the server code to the javascript. The javascript file is configured as an embedded resource, and a script reference to the file is being injected into the html by IScriptControl.GetScriptReferences(). The ServerControl is contained in a DLL assembly. When I use the control in a test page everything works fine.
What I want to do is to extend the control - to derive a new control from it, in a second assembly, that provides some extended functionality. (The first assembly contains code that is shared across customers, the second code that is shared across several projects for the same customer). So, my problem: I create a new ServerControl that derives from the first, but doesn't yet provide any new functionality.
[Code]....
Then I change my "<%@ Register ... %>" tag in the test page to reference the derived control. Things compile just fine, and the code-behind runs fine, but I get an undefined variable error in javascript. Sys.Application.add_init() is calling $create(), passing the <namespace>.<classname> of the javascript class, and it's throwing an error on the namespace.
Now, the namespace is registered on the first line of javascript file. Which makes it look like the javascript file might not be being included, when using the derived control. So I stuck a "debugging" line in front of the Type.registerNamespace(). Using the base control, the debugger breaks as it should. Using the derived control, it does not.
So, I look at the script includes in both versions of the page. They are identical. The sources are src="/testing/WebResource.axd?<random junk>", or src="/testing/ScriptResource.axd?<random junk", so I'm not sure which one refers to my embedded javascript file, but whichever one it is, the includes are identical between the page using the base control that works and the page using the derived control that does not.
View 1 Replies
Apr 8, 2010
I got a master page with a server control in it. Randomly the server control is inaccessible from codebehind. This doesn't happen on a specific action (eg a Button click or so). Currently I have no clue what this could be. I don't think it's output caching since this is not explcitly activated and the error happens far to seldom for that. But I'm going to disable caching in the master page explicitly with next deployment.
The control is defined in markup. The accompaning codebehind is:
PGFMainNavi.HasAccessToFunction = HasAccessToNaviItem;
// HasAccessToNavi is a local function
Exception is:
System.NullReferenceException: Object reference not set to an instance of an object
View 1 Replies
Feb 10, 2011
I have the following ListView:
<asp:ListView ID="procedureTicketList" runat="server" ...
<ItemTemplate>
<asp:GridView ID="MyGridView" runa...
How can I access to MyGridView programmatically ?
View 2 Replies
Feb 1, 2011
Is there a way to apply your own CSS tags to <li> tags when using ASP .NET 4.0 menu control? For example, say I have an external style sheet that has tags "class1", "class2", "class3", and etc. I want to apply "class1" to the first menu item. Then if menu item is selected, I want to apply "class2" and if it's not selected, "class3". I played with various 'Static' styles, but just can't get it work. I finally gave up and created my own menu control that extends ASP .NET menu control and provides my own custom rendering. This works, but I'm wondering if there is a way to get it work with built-in menu control.
View 1 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
Apr 23, 2010
Can someone point me in the right direction for adding a parent then sending the user to a new page to add children one by one?
My example: Exam (Parent) to ExamQuestion (Children).
View 5 Replies
Jun 22, 2010
I have such XMl
<root>
<list>
<list>
<topic></topic>
<topic></topic>
</list>
<topic></topic>
<topic></topic>
</list>
<topic></topic>
<topic></topic>
<topic></topic>
</root>
I need to get the first level of children:
<list></list>
<topic></topic>
<topic></topic>
<topic></topic>
I try to do like this
var list = x.Descendants().Where(e => e.Name == "list" || e.Name == "topic");
View 1 Replies
May 26, 2010
I have very strange Cascading Dropdownlist behavior. When I use one parent, one child - everything is fine, but one parent two children combination does not work well. Sometimes both children show right data; sometime first is fine and second is grey, or first is fine and second [Method error 500], or second is fine and first is wrong and so on.
Did somebody try to use parent two children combination?
View 4 Replies
Mar 14, 2011
I have two tables in SQL. The first defines the parent, and has a primary key column called ParentId. I also have a child table that has a primary key, and a foreign key as 'ParentId'. So the two tables form a one parent - to many children relationship.
The question is what is the most efficient way to pull the parent + child data C# code? The data has to be read into the following objects:
[Code]....
and use LINQ to merge all parents with children. This approach makes 2 trips to the db.
The third and final (also most inefficient) approach is to grab all parents, and while constructing each parent object, make a trip to the DB to grab all its children. This approach takes n+1 connections: 1 for all parents and n number of trips to get all children for each parent.
Any advise on how to do this easier? Granted i can't get away from using stored procedures, and I can't use LINQ2SQL or EF. Would you prefer Data Tables vs DataReaders and if so how to use either with approach 1 or 2?
View 4 Replies