.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

referencing a user control in a master page

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :ASP.Net


I have the following code which at the moment sits in a number of pages:

    private void ConfigureEmailSignup()
        ContentPlaceHolder cphBaseContent1 =
        if (cphBaseContent1 != null)
            Controls_Email_Signup emailSignUp =
            if (emailSignUp != null)
                emailSignUp.DisplayType = "store-list";
                // event log
            // event log

It sits in the page because I reference the usercontrol type 'emailSignUp' and pass data to an exposed variable 'DisplayType'.  The control is located in the pages master page. Ideally what i'd like to do is put this in its own class or something, so I can just call it passing the configuration variable, but I'm unsure how this would work - any advice would be appreciated.



View Complete Post

More Related Resource Links

Accessing User Control that is in a Master Page

I have looked everywhere for how to do this and all I come up with is threads describing how to expose public properties.  I have a USER CONTROL in my  Master page. It is a search box with a text box and a dropdown for search type (last name, account number, etc) and a search button.  When the user clicks the search button, I open a new page that displays the results.  How do I pass the values from the USER CONTROL search fields to the new page?  I would post code, but I have nothing to post yet since I don't know where to start. I have tried exposing the public property of the user control, but I don't know how to retrieve those values on the results page.  Anyone have any sample code on how this is done? Thank you in advance for your help!

Accessing a public property of a nested user control in a master page from a pages' user control

Hi  I've got a web site that has a master page and that master page (mpMaster that has a user control (ucControl1) which has a sub user control (ucControl2), this user control has a property which accepts a value. Now, I have a page that uses the master page and on this page I have another user control (ucPageControl), I need to  find a way of setting the value in ucControl2 from ucPageControl. Is this possible at all? Many thanks Ed

Building Re-Usable ASP.NET User Control and Page Libraries with VS 2008


I am having problems with a user control. I want my solution to have a separate project for holding my user controls.

The main project can get a reference to this user control project and can import this user control dll into my main project. 

Thanks in advance,

Dheeraj Mittal


Knowing the event occured in user control in current page




      My web application has user control which uses third party controls called Devexpress controls. The user control is a menu  and is part of the Master page. It is placed there because this needs to be available in all the pages. My user controls raises a even on item clicked. Now, My question is that Is there any way to know that the event has occurred in page_load of the current page in which I am in?

User Control not accessing the value of the properties send to it from the aspx page.


I have a dynamic accordion on a page. Set its datasource to an object of paged data source.The user control is in the accordions content template. When i was writing code the properties were showing but after giving the values of databases as


<uc:UserControl1  runat="server" Property1='<%#DataBinder.Eval(Container.DataItem,"columname1")%>' Property2='<%#DataBinder.Eval(Container.DataItem,"columname2")%>'  ></uc:UserControl1>


but the values shows null, these properties are shown as textboxes text property by user control.

MoreOver when I checked the values of database Items.So i made a textbox instead of usercontrol here as

<asp:TextBox ID="txtTest" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Columname1")%>'></asp:TextBox>

It is showing the correct value. And if i pass the value directly it is also showing correctly like

<uc:UserControl1  runat="server" Property1="XYZ")%>' Property2="ABC")%>'  ></uc:UserControl1>

. where I am wrong

the problem is eval is not passing the value to usercont

Referencing ConfiguratingSettings.AppSettings in a ASCX user control?

Hi there,I'm trying to reference a string from the web.config file from a ASCX user control, but I get the error message: [b]Compiler Error Message: BC30203: Identifier expected.My code in the user control file is as follows:<div id="header"><h1><%= Server.HtmlEncode(Convert.ToString(ConfigurationSettings.AppSettings["Web_Title"])) %></h1></div>Do I need to import any namespaces? Hopefully someone can help!Thanks

How show the computer user into a label in a master page

  Hello all, I'm creating a web site and I have this question, I installed a label with the name Userlbl in the master page, and the idea that I have, is when somebody opens the website, the label shows the computer's user, in my case Welcome: "Charly_csh" I tried with this code, that I used before in access and it works, when I load the page on the localhost, but when I load on the server, it shows NETWORK SERVICE The code is this: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Userlbl.Load Dim wshNetwork As Object 'New wshNetwork wshNetwork = CreateObject("WScript.Network") Me.Userlbl.Text = wshNetwork.UserName wshNetwork = Nothing End Sub Does somebody have an idea???       

How to Access Parent Page (.aspx) control (IDs) from its child User Control (.ascx)

I have a parent .aspx page that has a asp:panel control in it, and this parent .aspx is also referencing a user control that I registered in that .aspx. Lets just call it usercontrolA.ascx for this post.The user control has a radiobuttonlist itself.Based on a selection from the radiotbuttonlist in the user control, I want to be able to hide the asp:panel in my .aspx (parent) but unfortunately I cant' get it to work:parentPanel.visible = true;  <<< I trried this in usercontrolA.ascx.csBut the user control doesn't know about the panel in the parent .aspxSo do I need to expose that somehow from the parent so that I can access it from the code behind of the child .ascx?  How?

