passing values to custom user control from dropdownlist

Discussion in 'ASP .Net' started by adam, Aug 8, 2003.

  1. adam

    adam Guest

    i have custom user control and i'm trying to pass values to custom user
    control......I need help it seems to me i cannot pass the value to user
    control from dropdownlist. I have property in a control. In a default.aspx
    page <SkinExample:Hello id="HelloControl" SkinName="red" runat="server" />
    i can pass the value, it works fine, but from the dropdownlist in a
    codebehind page i can't pass the value.

    Could some one help me out with this.............Thanks

    here is my default.aspx page look like

    <%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
    Inherits="SkinExample._Default" %>
    <%@ Register TagPrefix="SkinExample" Namespace="SkinExample"
    Assembly="SkinExample" %>
    <!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
    <body ms_positioning="GridLayout">
    <form id=Form1 method=post runat="server">
    <SkinExample:Hello id="HelloControl" runat="server" />
    <asp:dropdownlist id=DropDownListSkins style="Z-INDEX: 101; LEFT: 21px;
    POSITION: absolute; TOP: 79px" runat="server" width="228px"
    <asp:ListItem Value="null" Selected="True">Select your skin from the
    <asp:ListItem Value="default">Default</asp:ListItem>
    <asp:ListItem Value="green">Green</asp:ListItem>
    <asp:ListItem Value="red">Red</asp:ListItem>
    <asp:Label id=Label1 style="Z-INDEX: 102; LEFT: 49px; POSITION: absolute;
    TOP: 253px" runat="server" Width="264px"></asp:Label>

    and codebehind page
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    namespace SkinExample
    /// <summary>
    /// Summary description for _Default.
    /// </summary>
    public class _Default : System.Web.UI.Page
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
    protected System.Web.UI.WebControls.DropDownList DropDownListSkins;

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

    private void DropDownList1_SelectedIndexChanged(object sender,
    System.EventArgs e)
    Control myCC = Page.FindControl("HelloControl");
    ((Hello)myCC).SkinName +=

    Label1.Text = "";
    Label1.Text += DropDownListSkins.SelectedItem.Value.ToString();

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    this.DropDownListSkins.SelectedIndexChanged += new
    this.Load += new System.EventHandler(this.Page_Load);

    adam, Aug 8, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.