_控件名".2.如果有圖片之類需要路徑的請用:/a/b/c.jpg3.需要調用用戶控件事件的話需要寫一個委托。以下面做一個查詢為例html代碼<%@ControlLangua" />

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

如何實現用戶自己定義控件。

系統 1619 0
1.?新建 *.axcx 文件。
2. 跟一般網頁一樣放控件。
3. 在事件里面寫處理過程。
4. 拖到aspx頁面就可以用了。

過程注意的地方。
1.如果用到javascript ,用document.getElementById()來查找服務器控件需要在控件名前面加上 "<%= this.ClientID %>_控件名".
2.如果有圖片之類需要路徑的請用:/ a / b / c.jpg
3.需要調用用戶控件事件的話需要寫一個委托。
以下面做一個查詢為例
html 代碼
<% @?Control?Language = " c# " ?AutoEventWireup = " false " ?Codebehind = " Search.ascx.cs " ?Inherits = " Search " ?TargetSchema = " http://schemas.microsoft.com/intellisense/ie5 " ?enableViewState = " True " %>
< script >
????????????
var ?ParentName? = ? " <%=?this.ClientID?%> " ;
????????????
function ?initXMLHTTPRequest() {
????????????????
var ?xRequest? = ? null ;
????????????????
if ?(?window.XMLHttpRequest?) {
????????????????????xRequest?
= ? new ?XMLHttpRequest();
????????????????}
? else ? if ?(?window.ActiveXObject?) {
????????????????????xRequest?
= ? new ?ActiveXObject( " Microsoft.XMLHTTP " );
????????????????}

????????????????
return ?xRequest;
????????????}

????????????
function ?GetDataSetCity(obj)
????????????
{????????????????
????????????????
var ?svalue = obj.value;
????????????????
var ?webFileUrl? = ? " ?father= " ? + ?svalue;
  ????????????
var ?result? = ? "" ;
  ????????????
var ?xmlHttp? = ?initXMLHTTPRequest();? // new?ActiveXObject("MSXML2.XMLHTTP");
  ????????????xmlHttp.open( " POST " ,?webFileUrl,? false );
  ????????????xmlHttp.send(
"" );
  ????????????
  ????????????result?
= ?xmlHttp.responseText;

????????????????
if (result? != ? "" )
????????????????
{
????????????????????document.all(ParentName
+ " _dropCity " ).length = 0 ;
 ????????????????????
var ?piArray? = ?result.split( " , " );
 ????????????????????
for ( var ?i = 0 ;i < piArray.length;i ++ )
 ????????????????????
{
 ????????????????????????
var ?ary1? = ?piArray[i].toString().split( " | " );
 ????????????????????????document.all(ParentName
+ " _dropCity " ).options.add( new ?Option(ary1[ 1 ].toString(),ary1[ 0 ].toString()));
 ????????????????????}

????????????????}

????????????????
else
????????????????
{
????????????????????
for ?(i = (document.all(ParentName + " _dropCity " ).length - 1 );i >= 0 ;i -- ) {
????????????????????????document.all(ParentName
+ " _dropCity " ).options.remove(i);
????????????????????}

????????????????????document.all(ParentName
+ " _dropCity " ).options.add( new ?Option( " 城市 " , " 0 " ));
????????????????}

????????????}

????????????
function ?getData()
????????????
{
????????????????
var ?province = document.getElementById(ParentName + " _dropProvince " );
????????????????
var ?pindex? = ?province.selectedIndex;
????????????????
var ?pValue? = ?province.options[pindex].value;
????????????????
var ?pText?? = ?province.options[pindex].text;
????????????????
????????????????
var ?city = document.getElementById(ParentName + " _dropCity " );
????????????????
var ?cindex? = ?city.selectedIndex;
????????????????
var ?cValue? = ?city.options[cindex].value;
????????????????
var ?cText?? = ?city.options[cindex].text;
????????????????
????????????????document.getElementById(ParentName
+ " _hidprovince " ).value = pText;
????????????????document.getElementById(ParentName
+ " _hidcity " ).value = cText;
????????????}

????????????
function ?JHR()
????????????
{
????????????????window.history.back();
????????????}

