I got one problem, I have three user controls say Control1,control2, control3.
I want to make Control1 into 3 divs and see contol1 UI in first part
control2-2nd part of div
Control3- in 3 Part of div
Is it possible?
I wanted to do this just for the sake i can maintain with less code .Is there any alternative .other this which will suit me best.
Please suggest
Yes, you can put multiple user control on a single user control. However your question is down voted the solution of your problem is as given below :
Create a sample website. Add Webusercontrol1.ascx ,Webusercontrol2.ascx, Webusercontrol3.ascx, Webusercontrol4.ascx in it and modify the code as given below.
Default.aspx page html
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="SO_1._Default" %>
<%# Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
</asp:Content>
UserControl-1 Html : This is container user control and this will have all required user control on it.
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs"
Inherits="SO_1.WebUserControl1" %>
<%# Register Src="WebUserControl1.ascx" TagName="WebUserControl2" TagPrefix="uc1" %>
<%# Register Src="WebUserControl2.ascx" TagName="WebUserControl2" TagPrefix="uc2" %>
<%# Register Src="WebUserControl3.ascx" TagName="WebUserControl3" TagPrefix="uc3" %>
<%# Register Src="WebUserControl4.ascx" TagName="WebUserControl4" TagPrefix="uc4" %>
<p>
<b>DIV-1 Container User control</b></p>
<div>
<b>DIV1</b>
<br />
<uc2:WebUserControl2 ID="WebUserControl21" runat="server" />
</div>
<div>
<b>DIV2</b>
<br />
<uc3:WebUserControl3 ID="WebUserControl31" runat="server" />
</div>
<div>
<b>DIV3</b>
<br />
<uc4:WebUserControl4 ID="WebUserControl41" runat="server" />
</div>
UserControl-2 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-1
UserControl-3 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-2
UserControl-4 html
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl2.ascx.cs" Inherits="SO_1.WebUserControl2" %>
User Control-3
Related
In my webpage I use two user controls:
ucControl1 and ucControl2. The ucControl1 control also contains an instance of the ucControl2 control inside it.
When you run the application and go to the page in question, it appears that only the instance that is inside the ucControl1 is working correctly. When trying to execute the functionality of the ucControl2 that is directly on the page, it correctly executes the backend code, opens the modal correctly but does not show the results on the screen.
What could be happening?
The page is like this
<%# Page Language="C#" AutoEventWireup="true" CodeFile="PageSample.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="PageSample" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<%# Register Src="~/Controls/ucControl1.ascx" TagPrefix="uc1" TagName="ucControl1" %>
<asp:Content runat="server" ContentPlaceHolder ID="cpSampleID">
<div>
<uc1:ucControl2 runat="server" ID="uc2" />
</div>
<uc1:ucControl1 runat="server" ID="uc1" />
</asp:Content>
And the usercontrol1
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl1.ascx.cs" Inherits="ucControl1" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc1" TagName="ucControl2" %>
<%-- Something Something Something --%>
<uc1:ucControl2 runat="server" ID="ucControl2" />
I've found a solution. The modal is opened by javascript.
ucControl2
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl2.ascx.cs" Inherits="ucControl2" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<div id="modal">
<!-- Some Textboxes -->
</div>
Method to open the modal
public void OpenModal()
{
string id = "modal";
string js = $#"
$(document).ready(function() {{
if ($('.modal.in').length > 0) {{
$('.modal').on('hidden', function() {{
$('.modal').off('hidden');
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}});
$('.modal').modal('hide');
}} else {{
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}}
}});";
ScriptManager.RegisterStartupScript(this, this.GetType(), id, js, true);
}
So when the control is called, the javascript does not know which of the controls should open, and in this case it is opening the first control that is on the page.
To solve it I've changed the div through an asp panel, in this way asp generates a different client ID for each control and the controls are displayed correctly.
I'm referencing some user controls at the top of my page
however when I try to use the control its saying that the element is not a know element for page_header. I'm tearing my hair out with this can anyone help please?
<%# Page Language="VB" AutoEventWireup="false" CodeFile="automation_provisioning.aspx.vb" Inherits="customers_automation_provisioning" %>
<%# Register TagPrefix="cc" Namespace="Chessplc.Common.App.UI.Controls" Assembly="Chessplc.Common.App" %>
<%# Register TagPrefix="cc" Namespace="Chessplc.Common.App.UI.Validators" Assembly="Chessplc.Common.App" %>
<%# Register Src="../App_UserControls/paging_listview.ascx" TagName="paging_listview" TagPrefix="uc" %>
<%# Register Src="../App_UserControls/meta.ascx" TagName="meta" TagPrefix="uc" %>
<%# Register Src="../App_UserControls/page_header.ascx" TagName="page_header" TagPrefix="uc" %>
<%# Register Src="../App_UserControls/page_footer.ascx" TagName="page_footer" TagPrefix="uc" %>
<%# Register Src="../App_UserControls/menu_customers.ascx" TagName="menu_customers" TagPrefix="uc" %>
<%# Register Src="../App_UserControls/menu_contract.ascx" TagName="menu_contract" TagPrefix="uc" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<uc:page_header ID="ucHeader" runat="server" />
<form id="form1" runat="server">
<div>
<div id="main_content">
</div>
</div>
</form>
</body>
</html>
Thanks
Chris
So I'm the new guy on the dev team, trying to update a "Dashboard" type page, which is the default landing page for our users. The default.aspx page consists of 16 Web User Controls (.ascx). I've been asked to add stock "widget" on the dashboard, so users can monitor our company's stock symbol. To allow for different timeframes (1 day, 5 day, 3 month, etc) I was planning on using a Menu (tabs) within a new .ascx. When I try to use a menu, I get the error "Control 'StockDisplay_StockMenu' of type 'Menu' must be placed inside a form tag with runat=server". If I wrap the menu in form tags, I get the "A page can have only one server-side Form tag" error.
Most search results suggest looking at the Master Page, but we're not using one here. I checked The default.aspx page, and it does not have any form tags. Other searches suggested removing < head> and < body> tags in the .ascx, which I've done, but still I have the issue.
Here's my stripped down code, which still produces the error:
<%# Control Language="VB" AutoEventWireup="false" CodeFile="UC_StockDisplay.ascx.vb" Inherits="UC_StockDisplay" %>
<%# Import Namespace="System.Data" %>
<form id="Form1" runat="server">
<asp:Menu ID="StockMenu" runat="server">
<Items>
<asp:MenuItem Text="One Day" />
<asp:MenuItem Text="Five Days" />
<asp:MenuItem Text="Three Months" />
<asp:MenuItem Text="Six Months" />
<asp:MenuItem Text="One Year" />
</Items>
</asp:Menu>
</form>
Here's the default.aspx:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%# Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%# Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%# Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%# Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%# Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%# Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%# Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%# Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%# Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%# Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%# Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%# Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%# Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%# Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%# Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%# Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">
<center>
<img src="images\banner2.gif" border=0><br>
<font face="Courier New Bold" size=5 color=white>Helpdesk 3.5</font><br>
<table width=100% cellspacing=10>
<tr>
<td width="33%" valign=top>
<uc1:HelpUs ID="HelpUs" runat="server" />
<br>
<uc3:ImportantLinks ID="ImportantLinks" runat="server" />
<br>
<uc10:Directory ID="Directory" runat="server" />
<br>
<uc6:UCRequestForms ID="UCRequestForms" runat="server"/>
<br>
<uc7:MiscLinks ID="MiscLinks" runat="server" />
</td>
<td width="33%" valign=top align=center>
<uc5:WorkOrder ID="WorkOrder" runat="server" />
<br>
<uc8:Emergency ID="Emergency" runat="server" />
<br>
<uc2:ImportantNumbers ID="ImportantNumbers" runat="server" />
<br>
<uc11:Weather ID="Weather" runat="server" />
<td width="33%" valign=top>
<uc17:StockDisplay ID="StockDisplay" runat="server" />
<br />
<uc9:Floorplan ID="Floorplan" runat="server" />
<br>
<uc4:Printers ID="Printers" runat="server" />
<br>
<uc15:MyInfo ID="MyInfo" runat="server" />
<br>
<uc14:CoreValues ID="CoreValues" runat="server" />
<br>
<uc12:Holiday ID="Holiday" runat="server" />
<br />
<uc16:Travel ID="Travel" runat="server"></uc16:Travel>
</td>
</tr>
</table>
</center>
</body>
</html>
After adding one control you have a form with runat="server" tag:
<form id="Form1" runat="server">
<asp:Menu ID="StockMenu" runat="server">
You already mentioned you have 16 usercontrol in one page. So you have 16 forms with runat="server" tag. Which is not allowed.
Solution: As Chris Lively suggested, strip out the the form tag from your wsercontrols. Add just one form tag in the page. You should be ok.
Here's how should all your controls should look like:
<asp:Menu ID="Menu1" runat="server">
<Items>
<asp:MenuItem Text="One Day" />
<asp:MenuItem Text="Five Days" />
<asp:MenuItem Text="Three Months" />
<asp:MenuItem Text="Six Months" />
<asp:MenuItem Text="One Year" />
</Items>
</asp:Menu>
And your page should look like:
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%# Register src="UC_HelpUs.ascx" tagname="HelpUs" tagprefix="uc1" %>
<%# Register src="UC_ImportantNumbers.ascx" tagname="ImportantNumbers" tagprefix="uc2" %>
<%# Register src="UC_ImportantLinks.ascx" tagname="ImportantLinks" tagprefix="uc3" %>
<%# Register src="UC_Printers.ascx" tagname="Printers" tagprefix="uc4" %>
<%# Register src="UC_WorkOrder.ascx" tagname="WorkOrder" tagprefix="uc5" %>
<%# Register src="UC_RequestForms.ascx" tagname="UCRequestForms" tagprefix="uc6" %>
<%# Register src="UC_MiscLinks.ascx" tagname="MiscLinks" tagprefix="uc7" %>
<%# Register src="UC_Emergency.ascx" tagname="Emergency" tagprefix="uc8" %>
<%# Register src="UC_Floorplan.ascx" tagname="Floorplan" tagprefix="uc9" %>
<%# Register src="UC_Directory.ascx" tagname="Directory" tagprefix="uc10" %>
<%# Register src="UC_Weather.ascx" tagname="Weather" tagprefix="uc11" %>
<%# Register src="UC_Holiday.ascx" tagname="Holiday" tagprefix="uc12" %>
<%# Register src="UC_CoreValues.ascx" tagname="CoreValues" tagprefix="uc14" %>
<%# Register src="UC_MyInfo.ascx" tagname="MyInfo" tagprefix="uc15" %>
<%# Register src="UC_Travel.ascx" tagname="Travel" tagprefix="uc16" %>
<%# Register src="UC_StockDisplay.ascx" tagname="StockDisplay" tagprefix="uc17" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>IT Helpdesk</title>
</head>
<body style="background-color:#1B5B9D;">
<form id="form1" runat="server">
<%-- your usercontrols and other tags --%>
</form>
EDIT: As you mentioned other usercontrols don't have forms, just adding form tag in the main page and remove that tag from usercontrol should solve your problem.
I have the folling code in my content page:
- masterpage
- strong type of masterpage
- ajaxcontroltoolkit
I think the error is caused by the fact that I have
<%# MasterType VirtualPath="~/dashboard/ProfMaster.master" %>
in the code. But I do not know how to solve it. I read some workaround like http://www.west-wind.com/weblog/posts/2006/May/27/The-Controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie-
but that does not solve it.
Any ideas?
My
Code:
<%# Page Title="" Language="C#" MasterPageFile="~/dashboard/ProfMaster.master"
AutoEventWireup="true" CodeBehind="profEditArticle.aspx.cs"
Inherits="NoteBook.dashboard.profEditArticle" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit.HTMLEditor"
TagPrefix="cc1" %>
<%# MasterType VirtualPath="~/dashboard/ProfMaster.master" %>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHPROFRIGHT" runat="server">
<cc1:Editor ID="Editor1" runat="server" />
</asp:Content>
I know you can't put a control inside a C# function like this
<%= VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />) %>
but I am wondering if you can pass the value from a control to a C# function.
umbraco:Item above outputs something like ~/media/bg1.jpg
Here is what I am trying to do:
<%# Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(<umbraco:Item field="background" runat="server" />)%>');
}
</style>
</asp:content>
Anyone know any solution? Thanks in advance.
If it's just a plain textstring then you can do the following:
<%# Master Language="C#" MasterPageFile="/masterpages/Master.master" AutoEventWireup="true" %>
<%# Import Namespace="umbraco" %>
<%# Import Namespace="umbraco.presentation" %>
<%# Import Namespace="umbraco.presentation.nodeFactory" %>
<asp:content ContentPlaceHolderId="cphHead" runat="server">
<style type="text/css">
#content {
background: url('<%=VirtualPathUtility.ToAbsolute(Node.GetCurrent().GetProperty("background").Value)%>');
}
</style>
</asp:content>
However, if the "background" property is a media picker then you need a little more help than just that, which will involve the umbraco.cms.businesslogic.media namespace. I suggest you check out the libraries with Reflector, or the source code repository on Codeplex to find out the classes you should be using and how to subsequently populate your property.
HTH,
Benjamin