Custom Element Web Forms

Asked

Viewed 116 times

1

How can I make a custom element in aspx that I inherit DropDownList?

I wish the element would stay that way when I call it:

<componente:DropPersonalizado runat="server" id=""></componente:DropPersonalizado>

  • It would be a Usercontrol?

  • Yes @Cezar, would be a user control

  • I get it, you have some more pertinent information to do something personalized, what will change from the original offered by Toolbar of what you want to customize ??? has something specific !!! if yes put as a complement to your question !!!

  • Man, at the moment I just need that. The rest I want to try to do alone. D Thank you for the attention

1 answer

0

Create a User Control as follows: Click on your project and add a new image item below:

inserir a descrição da imagem aqui

After you put your name he will open one design and a code concerning this UserControl and you can add the elements you need in building something particular.

Creating:

I put a Panel and a Dropdownlist this way:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WUCDropDownList.ascx.cs" Inherits="WebApplication3.WUCDropDownList" %>
<asp:Panel ID="PanelDrop" runat="server">
    <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</asp:Panel>

In your code I made some settings for example size, as demonstrated in the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication3
{
    public partial class WUCDropDownList : System.Web.UI.UserControl
    {
        public Unit Width
        {
            get
            {
                return DropDownList1.Width;
            }
            set
            {
                DropDownList1.Width = value;
                PanelDrop.Width = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}

Because? When I put this component on the screen I will have public access to this setting and with it I can change the size that will be rendered on the screen.

Open your page in Design Mode (Example: default.aspx) and drag the created component in the desired location.

inserir a descrição da imagem aqui

And in its properties will appear that size setting:

inserir a descrição da imagem aqui

Obs: Any property, event or configuration must be implemented in Código do User Control

Browser other questions tagged

You are not signed in. Login or sign up in order to post.