CodeVerge.Net Beta


   Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: Date Entered: 12/29/2006 12:58:45 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 68 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
"bunmiog" <>
NewsGroup User
Web User control in master pages12/29/2006 12:58:45 AM

0

I created a web user control (*.ascx) file it works with a page that has no master pages directive but it doesn't work when the page has MasterPageFile="~/MasterPage.master"  is there a way around this problem.

Thanks

"Rossoneri" <>
NewsGroup User
Re: Web User control in master pages12/29/2006 4:56:22 AM

0

I would have to look at your complete code. Here is an example from an aspx page:

<%

@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="Test.aspx.cs" Inherits="Test" %>
<%
@ Reference Control="~/controls/UserControl.ascx" %>

<

asp:Content ID="conMain" runat="server" ContentPlaceHolderID="cphMaster">

<

asp:PlaceHolder ID="plhControl" runat="server" />

</

asp:Content>

Then in the code beside:

protected

void Page_Load( object sender, EventArgs e )
{
      UserControl testControl = (UserControl) LoadControl( "~/controls/UserControl.ascx" );
      plhControl.Controls.Add( testControl );
}
"Rossoneri" <>
NewsGroup User
Re: Web User control in master pages12/29/2006 4:58:37 AM

0

Sorry, the above code is adding one programatically, which probably isn't what you were looking for. Does it throw an exception or something?
"tfsmag" <>
NewsGroup User
Re: Web User control in master pages12/29/2006 2:35:58 PM

0

When your aspx page has a master page, you need to make sure any content for that page is put inside of the contentplaceholder on that page. If your page does not have a contentplaceholder this could be the problem. See the example below.

 
<%@ Page Language="VB" MasterPageFile="~/Intranet.master" AutoEventWireup="false"
    CodeFile="Default.aspx.vb" Inherits="FR_Default" Title="Untitled Page" ValidateRequest="false" %>
<%@ Register src="../UserControls/FormsRepository/FormsTool.ascx" TagName="FormsTool"
    TagPrefix="uc1" %>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderMain" runat="Server">

    <uc1:FormsTool ID="FormsTool1" runat="server" />
 </asp:Content>

if the call to the usercontrol is not inside of the content place holder it will not work correctly. Hope this helps.


------------------------------------------------
Jeff Turner (simpleModus)

Don't forget to mark the correct answer for your
question to help out future visitors!
"bunmiog" <>
NewsGroup User
Re: Web User control in master pages12/29/2006 4:38:13 PM

0

Thanks all for your replies here is what I have in my test page

<%

@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" ValidateRequest="false" CodeFile="Default2.aspx.cs" Inherits="Default2" Title="Untitled Page" %>

<%

@ Register Src="ctlCalendar.ascx" TagName="ctlCalendar" TagPrefix="uc1" %>

<

asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<uc1:ctlCalendar ID="CtlCalendar1" runat="server" />

</

asp:Content>

But still it doesn't work. The user control is just a drop down calendar (textbox, input button, calendar control and a panel) with two properties.
I have no idea what is wrong with my page

 

"tfsmag" <>
NewsGroup User
Re: Web User control in master pages1/2/2007 10:00:07 AM

0

could you post the code for the user control too? Sometimes it might be something as easy as an unclosed tag in your user control? The code you posted above looks like it should work.                 

------------------------------------------------
Jeff Turner (simpleModus)

Don't forget to mark the correct answer for your
question to help out future visitors!
"bunmiog" <>
NewsGroup User
Re: Web User control in master pages1/3/2007 5:26:24 PM

0

here is the code for the *.ascx

<%

@ Control Language="c#" Inherits="projectDates.ctlCalendar" CodeFile="ctlCalendar.ascx.cs" %>

<

asp:textbox id="TxtDate" runat="server"> </asp:textbox>

<

input type="button" id="Button1" runat="server" value="..." style="background-image: url(App_Themes/Basic/Images/cal/calendar.gif); width: 27px"><br>

<

asp:Panel id="pnlCalendar" runat="server">

<asp:calendar id="mntCalendar" runat="server" BackColor="White" Width="200px" DayNameFormat="FirstLetter"

ForeColor="Black" Height="180px" Font-Size="8pt" Font-Names="Verdana" BorderColor="#999999"

CellPadding="4" onselectionchanged="mntCalendar_SelectionChanged">

