How can I make a custom element in aspx that inherits DropDownList
?
I would like the element to look this way when I call it:
<componente:DropPersonalizado runat="server" id=""></componente:DropPersonalizado>
How can I make a custom element in aspx that inherits DropDownList
?
I would like the element to look this way when I call it:
<componente:DropPersonalizado runat="server" id=""></componente:DropPersonalizado>
Create a User Control as follows: Click on your project and add a new item related to the image below:
Afterenteringyournameitwillopendesign
andcode
forthisUserControl
andyoucanaddtheelementsyouneedinbuildingsomething.
Creation:
IputaPanelandDropDownListlikethis:
<%@ControlLanguage="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)
{
}
}
}
Why? When I put this component on the screen I will have public access to this configuration and with that 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 to the desired location.
Andinyourpropertieswillappearthatsizeconfiguration:
Note: Any property, event, or configuration should be implemented in Código
do User Control