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

Top 5 Contributors of the Month
Post New Web Links

How to reference a elements of one control from other

Posted By:      Posted Date: September 20, 2010    Points: 0   Category :ASP.Net

Can someone explain how user controls can communicate with each other within an asp.net application. I am facing many obstacles at the moment regarding this problem. For example, is it possible to set the visible property of a panel on one user control based on what happens in another?

Another example would be: Can I set the text of a label in one control to be the value of some other property from another control's class like.... Me.PreContentColumn.ColumnID = LocalProduct.PreContentColumnId.

Please let me know if this sounds confusing...

View Complete Post

More Related Resource Links

Problems with a .NET4 Control GAC Reference failing at runtime but fine during debugging

I believe this question is specific to the CLR how ever I will test this in a Forms Application later. I have multiple .Net 4 Targeted WPF Applications that Reference Non Microsoft .NET 4 WPF Controls that I can confirm are in the GAC. Everything Debugs Great (Noting that none of the references are copied to the output directory) and Install's well using a Setup Package and manually installing has the same effect even after a reboot. The problem is the application will not start even as an administrator as it does not find the Control References in the GAC. This also happens if I try to start the application manually in the visual studio output Directory. I can also confirm that opening the application in reflector that reflector is able to correctly find the references. Finally if I copy the controls (.dll's) to the location of the application everything runs as expected for all the above issues.   My question here is why is my application not able to load the .NET 4 controls from the GAC? Also note that everything uses a Strong Name.

WPF Ribbon Control binding to a VM Ribbon reference

Hi, I have a scenario where I will initialize the Ribbon in XAML but its relatd Tab, group, buttons etc., needs to be coming from VM file , meaning there will be a public property of Ribbon which needs to be set back to the Ribbon that was initialized in XAML like ( I am using WPF provided Ribbon control only)  <r:Ribbon Height="135" VerticalAlignment="Top" Name="mainRibbon" ... > // Above XAML I need to set the RibbonControl which is a public property (having the tabs, gropping, buttons etc., // Since WPF ribbion doesn't have ItemsSource I am struggling to set this ... In the VM file private Ribbon _RibbonControl; public Ribbon RibbonControl { get {      CreateRibbon() //This functon will creates tabs, groups, buttons etc., & adds to _RibbonControl      return _RibbonControl; } } Any help here is greatly appreciated. Prakash.G

Object Reference Error While Rendering Menu Control


I am having a problem with rendering a menu control inside a server control. I am getting an error in the RenderContents override method when I try to render the Menu Control. The error I am getting is an Object Reference error. The code is below...

