如何自定义用户控件 [英] how to customize the User Control
问题描述
HI,
我有一个包含Textbox,radiobutton,dropdownlist和button的aspx页面。我希望在另外两页中使用相同的控件或相同的表单。所以我打算创建用户控件但我无法找到那些控件。
有人可以告诉我如何在用户控件中执行此操作并处理它像dropdownlist选择inedex的事件已更改,textbox textchanged事件和所有..?
提前感谢..
Madan
I have one aspx page with Textbox, radiobutton, dropdownlist and button. same controls or same form i want in another two pages. so im planning to create the User control but Im not able to find that controls.
Can some one please let me know how to do this in User control and handle its events like dropdownlist selected inedex changed, textbox textchanged events and all..?
Thanks in advance..
Madan
推荐答案
这是什么问题?澄清而不是复制粘贴它
what is this question ? clarify instead of copy pasting it
创建用户控件后,在该文件后面的用户控件代码上创建每个控件的getter和setter。
这里我的用户控件让我们说demoControl.ascx,
假设有1个标签控件在那里,
Hi,
Once you create a user control,Create a getter and setter of each control on that user control code behind file.
here my user control lets say demoControl.ascx in that,
Suppose 1 label control is there,
<asp:label id="lblName" runat="server/" xmlns:asp="#unknown"></asp:label>
&在demoControl.ascx.cs中,
& in demoControl.ascx.cs ,
public Label LBL_Name
{
get
{
return lblName;
}
set
{
lblName = value;
}
}
在所需页面中调用该用户控件。
Calling that user control in your required page.
<![CDATA[<%@ Register TagPrefix="demoTest" TagName="demoTest" Src="<User Control Path>" %>]]>
<demotest:demotest id="ucDemoControl" title="DemoControl" runat="server" xmlns:demotest="#unknown" />
&在代码隐藏中,
& In codebehind,
ucDemoControl.LBL_Name.text="Code Project";
这篇关于如何自定义用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!