天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

asp.net 簡單實現禁用或啟用頁面中的某一類型的控件

比如,我們在提交一個表單的時候,可能由于網絡服務器的原因,處理很慢,而用戶在處理結果出來之前反復點擊按鈕提交。這樣很容易造成不必要的麻煩甚至是錯誤。說了這么多,其實就是要實現一個禁用某些控件的一種功能。好了,下面我就介紹自己簡單實現的這個小功能,貼代碼:
復制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace DotNET.Common.Util
{
/// <summary>
/// 控件枚舉,我們在禁用或啟用時,就是根據這個枚舉來匹配合適的項
/// </summary>
public enum ControlNameEnum
{
Panel = 0, //容器 這個比較常用
TextBox = 1,
Button = 2, //這個也比較常用 比如 按鈕提交后的禁用,返回結果后啟用
CheckBox = 3,
ListControl = 4,
All = 100 //所有
}
public static class ControlHelper
{
#region 同時禁用或者啟用頁面的某些控件
/// <summary>
/// 設置是否啟用控件
/// </summary>
/// <param name="control"></param>
/// <param name="controlName"></param>
/// <param name="isEnable"></param>
public static void SetControlsEnabled(Control control, ControlNameEnum controlName, bool isEnabled)
{
foreach (Control item in control.Controls)
{
/* 我們僅僅考慮幾種常用的ASP.NET服務器控件和html控件 */
//Panel
if (item is Panel && (controlName == ControlNameEnum.Panel || controlName == ControlNameEnum.All))
{
((Panel)item).Enabled = isEnabled;
}
//TextBox,HtmlTextBox
if (controlName == ControlNameEnum.TextBox || controlName == ControlNameEnum.All)
{
if (item is TextBox)
{
((TextBox)(item)).Enabled = isEnabled;
}
else if (item is HtmlInputText)
{
((HtmlInputText)item).Disabled = isEnabled;
}
else if (item is HtmlTextArea)
{
((HtmlTextArea)(item)).Disabled = isEnabled;
}
}
//Buttons
if (item is Button && (controlName == ControlNameEnum.Button || controlName == ControlNameEnum.All))
{
if (item is Button)
{
((Button)(item)).Enabled = isEnabled;
}
else if (item is HtmlInputButton)
{
((HtmlInputButton)(item)).Disabled = !isEnabled;
}
else if (item is ImageButton)
{
((ImageButton)(item)).Enabled = isEnabled;
}
else if (item is LinkButton)
{
((LinkButton)(item)).Enabled = isEnabled;
}
}
//CheckBox
if (controlName == ControlNameEnum.CheckBox || controlName == ControlNameEnum.All)
{
if (item is CheckBox)
{
((CheckBox)(item)).Enabled = isEnabled;
}
else if (item is HtmlInputCheckBox)
{
((HtmlInputCheckBox)(item)).Disabled = !isEnabled;
}
}
//List Controls
if (controlName == ControlNameEnum.ListControl || controlName == ControlNameEnum.All)
{
if (item is DropDownList)
{
((DropDownList)(item)).Enabled = isEnabled;
}
else if (item is RadioButtonList)
{
((RadioButtonList)(item)).Enabled = isEnabled;
}
else if (item is CheckBoxList)
{
((CheckBoxList)(item)).Enabled = isEnabled;
}
else if (item is ListBox)
{
((ListBox)(item)).Enabled = isEnabled;
}
else if (item is HtmlSelect)
{
((HtmlSelect)(item)).Disabled = !isEnabled;
}
}
//如果項目還有子控件,遞歸調用該函數
if (item.Controls.Count > 0)
{
SetControlsEnabled(item, controlName, isEnabled);
}
}
}
#endregion
}
}

ASPx頁面中的調用如下:
復制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ControlHelper.SetControlsEnabled(this.Page, ControlNameEnum.Panel, false); //Panel禁用
}
}

需要注意的是,我這里的實現只是針對幾種常用控件,您可以按照自己項目的需要任意擴展。
測試打包下載

AspNet技術asp.net 簡單實現禁用或啟用頁面中的某一類型的控件,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 出租屋交换人妻 全文 | 国产永久视频 | 中文字幕一区二区三区在线不卡 | 嫩草影院一区 | AV天堂AV亚洲啪啪久久无码 | 18未满不能进的福利社 | 在线观看国产高清免费不卡 | 动漫美女人物被黄漫在线看 | 国产乱码伦人偷精品视频 | thermo脱色摇床安卓下载 | 亚洲AV久久无码精品九号 | 国产三级精品三级男人的天堂 | 99精品视频在线观看免费播放 | 老太婆风流特黄一级 | 超碰免费视频caoporn | 日本污ww视频网站 | 精品欧美18videosex欧美 | 老师破女学生特级毛片 | 伊人久久综合网站 | 久久久99精品成人片中文 | 欧美亚洲日韩一道免费观看 | 嫩草亚洲国产精品 | 亚洲一级特黄 | 大肥婆丰满大肥奶bbw肥 | a视频在线观看 | 国产学生在线播放精品视频 | 最近中文字幕高清中文字幕MV | 俄罗斯15一16处交 | 媚药调教被撑到合不拢h | 亚洲精品电影久久久影院 | 好爽好深太大了再快一点 | 无羞耻肉动漫在线观看 | 亚洲 日韩经典 中文字幕 | 国产精品成久久久久三级四虎 | 诱受H嗯啊巨肉舍友1V1 | 免费观看视频成人国产 | 快播成电影人网址 | 毛片在线全部免费观看 | 一区二区三区内射美女毛片 | 国产精品久久久久久免费播放 | 久久久这里有精品999 |