</ script >
< table? cellSpacing ="0" ?cellPadding ="0" ?width ="100%" ?border ="0" >
????
< tr >
????????
< td? vAlign ="bottom" ?align ="right" ?width ="24" ?height ="218" >< IMG? height ="218" ?src ="/yizhi/images/chaxun_12.gif" ?width ="24" ></ td >
????????
< td? vAlign ="bottom" ?align ="left" >
????????????
< table? id ="__01" ?height ="235" ?cellSpacing ="0" ?cellPadding ="0" ?width ="216" ?border ="0" >
????????????????
< tr >
????????????????????
< td? colSpan ="3" >< IMG? height ="102" ?alt ="" ?src ="/yizhi/images/chaxun_01.gif" ?width ="216" ></ td >
????????????????
</ tr >
????????????????
< tr >
????????????????????
< td >< IMG? height ="8" ?alt ="" ?src ="/yizhi/images/chaxun_02.gif" ?width ="15" ></ td >
????????????????????
< td >< IMG? height ="8" ?alt ="" ?src ="/yizhi/images/chaxun_03.gif" ?width ="185" ></ td >
????????????????????
< td >< IMG? height ="8" ?alt ="" ?src ="/yizhi/images/chaxun_04.gif" ?width ="16" ></ td >
????????????????
</ tr >
????????????????
< tr >
????????????????????
< td? background ="/yizhi/images/chaxun_05.gif" ?width ="15" ></ td >
????????????????????
< td? align ="center" ?width ="185" ?bgColor ="#f7f7f7" ?height ="103" >
????????????????????????
< table? cellSpacing ="5" ?cellPadding ="0" ?width ="90%" ?border ="0" >
????????????????????????????
< tr >
????????????????????????????????
< td? align ="left" >< asp:textbox? id ="txtName" ?Runat ="server" > 請輸入關鍵字 </ asp:textbox >< a? id ="aSearchs" ?onclick ="JHR();" ?href ="UserListAll.aspx" ?target ="_blank" ></ td >
????????????????????????????
</ tr >
????????????????????????????
< tr >
????????????????????????????????
< td? align ="left" >< asp:DropDownList? ID ="dropCategory" ?Runat ="server" ></ asp:DropDownList ></ td >
????????????????????????????
</ tr >
????????????????????????????
< tr >
????????????????????????????????
< td? align ="left" >< asp:DropDownList? ID ="dropTime" ?Runat ="server" >
????????????????????????????????????????
< asp:ListItem? Value ="0" > 發布時間 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="1" > 1天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="2" > 2天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="3" > 3天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="4" > 4天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="5" > 5天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="10" > 10天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="20" > 20天內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="30" > 一個月內 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="90" > 三個月內 </ asp:ListItem >
????????????????????????????????????
</ asp:DropDownList ></ td >
????????????????????????????
</ tr >
????????????????????????????
< tr >
????????????????????????????????
< td? align ="left" >< asp:DropDownList? ID ="dropProvince" ?Runat ="server" ></ asp:DropDownList >
????????????????????????????????????
< asp:DropDownList? ID ="dropCity" ?Runat ="server" ></ asp:DropDownList ></ td >
????????????????????????????
</ tr >
????????????????????????????
< tr >
????????????????????????????????
< td? align ="left" >< asp:Button? ID ="btnSearch" ?Runat ="server" ?Text ="搜?索" ></ asp:Button >< INPUT? id ="hidprovince" ?style ="WIDTH:?31px;?HEIGHT:?22px" ?type ="hidden" ?size ="1" ?name ="hidprovince"
????????????????????????????????????????runat
="server" >< INPUT? id ="hidcity" ?style ="WIDTH:?34px;?HEIGHT:?22px" ?type ="hidden" ?size ="1" ?name ="hidprovince"
????????????????????????????????????????runat
="server" ></ td >
????????????????????????????
</ tr >
????????????????????????
</ table >
????????????????????
</ td >
????????????????????
< td? background ="/yizhi/images/chaxun_07.gif" ?width ="16" ></ td >
????????????????
</ tr >
????????????????
< tr >
????????????????????
< td >
????????????????????????
< img? src ="/yizhi/images/chaxun_08.gif" ?width ="15" ?height ="8" ?alt ="" ></ td >
????????????????????
< td >
????????????????????????
< img? src ="/yizhi/images/chaxun_09.gif" ?width ="185" ?height ="8" ?alt ="" ></ td >
????????????????????
< td >
????????????????????????
< img? src ="/yizhi/images/chaxun_10.gif" ?width ="16" ?height ="8" ?alt ="" ></ td >
????????????????
</ tr >
????????????????
< tr >
????????????????????
< td? colspan ="3" >
????????????????????????
< img? src ="/yizhi/images/chaxun_11.gif" ?width ="216" ?height ="14" ?alt ="" ></ td >
????????????????
</ tr >
????????????????
< tr >
????????????????????
< td > &nbsp; </ td >
????????????????
</ tr >
????????????
</ table >
????????
</ td >
????
</ tr >
</ table >

