Creating A User Control With Variable Layout?
Oct 13, 2010
I have a user control which contains a number of child controls. I want to be able to change the layout of the control (i.e. change the markup surrounding the child controls) via a property of the user control, but I don't want to have to duplicate the child controls themselves. This precludes using, say, a MultiView with different versions of the layout in each view, since in that case I'd have to duplicate the controls. I'd also rather use markup than emit the code for the control directly (as you'd do in a server control).
To give a contrived example, say I have a label and a textbox. In one layout, I want the label and textbox to be contained by divs and laid out on top of each other. In an alternate layout, I want them to be contained side by side in a table.
Should I just go ahead and duplicate the controls between each view? It seems like a violation of the DRY principle, but I'm not sure if I have much choice. A partial solution would be making the views of a multiview into naming containers so that I could at least save myself the time of having to prefix the duplicate control IDs with something to make them unique.
View 3 Replies
Similar Messages:
Mar 5, 2011
It's simple to create both user control from the two world : ASP.NET+Razor or MVC 3.0.But i do not known how to consume the user control FROM the razor"_layout.chtml" page.I want to put such thing within the layout page: <uc:MyTag Prop1="" Prop2="" />So i need to declare this directive at top of the layout file : <%@ Register TagPrefix="uc" TagName="MyTag" Src="Controls/Mytag.ascx" %>
View 1 Replies
Feb 2, 2010
I have a user control that contains an image of a product along with some product details.
If the product image is landscape, I want to render the control one way, and if the product image is portrait, I want to render the control a second way.
Example HTML Layouts (drastically simplified):
<div><table><tr><td>
<p><strong>XXXXXX</strong></p>
</td></tr><table></div>
versus
<div><table><tr><td>
<p><em>XXXXXX</em></p>
</td></tr><table></div>
Right now, both layouts are rendered. How can I conditionally render one layout and not the other?
View 13 Replies
Mar 8, 2011
I have a user control I'm building that has a table layout with two sets of radio buttons, like:
how I could use a radiobuttonlist for each set of vertical buttons within this layout, unless I used a rowspan on each col, but that seems problematic from a layout perspective? I would rather use a RBL from a programming standpoint.
If I instead used a set of radiobuttons with a groupname for each, how do I get/set the selected button (for each set) from outside the UC?
View 2 Replies
Jun 23, 2014
I need to create below layout using Div's. i should not use table to create this. also i need to do this with css and I have to use % for width and height. Any sample code. on the below image left border is missing. But I want that as well.
View 4 Replies
Feb 1, 2010
i spent a few days in creating layout of asp.net pages using the tables and found it really tough to deal with.....
now i want to have a go with the css but not the asolute positioning of the css......
so what are the tags of css which will be helpful to me for creating layouts of my asp.net pages?
View 4 Replies
Mar 7, 2011
I am having one doubt regarding the use of static variable in Asp.net pages.I am having one page say UserDetails.aspx.In this page, I have one static variable to store some data specific to a user. So, will this ?
public partial class UserDetails
{
static int numberOfReviews=0;
[code]...
View 5 Replies
Jun 17, 2010
I am using the below example code and have a problem where I can't pass the Request.RawUrl value into an object that extends the Control object (class Test below).When I use the line:
<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %>"></Test1:Test>
I find that the Target property is never called.If I use this line instead:
<Test1:Test runat="server" ID="testControl" Target="<%# Request.RawUrl %> test"></Test1:Test>
the string value "<%# Request.RawUrl %> test" is passed to the Target property.f I use this line as explained in many posts online:
<Test1:Test runat="server" ID="testControl" Target="<%= Request.RawUrl %>"></Test1:Test>
the string value "<%= Request.RawUrl %>" is passed to the Target property.I need to get the value of Request.RawUrl passed to the Target Property of my Test control object. Does anyone have any ideas where I am going wrong?Control:
namespace Testing
{
public class Test : Control
[code]...
View 1 Replies
Oct 29, 2010
I have a property on a page called
public string productName { get; set; }
I want to access this in my usercontrol code behind. What's the right way to do it?Currently I am doing
((MyPage)Page).productName
But the user control is not compiling. My pagename is MyPage and I have also added a Reference
<%@ Reference VirtualPath="~/MyPage.aspx" %>
View 1 Replies
Mar 3, 2010
I am trying to modify a .ascx file, to declare a variable. I've read that this is normally done in the code behind view, but I do not have access to the code behind, and this is a very small addition. We are using DotNetNuke, and in the .ascx file I have written
<script runat="server">
String foo = "bar";
</script>
And this causes the page to explode. I have some experience with PHP, but am very new to .NET. Is there a way to define a variable in a .ascx file in this way? Maybe I have not imported all the correct libraries at the top of the page?
View 7 Replies
Jun 17, 2010
I have a simple user control which toggles between the visibility of a few images depending on the UserId. When the page is loaded for the first time, the userID is being assigned correctly (I'm debugging). However, there are two other buttons on the page for filtering the type of users, they are perform their functionality via Ajax (not the toolkit, but the normal javascript ajax) When one of these buttons are clicked, the user control cant get the userid, it always comes up as Zero. Oh, btw, the usercontrol is in a DataRepeater, so it occurs for each of the user.. all the time.. or thats the Idea. I have several other pages like this, (none of them have ajax) and the user control has no problems whatsoever.
My User control code:
[Code]....
And the Data Repeater is something like this:
[Code]....
Here, Immediately after the userControl <ucAB:....> line, I am printing the userid just to see if its valid (by <%# Eval("UserId") %> and the user id's are valid too. I dont understand why the User Control cant pick it up on ajax postback?
View 3 Replies
Oct 29, 2010
I have a property on a page called
public string productName { get; set;}
I want to access this in my usercontrol code behind. What's the right way to do it? Currently I am doing
(MyPage)Page).productName
But the user control is not compiling. My pagename is MyPage.
View 2 Replies
May 17, 2010
I am new to web design so bear with me. I have an .aspx page with a user control at the top that is basically a container for an image. It serves as a banner spanning the entire page. The lower part of the page is a left and right sidebar with a main middle section.
The image is simply some text at the left layered over a background that fades from blue to white, top to bottom. Image size is 90 p. high by 1000 p. wide. How can I get this image to vary width withing the control along with the rest of the page when rendered under different screen resolutions?
View 1 Replies
Feb 11, 2010
I have a user control which has a Gridview and a listview, I want to make this control generic so that I can just pass the type of the class I want to edit, which would be a linq entity, and then it would automatically do the rest, so far I havent had any success and I was wondering if anybody knows a tutorial or some info about doing this?
View 1 Replies
Feb 12, 2010
I have a problem with ViewState. I have an aspx page that has a treeview on the left and an UpdatePanel with an ASP.NET Panel inside on the right. It is in that inner Panel where I load and unload dynamically user controls. I use that update panel to load dynamically controls.
I also made a custom control for my user controls because I need to pass some values from page. On that constructor I use ViewState to store these values.
The first time I load the user control I call its constructor with parameters. When I reload that user control on each postback I use its normal constructor.
My problem is I the values I've stored on ViewState has become null on successive postback.
Update:
This is a piece of my user control:
public class MyUserControl : System.Web.UI.UserControl
{
private int PKId
{
get { return ViewState["pkId"] as int; }
set { ViewState["pkId"] = value; }
}
public MyUserControl(int pkId)
{
this.PKId = pkId;
}
...
}
I'm following this article to load controls dynamically: http://msdn.microsoft.com/en-us/magazine/cc748662.aspx#id0070065.
Second Update:
I also set the same control ID when I load the user control at first time and on each reaload.
Maybe I can use another method to store these values like input hidden fields or Cache. I've choosen ViewState because I don't want to overload server with Session values for each user.
Third update:
I load the controls with this code:
System.Web.UI.UserControl baseControl = LoadControl(ucUrl) as System.Web.UI.UserControl;
if (baseControl != null)
{
baseControl.ID = "DestinationUserControl";
PanelDestination.Controls.Add(baseControl);
}
And reaload with this code:
DynamicControls.CreateDestination ud = this.LoadControl(TrackedUserControl) as DynamicControls.CreateDestination;
if (ud != null)
{
ud.ID = "DestinationUserControl";
PanelDestination.Controls.Add(ud);
}
View 4 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
Sep 20, 2010
I find myself always repeating code when it comes to gridviews. I want to build a usercontrol so I can just set a datasource andcolumn types etc and I can use the same control over and over in different projects.
View 4 Replies
Dec 31, 2010
i'm developing a webusercontrol, that has very properties, properties are of custome types (not primitive), so i want user can edit properties in grid property. i want something like gridview here is a portion of my code:
[Code]....
[Code]....
View 4 Replies
Aug 11, 2010
I want to create a completely new control instead of extending an existing one. I have found a few articles on the net, but it's not exactly what I'm looking for. I've created Custom User controls in Win Forms before and thought it would be somewhat the same in ASP.NET, but it does not seem so. Many articles talk about a Web Control Library template which doesn't seem to be available when creating a New Project, but is available when adding a New item to an existing ASP.NET forms project in VS2008.
I have extended control by using the ASP.NET Server Control template. But all you get with is a .cs file. How do design a brand new control with that?What I want is to create a control from scratch, with postback functionality, and that compiles to a DLL. Am I going about this all wrong? Should I rather be looking at the ASP.NET Server Control Project Template? If so, How do I create a brand new control with the ASP.NET Server Control?I'm working with VS2008 SP1, .net 3.5, and C#.
View 2 Replies
Apr 10, 2010
I am using vb.net/asp.net 2005. I have a master page that displays a child content page. The child content page contains a user control that I created. In the user control I would like to access a variable that is set in the Master page.
View 3 Replies
May 4, 2010
i have following issue: I am creating a new user register form manually without CreateUserWizard control, and all works perfectly unitil I intentionaly (for test purposes) enter existing username (for example BLABLABLA) into username.textbox. After that i get my error message as expected that says "username BLABLABLA allready exist", now when I tray (as a future user who could be in the same situation) to correct the username and enter another one (for example TRATRATRA), it still gives me this error "username BLABLABLA allready exist!" This is the second day that I'm traying to solve this!
Here is a part of my code:
[Code]....
View 4 Replies
Jan 6, 2011
How can I define a value in a Razor Layout page to be used in the views that use that layout?
View 2 Replies
Feb 25, 2010
I am working on a page where user controls are dynamically added to the page and refreshed with a timer in an updatepanel.
Since I already coded dynamic user control loading into the page, I would also like to implement *some* form of dynamic layout method for those controls. I was thinking coordinate values.
I have used Top and Left properties on panels before to achieve this functionality in my windows forms applications but since this is a web application things are different.
I realize I can do the whole "absolute positioning layout model" override in Visual Studio but as far as I know this only benefits me at design time. Is there a way to programatically trigger that behavior?
I looked at the silverlight Canvas and how you can pass offset values in with your controls. Something like that would be great, but this isn't Silverlight, lol. I also considered a web method to return globs of html tags to fill the area between these controls.
This is a page that would be reused over and over from client to client so this is why I would like to get this dynamic layout working. It would save me much effort later on.
View 5 Replies
Dec 13, 2010
I have a custom CRM package and I need to allow specific users have different layouts on selected screens. I do not want to support multiple software packages so I am thinking that I have some type of interface that allows a user to select what fields they want to input on a given screen. However, what is the easiest way to make this happen? I am thinking that I have some type of XML file that is read that a user can define.
View 1 Replies
Jun 21, 2010
Is it possible to create a Custom Control which inherits from System.Web.UI.WebControls.Login and change its layout and add additional controls such as a DropDownList. I have tried various ways to do this by overriding the Render Contents methods but each time I have to recreate the controls which are already present in the main Login control. Is it possible to somehow get a reference to the controls in the parent class and then override the Render Contents method to render the controls how I need them?I would like if at all possible to use the controls and functionality that already exist in the Login control but just change the layout and add in an additional DropDownList control.
View 1 Replies