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

欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

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

系統 1703 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條評論
主站蜘蛛池模板: 国产精品人妻无码八区仙踪林 | 亚洲码专区 | 欧美视频在线观看 | 91精品视频免费在线观看 | 男人的天堂av2017在线 | 男女交配视频网站 | 亚洲精品久 | 国产精品一二区 | 国产专区在线播放 | 亚洲成片在线观看12345ba | 亚洲福利 | 国产日韩欧美中文字幕 | 日韩av在线中文字幕 | 色屁屁www免费看视频影院 | 九九精品视频在线播放 | 精品视频网| 免费观看h片 | 成年人在线观看视频 | 免费一级欧美片片线观看 | 亚洲天天综合色制服丝袜在线 | 欧美顶级毛片在线播放 | 天天色天天碰 | 中国女警察一级毛片视频 | 精品国产91亚洲一区二区三区www | 亚洲播播播 | 色吧久久 | 国产乳摇福利视频在线观看 | 久草综合在线视频 | 波多野结衣免费观看视频 | 91网页在线观看 | 亚洲精品一区在线观看 | 欧美影院| 欧美成人激情在线 | 国产女主播在线 | 亚洲精品一区在线 | 久久久久久综合 | 亚洲国产成人va在线观看网址 | 日韩欧美在线视频 | 1024app成人无限观看 | 亚洲精品视频一区二区三区 | www.久久久久久久久 |