Is there a way in VB.Net to embed a custom user control to a web page based on Word or Excel

Hi Everyone.  I'm looking to create a web page that would be used on a local intranet that would use a custom control based on Word and Excel.  I've used code previously to embed it in a Windows application but wasn't sure if anyone knew of any examples out there on how to embed a custom control into a ASP.Net page.

Multiple instance of User Control on Page - Button Click Event

Hi, I have this Web User Control, with 3 controls:<asp:TextBox ID="txtSearch" runat="server" /> <asp:RequiredFieldValidator ID="rfvSearch" runat="server" ControlToValidate="txtSearch" Display="None" /> <asp:Button ID="btnSearch" runat="server" onclick="btnSearch_Click" /> In code behind: protected override void Render(HtmlTextWriter writer) { rfvSearch.ValidationGroup = this.ID + "_validation"; txtSearch.ValidationGroup = this.ID + "_validation"; btnSearch.ValidationGroup = this.ID + "_validation"; base.Render(writer); } protected void btnSearch_Click(object sender, EventArgs e) { Response.Redirect("ResultadoSearch.aspx?argumento=" + txtSearch.Text); } When I try to add two UserControl and I Click in btnSearch of second UserControl, txtSearch.txt returns value of first User control.How I can get the value of second txtSearch?

Referencing a ghosted master page in unghosted page layout

Hello All, I am developing a publishing portal in MOSS 2007 environment. I am employing wspbuilder to deploy my master pages, page layouts and site contents in the publishing site. I would like to know whether referencing a ghosted master page(residing in the 12 hive) in an unghosted page layout(residing in the content database) would be efficient. I read in some articles that fetching the pages from file system increases the throughput when compared to that of hitting the content database. Is it advisory to do it this way? Any insights on this would be of great useRegards, Raghuraman.V CALAMITY IS THE TOUCHSTONE OF A BRAVE MIND

Finding a control inside a ListView on a master page

I have a listview on a master page that ISN'T part of a content place holder that I want to fill in and disable if the user is already logged in. I have a label set up already which works fine. I'm just having problems accessing a Textbox by the name of "NameTextBox" in the InsertItem template of the listview.Here is the part of my codefile:Dim vCurrentUser As MembershipUser = Membership.GetUser() If Not vCurrentUser Is Nothing Then Dim pnl As Label = LoginView1.FindControl("Label1") pnl.Text = Page.User.Identity.Name Dim NameBox As TextBox = ListView1.InsertItem.FindControl("NameTextBox") NameBox.Text = Page.User.Identity.Name End IfI get a Object not found exception. What is the correct way to find a control inside a InsertItemTemplate and the correct Event to use?

ConfirmButtonExtender and ModalPopupExtender Server Control with Master Page Failed to find element


I am in the process of building a server control that contains a ConfirmButtonExtender. This is my code:

The Master Page:

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="CBC_MasterPage" %>

<!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">
    <asp:ContentPlaceHolder id="head" runat="server">
    <form id="form1" runat="server">
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

Master Page User.Identity.Name problem


Hello I've written some code to check information based on the authenticated user. The following code works on an ASPX page load but fails when I move into a Master Page. Specifically, the error is "Compiler Error Message: BC30451: Name 'User' is not declared."  

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


' Get & split Domain user Information

Dim strDomainUser As String = User.Identity.Name

Finding control from master page inside tabcontainer in content page


I have a codebehind.vb for a master page from which I'm trying to find a hiddenfield in the content page. I was finding it like this without a hitch...

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("hfSearch"), HiddenField)

Then I decided to add an Ajax TabContainer to the content page. Now I'm having a hard time finding the hiddenfield. I've tried these variations, but still not working.

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabContainer1").FindControl("hfSearch"), HiddenField)

Dim hfContentSearch As HiddenField = CType(Page.Master.FindControl("main").FindControl("TabPanel1").FindControl("hfSearch"), HiddenField)

Can someone please help me with the syntax?

Thank you.


Calling parent page method from user control


I looked up the  threads about  this. But I couldn't do it...

this is my method in aspx.page:

public  void MesajlariGetir()
        DataSet ds = new DataSet();

        SqlConnection con = new SqlConnection();
        SqlCommand cmd = new SqlCommand("msjlarigetir", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@Kime", Session["kullaniciadi"].ToString());
        con.ConnectionString = cnnstr;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        pds.DataSource = ds.Tables[0].AsDataView();
        pds.AllowPaging = true;
        pds.PageSize = 10;
        pds.CurrentPageIndex = CurrentPage;


Get the value of a User control in a Page


In my ASpx page i want to get the value of a server control which is in a User Control

Please Help

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend