.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

How to Bind a child control with properties of the parent control in Silverlight and WPF?

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :WPF
Dear Experts, I have a usercontrol in Silverlight and I want to enable the update button inside the usercontrol with property defined in the usercontrol. For the proof of concept sake I have defined the usercontrol xaml and the code behind in VB.NETBelow is the XAML and VB.NET Code. ----------------------------------------------------------------------- <UserControl x:Class="SLBAppAssementQuestions.SilverlightControl1"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     mc:Ignorable="d"     d:DesignHeight="300" d:DesignWidth="400">     <StackPanel>         <CheckBox x:Name="chkBox1" Margin="10" Checked="chkBox1_Checked" >Checkbox1</CheckBox>         <CheckBox x:Name="chkBox2" Margin="10" Checked="chkBox2_Checked">Checkbox1</CheckBox>         <Button  x:Name="BtnUpdate&q

View Complete Post

More Related Resource Links

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?

Sharing value from child control to parent control.


I am relatively new to this, but here is my problem.

I have a parent and a child control. Within the child control I have a dropdown list. Based on dropdown list's selected value I would like to toggle Visibility of Panel in parent control. For instance if I select Show in child control dropdown list, I need to pass true to parent control to make Panel visible and vice versa. How should I do that. I have read that can be done via the event handling and have seen certain scenarios but I am not clear on that. Please help!


Find Control of parent webpage from child page under iframe



I  Have a webpage suppose ParentPage.aspx which contains a iframe. Under iframe i am calling another webpage Childpage.aspx . Now i want to access ParentPage controls from ChildPage and change the property of that control.

Can any one suggest me how it is possible ?

Below i am writing a code which i am trying. In this code Page.PreviousPage is always null .

if (Page.PreviousPage != null)
                    AjaxControlToolkit.TabPanel objTab = (AjaxControlToolkit.TabPanel)Page.PreviousPage.FindControl("pnlDataElement");
                    if (objTab != null)
                       objTab.Enabled = true;

How to access child(.ascx) page control from parent page(.aspx) javascript


I have functionality to select All check boxes on grid rows.

Child User control is having grid with checkbox to select all rows of grid. I want to select individual cell html from each row when I select all rows when checkbox 'select all' is clicked and place it into textbox which is in Parent page.

This textbox can only be in parent page.

So i need to call child(.ascx) page control from parent page(.aspx) using javascript as follows.

function CheckUncheckChildren(event)
        var childChkBoxes = document.getElementById('<%=gvUserDetails.ClientID %>').getElementsByTagName("input");
        var childChkBoxCount = childChkBoxes.length;
        var evtelem = (isIE())?event.srcElement:event.currentTarget;
        if(evtelem.checked == true)
            for(var i = 0; i<childChkBoxCount; i++)

Propagate child event to a parent control in a user control

I developed a user control with using a picturebox and a label in .net.  Then I create an instance of the user control in a form. Here I wish to add an click event handler for that user control. I want to use only one click event handler for that control not for every controls (eg: picturebox ,label). Even an user click on a label ,picturebox or the form container, an UserControl_click event will be fired. How can I accomplish this?

GridView control to show master-child or master-slave data, written in c#, asp.net

I previously made a master slave datagrid using Visual Studio 2003 .Net (original article) that would allow users to show data to clients using collapse and expand features. These features however did not carry over to gridview for many users. This tutorial will explaing how to create a collapsable/expandable gridview in frameworks 2.0 and higher

Composite Control which contains arbitrary content defined in .aspx of parent and thier ViewState


I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>

<div class="box">
    <div class="Header-Left">
        <div class="Header-Right">
            My Control
    <div class="Content">
        <asp:PlaceHolder ID="contentPlace" runat="Server" />

Access and Bind data wihtout using Datasource Control


i want to bind my gridview with a dataset with concept of caching (to minimize the database server trips). plz give me a best example to get and bind data to gridview (command line) . grid paging is also enabled so example code should be capable to rebind data at Gridview page change.  

Child control in Repeater



     I am trying to find a child control from a repeater control's child control. I have the following structure like a top control is a repeater, below which is a Panel and below this is a DateControl(custom control).

I want to find the DateControl.

<asp:Repeater runat="server"
                       <asp:Panel ID="pnlAddDependent"

                                  <xyz:DateControl runat="server" ID="dfDepBirthDate"


When iam trying like this, i am getting the "Object Reference not set error". Please help, it is urgent.

if (this.rptMembers.FindControl("pnlAddDependent").FindContro

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

Problem with User Control Properties


I've been trying to figure out a problem that I've had for the past week and believe that the issue is something with a user control that I created. In short, the properties for the user control are recognized by intelisense when I register the control and then add it in the markup for a page. However, the values that I set in the markup are ignored by the class as if the properties don't exist.



Parent Page

 <%@ Register Src="../../controls/contactdetail.ascx" TagName="ContactDetail" TagPrefix="tfc" %>

<tfc:ContactDetail runat="server" ID="UserControlContactDetail" Title="Contact-Detail" ContactId="1580" EnableViewState="true" />   



User Control Class

Imports System.Data
Imports System.Data.SqlClient

Partial Class control_ContactDetail
    Inherits System.Web.UI.UserControl
    Public Property ContactId() As Integer
            Return _ContactId
        End Get
        Set(ByVal value As Integer)
            _ContactId = value
        End Set
    End Property
    Private _ContactId As Integer
    Public Property Title() As String
            Return _Title
        End Get

Removing a (child) user control from an observable collection

Hey all, so I have an ObservableCollection of UserControls.  These user controls have their own xaml and each of these has some type of "Close" button so it would be removed from the ObservableCollection. A groupbox is binded to the ObservableCollection so it would show all the UserControls.  When a user clicks on the "Close" button, the user control is removed from the ObservableCollection and thus, the groupbox.  How can I do this?  I've tried something like   (this .Parent as ObservableCollection<asdf>).Remove(this );   where asdf is a UserControl but I get a bunch of compiler errors.

How can I register a name for a control that is an ItemsControl child?

Hello, How can I register a name for a control that is an ItemsControl child? When I create the controls dynamically in code, the RegisterName works just fine.  However, when those same controls are created by the ItemsControl XAML, RegisterName does not work. Here is the XAML which correctly generates what I want: <Canvas Name="Tab_CanvasTabs"> <Canvas.Resources> <local:CategoryTabs x:Key="myTabs" /> </Canvas.Resources> <ItemsControl Name="Tab_ItemsControl" ItemsSource="{Binding Source={StaticResource myTabs}}"> <ItemsControl.Template> <ControlTemplate TargetType="ItemsControl"> <ItemsPresenter /> </ControlTemplate> </ItemsControl.Template> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Canvas /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <DataTemplate.Resources> </DataTemplate.Resources> <Canvas Name="Tab_Canvas_X" Tag="{Binding Path=Number}" MouseLeftButtonDown="Event_CategoryTab_Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Event

How to bind a calendar control to a datasource

In my application, user will enter some meeting dates in one page.   In the details page, they need to see those dates to make a selection for one file number. I want to show a calendar in the details page whice will show the dates already entered. To do that I need to bind the calendar to a datasource to get the information from the database. Please guide me to do that. Thanks in advance,

How to control the text and other properties in ResourceDictionary object that i wrote ?

I wrote some ResourceDictionary. This ResourceDictionary is actuly a button that i use - I created this button by using Rectangle and TextBlock ==> that mean that the my xaml look like the code below. The problem is that i cant change the font size and the text of the TextBlock. I can change is just from the xaml of the template. And ... How can i define some variable that will control on the rectAngle redius in runtime ? Someone can help ?? ? Thanks. ...<ResourceDictionary> <Style x:Key="MyBtn" TargetType="{x:Type Button}"> <Rectangle ... <TextBlock.... </ResourceDictionary> ...

custom server control with custom child collection,get the collection?

Hi!I want to create a custom server control, that then will have a custom child collection.The thing is that I also want to be able to modify the custom childs from the custom server control classFor example I have a row of cards, and the class is called CardRow, a CardRow is simply a class full of the class card in this case, se the class "Card" down below:using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Collections.Generic; namespace MemoryLib { [ToolboxData("<{0}:CardRow runat=server></{0}:CardRow>")] public class CardRow : WebControl { public List<Card> _Card; [PersistenceMode(PersistenceMode.InnerProperty)] public List<Card> Card { get { return _Card; } set { _Card = value; } } public CardRow() { } protected override void CreateChildControls() { } protected override void Render(HtmlTextWriter writer) { } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace MemoryLib

Silverlight media player control for mvc

I wamnted to add a silverlight media player to my MVC site. there was a silvlight Media player that you could drag and drop on a page from the tool box, but I cant find it anymore. I am not sure it was good for mvc anyhow,   what is the easiest way to get a silverlight media player up and running on a mvc site, I really dont want to make my own, incorarating a silverlight app just for the media playerr seems like a fair bit of work, i was really looking for the drag and drop option we had in VS2008  I'm using VS2010 .net 4 silverlight 4 Any ideas?
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