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" >
    <html>
    <head>
    </head>
    <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"
    autopostback="True">
    <asp:ListItem Value="null" Selected="True">Select your skin from the
    list</asp:ListItem>
    <asp:ListItem Value="default">Default</asp:ListItem>
    <asp:ListItem Value="green">Green</asp:ListItem>
    <asp:ListItem Value="red">Red</asp:ListItem>
    </asp:dropdownlist>
    <asp:Label id=Label1 style="Z-INDEX: 102; LEFT: 49px; POSITION: absolute;
    TOP: 253px" runat="server" Width="264px"></asp:Label>
    </form>
    </body>
    </html>

    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 +=
    DropDownListSkins.SelectedItem.Value.ToString();

    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.
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <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
    System.EventHandler(this.DropDownList1_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion
    }
    }
    adam, Aug 8, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD

    Re: user control - passing values

    Steve C. Orr, MCSD, Jul 12, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    434
    Sabre
    Jul 12, 2003
  2. Leeor Chernov
    Replies:
    2
    Views:
    775
    Leeor Chernov
    Oct 16, 2005
  3. Matt Sokol
    Replies:
    2
    Views:
    355
    Theo Tillotson
    Aug 7, 2003
  4. Chris Kennedy

    Passing values to a custom control

    Chris Kennedy, May 9, 2004, in forum: ASP .Net Building Controls
    Replies:
    5
    Views:
    168
    Sanket Naik
    Jun 26, 2004
  5. hmikki
    Replies:
    1
    Views:
    126
    Nathan Sokalski
    Oct 19, 2007
Loading...

Share This Page