2. cs 代碼
namespace ?ProductControls
{
????
using ?System;
????
using ?System.Data;
????
using ?System.Drawing;
????
using ?System.Web;
????
using ?System.Web.UI.WebControls;
????
using ?System.Web.UI.HtmlControls;

????
/// ? <summary>
????
/// Search?的摘要說明。
????
/// ? </summary>

???? public ? class ?Search?:?System.Web.UI.UserControl
????
{
????????
protected ?System.Web.UI.WebControls.TextBox?txtName;
????????
protected ?System.Web.UI.WebControls.DropDownList?dropCategory;
????????
protected ?System.Web.UI.WebControls.DropDownList?dropTime;
????????
protected ?System.Web.UI.WebControls.DropDownList?dropProvince;
????????
protected ?System.Web.UI.WebControls.DropDownList?dropCity;
????????
protected ?System.Web.UI.WebControls.Button?btnSearch;
????????
protected ?System.Web.UI.HtmlControls.HtmlInputHidden?hidprovince;
????????
protected ?System.Web.UI.HtmlControls.HtmlInputHidden?hidcity;
????????YzBLL.Members?m
= new ?YzBLL.Members();
????????
public ? string ?CategoryName
????????
{
????????????
get
????????????
{
????????????????
string ?Name? = ? this .txtName.Text.Trim();
????????????????
if ?(?Name? == ? " 請輸入關鍵字 " ?)
????????????????????Name?
= ? "" ;
????????????????
return ?Name;
????????????}

????????????
set
????????????
{
????????????????
????????????????
this .txtName.Text? = ?value;
????????????}

????????}

????????
public ? string ?CategoryID
????????
{
????????????
get
????????????
{
????????????????
return ? this .dropCategory.SelectedValue;
????????????}

????????????
set
????????????
{
????????????????
this .dropCategory.SelectedValue? = ?value;
????????????}

????????}

????????
public ? string ?CreateTime
????????
{
????????????
get
????????????
{
????????????????
return ? this .dropTime.SelectedValue;
????????????}

????????????
set
????????????
{
????????????????
this .dropTime.SelectedValue? = ?value;
????????????}

????????}

????????
public ? string ?Area
????????
{
????????????
get
????????????
{
????????????????
string ?area? = ? " 不限 " ;
????????????????
if ?(? this .hidprovince.Value.Trim()? != ? " 省份 " ??)
????????????????
{
????????????????????area?
= ? this .hidprovince.Value;
????????????????????
if ?(? this .hidcity.Value.Trim()? != ? " 城市 " ?)
????????????????????????area?
= ?area? + " - " + this .hidcity.Value.Trim();
????????????????}

????????????????
else
????????????????????area?
= ? "" ;
????????????????
return ?area;
????????????}

????????}

????????
private ? void ?Page_Load( object ?sender,?System.EventArgs?e)
????????
{
????????????
this .BindddlProvince();
????????????
if (father != "" )
????????????
{
????????????????
this .BindddlCity(Convert.ToInt32(father));
????????????}

????????????
else
????????????
{
????????????????dropCity.Items.Clear();
????????????????dropCity.Items.Add(
new ?ListItem( " 城市 " , " 0 " ));
????????????}

????????????
// ?在此處放置用戶代碼以初始化頁面
???????????? if ?(? ! Page.IsPostBack?)
????????????
{
????????????????BindCategory();
????????????????BindddlProvince();
????????????????
this .dropProvince.Attributes.Add( " onchange " , " GetDataSetCity(this); " );
????????????????
this .btnSearch.Attributes.Add( " onclick " , " getData(); " );
????????????}

????????}

????????
private ? void ?BindCategory()
????????
{
????????????DataTable?dtCategory?
= ? new ?DataTable();
????????????YzBLL.YzGqInfo?gq?
= ? new ?YzBLL.YzGqInfo();
????????????dtCategory?
= ?gq.GetCategory();
????????????
this .dropCategory.DataSource? = ?dtCategory;
????????????
this .dropCategory.DataTextField? = ? " CategoryName " ;
????????????
this .dropCategory.DataValueField? = ? " Categoryid " ;
????????????
this .dropCategory.DataBind();
????????????
this .dropCategory.Items.Insert( 0 , new ?ListItem( " 產品種類 " , " 0 " ));
????????}

????????
// 綁定ddlProvince
???????? public ? void ?BindddlProvince()
????????
{
????????????DataTable?dt
= m.AllProvince();
????????????
this .dropProvince.DataSource = dt.DefaultView;
????????????
this .dropProvince.DataTextField = " province " ;
????????????
this .dropProvince.DataValueField = " provinceID " ;
????????????
this .dropProvince.DataBind();
????????????
this .dropProvince.Items.Insert( 0 , new ?ListItem( " 省份 " , " 0 " ));
????????}

????????
// 綁定BindddlCity
???????? public ? void ?BindddlCity( int ?father)
????????
{
????????????
string ?mystr? = ? "" ;
  ????????DataTable?dt
= m.AllCity(father);

  ????????
if (dt.Rows.Count? != ? 0 )
  ????????
{
??????????????mystr
+= " , " + " 0 " + " | " + " 城市 " ;
    ????????
for ( int ?i = 0 ;i < dt.Rows.Count;i ++ )
    ????????
{
      ????????mystr?
+= ? " , " ? + ?dt.Rows[i][ 1 ].ToString()? + ? " | " ? + ?dt.Rows[i][ 2 ].ToString();
    ????????}

    ????????mystr?
= ?mystr.Substring( 1 );
  ????????}

  ????????
this .Response.Write(mystr);
  ????????
this .Response.End();
????????}


????????
private ? string ?father
????????
{
????????????
get
????????????
{
????????????????
if (ViewState[ " father " ] != null ? && ?ViewState[ " father " ].ToString() != "" )
????????????????
{
????????????????????
return ?ViewState[ " father " ].ToString();
????????????????}

????????????????
else
????????????????
{
????????????????????
if (Request[ " father " ] != null ? && ?Request[ " father " ].ToString() != "" )
????????????????????
{
????????????????????????
return ?Request[ " father " ];
????????????????????}

????????????????????
else
????????????????????
{
????????????????????????
return ? "" ;
????????????????????}

????????????????}

????????????}

????????????
set
????????????
{
????????????????ViewState[
" father " ] = value;
????????????}

????????}

????????
Web?窗體設計器生成的代碼

????????
public ? delegate ? void ?OnSearch( object ?sender,System.EventArgs?e);
????????
public ? event ?OnSearch?onSearch;
????????
private ? void ?btnSearch_Click( object ?sender,?System.EventArgs?e)
????????
{
????????????
if ?(?onSearch? != ? null ?)
????????????
{
????????????????onSearch(sender,e);
????????????}

????????}

????}

}

