There are 2 user controls(Test1.ascx and Test2.ascx). Test1.ascx contains Test2.ascx.
The inner user control(Test2.ascx) html is:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="Test2.ascx.cs"
Inherits="Test.UserControls.Test2" %>
<%# OutputCache Duration="200" VaryByParam="None" %>
<%# Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<telerik:RadTreeView runat="server" ID="radTreeView" >
<DataBindings>
<telerik:RadTreeNodeBinding Depth="0" CssClass="rootNode" />
</DataBindings>
</telerik:RadTreeView>
The outer user control(Test1.ascx) html is like:
<div runat="server" id="divTreeViewContainer">
<uc:ucTreeView runat="server" ID="ucTreeView" />
</div>
When first time the page is requested, both the user controls are loading perfectly.
The tree view from Test2.ascx is accessed by FindControl() in Test1.ascx as
//Find the tree view from the Test2.ascx user control
var radTreeView = ucTreeView.FindControl("radTreeView") as RadTreeView;
From 2nd page request on-wards(i.e after inner user control Test2.ascx is cached) the ucTreeView is coming as null.
Requirement:
The Test2.ascx user control needs to be cached and the control values of this user control will be accessed with in Test1.ascx user control(both in cached and non-cached condition). How to do it?
Lots of thanks in advance.
Related
I have a user control with the following directive
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="SelectorControl.ascx.cs" Inherits="SelectorControl" %>
and then I can register this control in any .aspx and use, like this
<%# Page Language="C#" AutoEventWireup="True" CodeBehind="FolderDistribution.aspx.cs"
Inherits="SearchFolder.FolderDistribution" %>
<%# Register TagPrefix="UC" TagName="TemplateSelection" Src="~/Controls/SelectorControl.ascx" %>
<div>
<UC:TemplateSelection ID="templates" runat="server" />
</div>
But, I need to set CodeFile in my UserControl (ascx) instead of CodeBehind. In control's directive I changed
CodeBehind="SelectorControl.ascx.cs" to CodeFile="SelectorControl.ascx.cs"
And in this case I get the following runtime error
The base class includes the field 'templates', but its type (TemplateSelection) is not >compatible with the type of control (ASP.controls__templateselection_ascx).
In Sitefinity - the page controls section I created a new tool and linked it up to the user control. But when I try and add that control to the page I am getting an error?
Is there a step I am missing?
UserControl
Control Language="C#" AutoEventWireup="true" CodeBehind="TransparencyControl.ascx.cs" Inherits="SitefinityWebApp.transparency.TransparencyControl" %>
<%# Register TagPrefix="ucTransparency" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<asp:Xml ID="XmlForm" runat="server"></asp:Xml>
PageControl
PageControl tool linked to ascx page
You need to set the path to the user control (ascx) not in the Controller CLR Type field, but in Control CLR Type or Virtual Path field.
So, just cut it from the former field and paste it in the latter field and you should be fine.
I am in the process of making a website that displays information in boxes.
There will be different pages with different combinations of boxes. They will have a lot of boxes in common.
Therefor, I am making the boxes as user controls to then put on the different pages. The different pages will also share a master page.
However, when starting development of the 2. box, I ran into a problem:
The Page_Load (or the whole code behind) of the 1. box runs fine, but the Page_Load og the 2. box gets ignored. This results in a lot of null values that makes the aspx file crash.
My CT1.aspx contains this to use the two user controls:
<%# Page Title="CustType1" Language="C#" MasterPageFile="~/MTCustomer/Master.master" AutoEventWireup="true" CodeFile="CT1.aspx.cs" Inherits="MTCustomer.CT1" %>
// Some HTML
<td ID="column1" style="width: 400px;">
<Box:CustomerInfoBoxAx runat="server" />
<Box:CustomerInfoBoxMt runat="server" />
</td>
// Some HTML
My Web.config contains this for the user controls to be usable:
<pages>
<controls>
<add tagPrefix="Box" tagName="InfoBoxA" src="~/Controls/InfoBoxA.ascx" />
<add tagPrefix="Box" tagName="InfoBoxB" src="~/Controls/InfoBoxB.ascx" />
</controls>
</pages>
My user control A looks lige this:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="InfoBoxA.ascx.cs" Inherits="Controls.InfoBoxA" %>
<% if (IsVisible("InfoBoxA") && Customer != null)
{ %>
<div>
<%-- Markup --%>
</div>
<% } %>
And box B looks like this:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="InfoBoxB.ascx.cs" Inherits="Controls.InfoBoxB" %>
<link rel="stylesheet" type="text/css" href="<%=VirtualPathUtility.ToAbsolute("~/Styles/InfoBoxStyle.css")%>">
<% if (IsVisible("InfoBoxB") && Customer != null)
{ %>
<div>
<%-- Markup --%>
</div>
<% } %>
I have tried to swap the order of the two user controls in the page.aspx, this also changed witch one had its Page_Load (or the whole code behind) ignored. Based on that, it looks like only the first code behind is executed, and the rest is ignored.
EDIT:
After following the exceptions that comes after the initial null reference exception, I can see that the Page.DataBind() in the first user control is still executing. This must mean that this is what causes the aspx file of both box one and two run. But how do I get around this?
Problem solved.
I removed Page.DataBind() from all user controls, and in the CT1.aspx.cs (the page code behind) i moved it from Page_Load() to OnLoadComplete().
By doing this, Page_Load() in all files have been executed before the Page.DataBind() is executed.
I have a aspx page name MakeRedemption.aspx, the code is something as following :
<%# Page Title="Make Redemption" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="MakeRedemption.aspx.cs" Inherits="MakeRedemption" %>
<%# Register Src="~/UserControls/MakeRedemption_SearchGift.ascx" TagName="MakeRedemption_SearchGift" TagPrefix="uc" %>
<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" Runat="Server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server"></asp:UpdatePanel>
<uc:MakeRedemption_SearchGift runat="server" ID="ucSearchGifts" GiftCategoryAvailable="false" /><% /*UnitCostAvailable="true"*/ %>
</asp:Content>
And I have a user control page name MakeRedemption_SearchGift.ascx.
I would like to ask, is the MakeRedemption.aspx consider a parent page for MakeRedemption_SearchGift.ascx ??
And MakeRedemption_SearchGift.ascx is the user control page of MakeRedemption.aspx
Kindly advise.
Yes, it is. After do some research, testing, further with senior advice. It is.
I have had this problem for a while now and no matter what i cannot seem to resolve it. I have a master page and a content page.
The content page simply contains a button
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</asp:Content>
The master page simply contains the content place holders. The button1 one event fires normally, however as soon as a form is added to the master page the button stops firing. the master page looks something like this
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
Member Login
<asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="bt_login"
onclick="btnLogin_Click" />
</form>
</div>
</div>
</div>
</div>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</form>
Can some one please help, the button works fine without the form in teh master page, however i need a form in the master page
Thanks
Ok after running the exact same project on another machine, everything worked fine. So I'm guessing there is an issue with the way i installed visual studio and asp.net.