1、建一个ascx文件,取名为txtBoxRejectChk.ascx(一个TextBox与Check的排他功能),code如下:
(1.1).ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="txtBoxRejectChk.ascx.cs" Inherits="txtBoxRejectChk" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class txtBoxRejectChk : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public String Comment
{
get
{
return txtBox.Text;
}
set
{
txtBox.Text = value;
}
}
public string check
{
get
{
return chkBox.Text;
}
set
{
chkBox.Text = value;
}
}
public CheckBox chek
{
get
{
return chkBox;
}
set
{
chkBox = value;
}
}
protected void txtBox_TextChanged(object sender, EventArgs e)
{
if (txtBox.Text.Length > 0)
{
chkBox.Checked = false;
chkBox.Enabled = false;
}
else
{
chkBox.Enabled = true;
}
}
protected void chkBox_CheckedChanged(object sender, EventArgs e)
{
if (chkBox.Checked == true)
{
txtBox.Text = "";
}
else
{
chkBox.Checked = false;
}
}
}
2.投票的0分-10分的功能
(2.1)MitiSelect.ascx <%@ Control Language="C#" AutoEventWireup="true" CodeFile="MitiSelect.ascx.cs" Inherits="MitiSelect" %> Completed satisfied | Acceptable | Dissatisfied | |||||||||
3.引用webusercontrol,取名为UserWebControl.aspx,code如下:
(3.1)UserWebControl.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserWebControl.aspx.cs" Inherits="UserWebControl" %>
<%@ Register src="txtBoxRejectChk.ascx" tagname="WebUserControl_textRejchk" tagprefix="uc1" %>
<%@ Register src="MitiSelect.ascx" tagname="WebUserControl_mutiselect" tagprefix="uc2" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserWebControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lbl1.Text=txtBoxRechk.Comment;
lbl2.Text = txtBoxRechk.check;
lbl2.Text = WebUserControl_textRejchk1.check;
lbl2.Text = WebUserControl_mutiselect1.strValue;
}
protected void Button1_Click(object sender, EventArgs e)
{
lbl2.Text = WebUserControl_mutiselect1.strValue;
}
}