<TodayDayStyle ForeColor="Black" BackColor="#CCCCCC"></TodayDayStyle>

<SelectorStyle BackColor="#CCCCCC"></SelectorStyle>

<NextPrevStyle VerticalAlign="Bottom"></NextPrevStyle>

<DayHeaderStyle Font-Size="7pt" Font-Bold="True" BackColor="#CCCCCC"></DayHeaderStyle>

<SelectedDayStyle Font-Bold="True" ForeColor="White" BackColor="#666666"></SelectedDayStyle>

<TitleStyle Font-Bold="True" BorderColor="Black" BackColor="#999999"></TitleStyle>

<WeekendDayStyle BackColor="LightSteelBlue"></WeekendDayStyle>

<OtherMonthDayStyle ForeColor="#808080"></OtherMonthDayStyle>

</asp:calendar>

</

asp:Panel><br />

 

This is the code in the code behind *.cs

namespace

projectDates

{

using System;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

/// <summary>

/// Summary description for ctlCalendar.

/// </summary>

public partial class ctlCalendar : System.Web.UI.UserControl

{

protected void Page_Load(object sender, System.EventArgs e)

{

if (!Page.IsPostBack)

{

this.TxtDate.Text = System.DateTime.Now.ToShortDateString();

this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");

}

else

{

char[] delimiterChars = { '%', '$', '.', ':', '\t' };

 

string[] id = Page.Request.Form["__EVENTTARGET"].Split(delimiterChars);

 

 

//get the name of the control that was clicked.

 

if (id[0] != this.ID)

{

this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");

}

else

{

this.pnlCalendar.Attributes.Add("style","POSITION: absolute");

}

}

Page.ClientScript.RegisterClientScriptBlock(

this.GetType(), "Script_Panel" + this.ID, "<script> function On" + this.ID + "Click() { if(" + this.ID + "_pnlCalendar.style.display == \"none\") " + this.ID + "_pnlCalendar.style.display = \"\"; else " + this.ID + "_pnlCalendar.style.display = \"none\"; } </script>");

this.Button1.Attributes.Add("OnClick","On"+this.ID+"Click()");

 

}

#region

Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

 

private void InitializeComponent()

{

}

#endregion

 

protected void mntCalendar_SelectionChanged(object sender, System.EventArgs e)

{

this.TxtDate.Text = mntCalendar.SelectedDate.ToShortDateString();

this.pnlCalendar.Attributes.Add("style","DISPLAY: none; POSITION: absolute");

}

//' This propery sets/gets the calendar date

public string txtDate

{

get

{

return this.TxtDate.Text;

}

set {

TxtDate.Text =

value;

}

 

 

}

 

}

}

7 Items, 1 Pages 1 |< << Go >> >|


Free Download:













window app style menus at the top

events sequence in nested master pages

menu problem

could not center the text in an horizontal menu control

master pages / content pages. how to set the form id ??????????

problem with treeview control in master page....

css not working in firefox

using .net 2.0 and system.web.ui.webcontrols.treeview with sql reporting services 2005 for navigation and display.

can sitemap,menu,treeview declaritively open node in new "_blank" window?

placing the viewstate of pages including master on to session without modify a drop of your production code

sitemap error: could not find the sitemap node with url

applying different css syle to single master pages

asp.net menu control

custom navigation

master page mystery event solution

content place holder question

object groups in skins

best way to iterate through treeview

master pages / content pages and postbacks

cannot access a custom page/masterpage type from a class file inside app_code

treeview like msdn

embedded pdf with "please wait"

how to flush just the contents of a master page?

how to access master page datalist from a content page ?

design view when using master pages

error message using personal starter kit

dynamically adding controls in content which is using masterpage

treeview question

layout of menu navigation

menu and inline css

asp.net theme based on type of browser

treeview expand problem

submit form in iframe within master page...

nested master page event handling sequence problem

i need some help with the asp:menu control

no app_code in web application

treeview trivia ... need help

trying to make it work.

navigation menu

accessing a web page in a project which is nested inside another project

content control values in form submit

problems acessing masterpage from a dll created in another website

contentplaceholder doesn't expand

adding cssclass attribute to contentplaceholder

dynamic page creation before merging with master file

your suggestions will be appreciated for this navigation problem....

menu control and javascript

progromatic navigation question

i'm confused about sitemaps

controlling the rendering of dynamic meta tags on a master page

   
  Privacy | Contact Us
All Times Are GMT