[ToolboxData("<{0}:Login runat=server></{0}:Login>")]
    public class Login : CompositeControl
        #region Members

        Label tst;
        Menu loginMenu;
        MenuItem mainLoginItem;
        MenuItem loginItem;
        MenuItem usernameItem;
        MenuItem passwordItem;
        SubMenuStyle subMnuStyleControl;
        SubMenuStyle subMnuStyleMenu;

        bool isLoggedIn = false;


        #region Properties

        public bool IsLoggedIn
            get { return isLoggedIn; }

            set { isLoggedIn = value; }


        #region Overridden Events

        protected override void RenderContents(HtmlTextWriter writer)



        protected override void OnInit(EventArgs e)

            #region Add CSS references
            string cssUrl = Page.ClientScript.GetWebResourceUrl(this.Ge

Can not reference text value in footer of Gridview control


I have been struggling with this all week end .... Yell

I am trying to implement adding a new record using the Gridview footer.

I have an example that works finethat I got from http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx.

My situation is a little different .. as I am using master page and the Gridview is in a page derived from the master page.

I have tried:

Dim txtNewName As TextBox = DirectCast(GridView1.FooterRow.FindControl("NewName"), TextBox)

"NewName" is the ID of the textbox in the footer of the Gridview.

When I try referencing ... txtNewName.Text ... it returns a null value.

There must be some trick to referencing this .Text value when using the Gridview that is within a Content Place Holder that results when using a page that was created using a master page.


Thanks in advance fo any possible help with this problem ...

Object reference not set to an instance of an object in Nested Repeater Control of CheckBox List con

 if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
                Repeater rptsub = (Repeater)item.FindControl("rptsub");
                CheckBoxList Chksub = (CheckBoxList)rptsub.FindControl("Chksub");
                Label lblsubroot = (Label)rptsub.FindControl("lblsubroot");
                DataRowView row = (DataRowView)e.Item.DataItem;
                RootId = Convert.ToInt32(row["IdApplication"].ToString());
                MetadataPermissions metadataPermissions = new MetadataPermissions(); ;
                DataSet rptRootValues = new DataSet();
                rptRootValues = metadataPermissions.GetrptSubMenus(RootId);
                DataRow[] drows = rptRootValues.Tables[0].Select("IdApplicationroot = " + row["IdApplication"].ToString());
                foreach (DataRow chkpermsns in drows)
                   ListItem li = new ListItem(chkpermsns["PermissionName"].ToString());


<asp:Repeater ID="rptroot" runat="server" OnItemDataBound="rptroot_ItemDataBound">

I need to Group Elements in Nested Repeater Control



User Group Management
User Groups Add  Delete   Edit  View  Activate/Deactivate  Export
User Management

Can you have control over the names of HTML elements?



I was just wondering, is it possible to have control over the name of an HTML element that's bound to a property of a viewmodel? For example, if I had a viewmodel with a property called ProductDescription, is it possible to have a text input in the view with the name "desc" instead of "ProductDescription" and somehow tell MVC that "desc" binds to ProductDescription?

Not a big issue, but it would be nice to have control over how my HTML elements are named.


UpdatePanel Reference in control.ascx.designer.cs keeps changing


I have an annoying problem when I'm developing in Visual Studio 2010. I am using an UpdatePanel in my .ascx file like this:

<asp:updatepanel id="upStuff" runat="server">....</asp:updatepanel>

in my control.ascx.designer.cs, the update panel is being defined like this:

protected global::System.Web.UI.WebControls.WebParts.updatepanel upSettings;

this produces the error:

"The type or namespace name 'updatepanel' does not exist in the namespace 'System.Web.UI.WebControls.WebParts' (are you missing an assembly reference?)"

The actual namespace should be System.Web.UI.UpdatePanel. When I go directly into the designer.cs file and change it, it works. However, every time I go back into editing control.ascx and save, Visual Studio always changes it back to System.Web.UI.WebControls.Webparts.updatepanel.

I'm not sure what is causing this. Is it how I should be referencing namespaces and classes in my project? I'm using .NET 3.5. Any help would be greatly appreciated.

Reference control inside an iframe


I am trying to reference a control inside a iframe. This should be very simple, but I am constantly getting an error. Either object does not exist or undefined. Then I tried to get a reference to all the objects inside a iframe, but I am getting the same kind of error.

FInally I used
var test = document.frames("framename").document.all;

It returns 0, but iframe contains couple of controls...

Any tips?

reference web control from shared sub



Guys I need reference a Treeview from a shared sub so I can run a databind on it after the the sub has finished doing it's thing.

Any Ideas?

Can't reference Control in Code Behind?


Hey guys,

I've got a very odd issue.

I'm getting an "Object Reference Not Set to an Instance Of An Object Error" in a Web User Control that I've created when referencing any control in the Code Behind. Intellisense reports that the control exists in the aspx, but whenever I build and run I get that error.

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

        Dim ImageURL As String = "~/Assets/IMG/"

        Select Case StatusType
            Case "Done"
                ImageURL += "Indicator_Done.png"
                panTaskItem.CssClass = "TaskItem-Green"
            Case "NotDone"
                ImageURL += "Indicator_NotDone.png"
                panTaskItem.CssClass = "TaskItem-Neutral"
            Case "Warning"
                ImageURL += "Indicator_Warning.png"
                panTaskItem.CssClass = "TaskItem-Yellow"
        End Select

        imgIndicator.ImageUrl = ImageURL
        lblTaskTitle.Text = TaskTitle
        lblTaskDescription.Text = TaskDescription

    End Sub

<asp:Panel ID="panTaskItem" runat="server" Width="100%">

    <div style="flo

How to reference an UI control from my ModelView class?


I have a listview which contains checkbox items

 <ListView x:Name="listControl"
               ItemsSource="{Binding Userlist}"
               ItemTemplate="{StaticResource ItemDataTemplate}" 
               CheckBox.Unchecked="OnUncheckItem" />

I need to know how to reference "listContro

How to pass control reference to its property in data binding expression


Here is data binding expression (dropdown list is nested in gridview)

<asp:DropDownList ID="ddlEmployees" 
         DataSource='<%# PayCheckBO.GetEmployeesNameIdPair() %>' 
         SelectedIndex='<%# GetSelectedIndex(HOW TO PASS REF of ddlemployee HERE)%>'/>

Code Behind has function which looks like

public int GetSelectedIndex(DropDownList ddl)
        //loop through the item in the dropdownlist
        //return index based on xyz checks

The whole reason for passing the reference is to save round trip to database and not to use SESSION

Web page with custom control elements



I would like to create web page/form with several subforms - means edit for records, e.g.: first page, no problem, data list in gridview with checkbox there I do select two records and press one Edit button, that should open Edit form with two subforms and one Save button - the thing is that I would like to have that subform fully as form designed previously (not just add elements).

In genaral I need to be sure how to make UI controls as class and use them in my actual pages.


Thank you.


Hover-Style for single elements of a new control



I've a UserConrol, lets say ButtonX with several parameters like color, text and border. This parameters are passed to different elements of my control, e.g., the text to an asp:Label and the border to the style attribute of an enclosing DIV. No I want to pass some parameter to the hover and active state of some inner control elements (e.g., the DIV). I know how to set every CSS style parameter of an asp:Label or DIV - but how can I set the hover parameters?

I can not write an external CSS class like

.button1:hover { ... } and assign this, because the color is assigned dynamically via the UserControl like <xy:ButtonX id=".." hoverColor="..." runat="server"/>

Thus, how can I change the hover parameters in my C# code behind dynamically?


Many Thanks


Visual Studio 2005 C# refuses to accept x64 C++ activex control as reference



Firstly: Sorry about my English.


I have many 32bit OCXs, they work fine on x86. But! When I rebuild them on x64, there is an error.

I can not use one of them.

On the developer machine is a Windows xp x64 professional and Visual Studio 2005 sp1.

So, I register the COM control, and after it i can make an instance in ActiveX Test Container (x64) but in VS2005 i can not use this com control. It is not in COM tab page and when i browse the abc.ocx, VS2005 refuses it...

Error message is the next:

A reference to the "...." could not be added.Please make sure that the file is accessible and that it is a valid assembly or COM component.

This contol is a visual control (shows pictures, resize them, ...) and the others are not.

A better way to reference your wizard steps using named steps

Note: this article uses the plain vanilla but the concepts apply equally well to its popular counterpart .

By far the most common way that I see wizard steps reference in code snippets is by their index.
Users Add  Delete EditViewActivate/DeactivateExport
Roles Add  Delete EditViewActivate/DeactivateExport
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