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.
Related
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
I need your help:
Asp ContentPlaceHolder is not working.
"blao balo bla balll" is not shown.
in Html code:
<!-- Insert default "slide" markup here -->
This is my Code - HomePage.master:
<%# Master Language="C#" MasterPageFile="~/umbraco/masterpages/default.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolderDefault" runat="server">
<asp:ContentPlaceHolder Id="slide" runat="server">
<!-- Insert default "slide" markup here -->
</asp:ContentPlaceHolder>
</asp:Content>
slide.master:
<%# Master Language="C#" MasterPageFile="~/masterpages/HomePage.master" AutoEventWireup="true" %>
<asp:Content ContentPlaceHolderId="slide" runat="server">
blao balo bla balll
</asp:Content>
Since the slide template uses the HomePage template as master page and replaces the content of a ContentPlaceHolder defined in the HomePage template, you should make sure to use the slide template whenever you want to display non default slide markup.
When using the HomePage template, as expected the default markup as defined in the HomePage template gets displayed.
I've see all of the other pages with this questions, but no amount of research has solved my problem. I am getting the "The state information is invalid for this page and might be corrupted" error. My page loads fine the first time. The page contains a div that has tabs that change the info on the page and the tabs are loaded dynamically and are linked to a different page. The tabing uses jquery. Without changing anything on the page, when I try to reload this page by click on the link that gets to this page or even by clicking on ANY link in the menu bar that goes to other pages, I this error. Again, this only happens in IE and I've put break points all over my code and it never goes back to the server.
<%# Page Language="C#" MasterPageFile="~/Templates/Main.Master" AutoEventWireup="true"
CodeBehind="Reporting.aspx.cs" Inherits="Pegged.Reporting" Title="Workforce Planning Report" %>
<%# Register Src="Controls/ucWebPageNavigation.ascx" TagName="ucWebPageNavigation"
TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$(function () {
$("#tabs").tabs({
ajaxOptions: {
error: function (xhr, status, index, anchor) {
$(anchor.hash).html(
"Couldn't load this tab. We'll try to fix this as soon as possible.");
}
}
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="IconLinks" class="TopLinks">
<uc1:ucWebPageNavigation ID="ucWebPageNavigation1" runat="server" />
</div>
<div id="divContainerReport" class="container_12">
<!--Facility Tabs-->
<div id="tabs">
<ul id="FacilityTabs" runat="server" ></ul></div>
</div>
</asp:Content>
This is the code that loads the tabs on page load:
ServicesDLL.Services ps = new ServicesDLL.Services();
string encryptString = "";
string encryptString2 = "";
encryptString = ps.EncryptQueryString("Test");
encryptString2 = ps.EncryptQueryString("Testing");
string innerhtml = "<li><a id=\"id1\" href=\"ReportFacility.aspx?facility=" + encryptString + "\">Test</a></li><li><a id=\"id2\" href=\"ReportFacility.aspx?facility=" + encryptString2 + "\">Testing</a></li>";
FacilityTabs.InnerHtml = innerhtml;
And this is the page the tabs load:
<%# Page Title="" Language="C#" MasterPageFile="~/Templates/Popup.Master" AutoEventWireup="true" CodeBehind="ReportFacility.aspx.cs" Inherits="Pegged.ReportFacility" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divReportView" class="grid_8 BlueBorder">
<p id="testText" runat="server"></p>
</div>
</asp:Content>
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>
<%# Register TagPrefix="uc3" TagName="AccountDetailCustomerBook" Src="/Controls/AccountDetailCustomerBook.ascx" %>
<%# Register TagPrefix="uc2" TagName="AccountDetailHistoryChart" Src="/Controls/AccountDetailHistoryChart.ascx" %>
<%# Register TagPrefix="uc1" TagName="AccountDetailAssetChart" Src="/Controls/AccountDetailAssetChart.ascx" %>
<%# Register TagPrefix = "uc4" TagName = "DetailsAnnuity" Src= "/Controls/DetailsAnnuity.ascx" %>
Using infragistics i have this error popping n below is the code how am using the control.
how can i remove this error?
<uc3:AccountDetailCustomerBook ID="AccountDetailCustomerBook1" runat="server" /> so am using it like this. It says: element "accountdetails customerbook" is not a known element and its showing the error for all the controls.
I had a similar problem and resolved it by including a tilde ~ character at the beginning of the src location.
For instance, register your 4 controls as follows:
<%# Register TagPrefix="uc3" TagName="AccountDetailCustomerBook" Src="~/Controls/AccountDetailCustomerBook.ascx" %>
<%# Register TagPrefix="uc2" TagName="AccountDetailHistoryChart" Src="~/Controls/AccountDetailHistoryChart.ascx" %>
<%# Register TagPrefix="uc1" TagName="AccountDetailAssetChart" Src="~/Controls/AccountDetailAssetChart.ascx" %>
<%# Register TagPrefix="uc4" TagName="DetailsAnnuity" Src="~/Controls/DetailsAnnuity.ascx" %>
Manually declare AccountDetailCustomerBook1 in your designer.cs file then build your project. You will see a more related error for this problem.