如何實現用戶自己定義控件。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲一区二区三区免费看 | 日日拍夜夜嗷嗷叫国产 | 日本精品一区 | 福利观看 | 九九热视 | 九九热香蕉视频 | 国产成人综合亚洲动漫在线 | 一级片一级毛片 | 中文字幕精品一区二区三区在线 | 国产精品九九热 | 欧美一级看片a免费视频 | 久久精品国产精品亚洲综合 | 99久久www免费 | 久久日本精品99久久久 | 四虎影午夜成年免费精品 | 在线亚洲精品国产成人二区 | 国产精品成人麻豆专区 | 国产欧美一区二区三区视频 | 国产区精品福利在线观看精品 | 欧美日韩免费 | 亚洲精品综合欧美一区二区三区 | 久久久亚洲国产精品主播 | 久草在线最新视频 | 亚洲天码中字 | 欧美日韩一级黄色片 | 亚洲福利一区二区 | 四虎影视成人永久在线播放 | 国内主播大秀福利视频在线看 | 亚洲影院中文字幕 | 亚洲日韩欧美综合 | 久久66热re国产毛片基地 | 天天插夜夜爽 | 99久久精品费精品国产一区二 | 国产精品人人视频 | 亚洲不卡 | 成人精品视频在线观看 | 日韩精品一区二区三区乱码 | 色综合久久中文字幕 | 欧美日韩视频在线成人 | aⅴ免费在线观看 | 91国视频在线观看 |