Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to write user control ?

How to write user control ?

Scheduled Pinned Locked Moved ASP.NET
csharpdesignsysadmintutorialquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paper67
    wrote on last edited by
    #1

    Hi, I have tried to construct a user control named EventCategory, that holds 2 dropdownlists to select an event category. Depending on the selection in the first dropdownlist, the second dropdownlist must be repopulated with items corresponding with the first dropdownlist selection. Here is my control : <%@ Control Language="C#" AutoEventWireup="true" CodeFile="EventCategory.ascx.cs" Inherits="EventCategory" %> <table border="0"> <tr> <td style="width: 65px"><asp:Label ID="CategoryLabel" runat="server" Text="Category:" AssociatedControlID="CategoryList" /></td> <td> <asp:DropDownList ID="CategoryList" runat="server" Width="130px" AutoPostBack="True" OnSelectedIndexChanged="CategoryList_SelectedIndexChanged" /> </td> <td style="width: 20px" /> <td style="width: 90px"><asp:Label ID="SubCategoryLabel" runat="server" Text="SubCategory:" AssociatedControlID="SubCategoryList" /></td> <td> <asp:DropDownList ID="SubCategoryList" runat="server" Width="130px" /> </td> </tr> </table> When i enter the control in a web page, I can wite something like this : <!-- The user control gets registered in web.config --> .... <UC:EventCategory ID="EventCategory" runat="server" SelectText="«Select»" Category="Parties" /> Here I want the "Parties" item to be initial selected in the CategoryList control when the page comes up. therefore I wrote the following in code behind : public partial class EventCategory : System.Web.UI.UserControl { #region Private data members private string m_strCategory = string.Empty; private string m_strSubCategory = string.Empty; #endregion #region Public properties [Category("Appearance"), DefaultValue(""), Description("The event category associated with the user control.")] public string Category { get { return ((CategoryList.SelectedItem != null) && (CategoryList.SelectedItem.Value != "0") ? CategoryList.SelectedItem.Text : string.Empty).Trim(); } set { m_strCategory = value.Trim(); } } [Category("Appearance"), DefaultValue(""), Description("The event subcategory associated with the user control.")] public string SubCategory { get { return ((SubCategoryList.SelectedItem != null) && (SubCategoryList.SelectedItem.Val

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups