_控件名".2.如果有圖片之類需要路徑的請(qǐng)用:/a/b/c.jpg3.需要調(diào)用用戶控件事件的話需要寫一個(gè)委托。以下面做一個(gè)查詢?yōu)槔齢tml代碼<%@ControlLangua" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

如何實(shí)現(xiàn)用戶自己定義控件。

系統(tǒng) 1904 0
1.?新建 *.axcx 文件。
2. 跟一般網(wǎng)頁(yè)一樣放控件。
3. 在事件里面寫處理過(guò)程。
4. 拖到aspx頁(yè)面就可以用了。

過(guò)程注意的地方。
1.如果用到j(luò)avascript ,用document.getElementById()來(lái)查找服務(wù)器控件需要在控件名前面加上 "<%= this.ClientID %>_控件名".
2.如果有圖片之類需要路徑的請(qǐng)用:/ a / b / c.jpg
3.需要調(diào)用用戶控件事件的話需要寫一個(gè)委托。
以下面做一個(gè)查詢?yōu)槔?
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" > 請(qǐng)輸入關(guān)鍵字 </ 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" > 發(fā)布時(shí)間 </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="1" > 1天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="2" > 2天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="3" > 3天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="4" > 4天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="5" > 5天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="10" > 10天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="20" > 20天內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="30" > 一個(gè)月內(nèi) </ asp:ListItem >
????????????????????????????????????????
< asp:ListItem? Value ="90" > 三個(gè)月內(nèi) </ 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?的摘要說(shuō)明。
????
/// ? </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? == ? " 請(qǐng)輸入關(guān)鍵字 " ?)
????????????????????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 " ));
????????????}

????????????
// ?在此處放置用戶代碼以初始化頁(yè)面
???????????? 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( " 產(chǎn)品種類 " , " 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?窗體設(shè)計(jì)器生成的代碼

????????
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);
????????????}

????????}

????}

}

如何實(shí)現(xiàn)用戶自己定義控件。


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

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

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 和林格尔县| 旬阳县| 桑植县| 兴海县| 资兴市| 衡水市| 永城市| 扎鲁特旗| 阜阳市| 云南省| 监利县| 库车县| 潞城市| 余干县| 安新县| 左贡县| 海南省| 木兰县| 桓仁| 广州市| 武川县| 德钦县| 扎赉特旗| 尉氏县| 从江县| 双峰县| 大冶市| 九台市| 辰溪县| 巨野县| 湄潭县| 酉阳| 浙江省| 九台市| 河西区| 家居| 二连浩特市| 淮滨县| 江源县| 察哈| 应城市|