模态窗体选择文本控件

系统 1557 0

模态窗体选择文本控件

经常使用摸态窗体,总是需要重复编写javascript脚本.所以封装了这个控件,这个控件使用的是aspnet2.0的API.所以用在1.1上的需要自己修改代码.

控件代码
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--> using System;
using System.ComponentModel;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace DotnetClubPortal.WebControls
{
/**/ /// <summary>
/// 用户选择控件
/// </summary>

[DefaultProperty( " Text " ),
ToolboxData(
" <{0}:SelectObjectrunat=server></{0}:SelectObject> " )]
public class SelectObject:,INamingContainer
{
protected System.Web.UI.HtmlControls.HtmlInputHiddenhiddenObjectId;
protected System.Web.UI.WebControls.TextBoxtxtObjectName;
protected System.Web.UI.WebControls.Buttonbutton;


private HtmlTableuiTable;

public SelectObject()
{
txtObjectName
= new Textbox();
hiddenObjectId
= new HtmlInputHidden();
}


/**/ /// <summary>
/// ID,ID中间使用","分隔
/// </summary>

[Browsable( false ),Category( " 设置 " ),Description( " 取得的对象值,中间使用','分隔 " ),DefaultValue( "" )]
public string ObjectId
{
get
{
return hiddenObjectId.Value;
}

set
{
hiddenObjectId.Value
= value.ToString();
}

}


/**/ /// <summary>
/// 名称,中间使用","分隔
/// </summary>

[Browsable( false ),Category( " 设置 " ),Description( " 对象名称,中间使用','分隔 " ),DefaultValue( "" )]
public string ObjectName
{
get
{
return txtObjectName.Text;
}

set
{
this .txtObjectName.Text = value.ToString();
}

}


[Category(
" 设置 " ),Description( " 选择页面路径 " ),Browsable( true ),NotifyParentProperty( true )]
public string PageUrl
{
get
{
object obj = ViewState[ " PageUrl " ];
return (obj == null ) ? string .Empty:obj.ToString();
}

set
{
ViewState[
" PageUrl " ] = value;
}

}


/**/ /// <summary>
/// 编辑框是否可见
/// </summary>

[Category( " 设置 " ),Description( " 编辑框是否可见 " ),Browsable( true ),DefaultValue( true )]
public bool IsVisable
{
get
{
object obj = ViewState[ " Visable " ];
return (obj == null ) ? false : bool .Parse(obj.ToString());
}

set
{
ViewState[
" Visable " ] = value;
}

}


protected override void Render(HtmlTextWriteroutput)
{
base .Render(output);
Control[]CtrlArray;
CtrlArray
= new Control[ 3 ];
CtrlArray[
0 ] = this .hiddenObjectId;
CtrlArray[
1 ] = this .txtObjectName;
CtrlArray[
2 ] = this .button;
CreateTabeRow(CtrlArray);
}




/**/ /// <summary>
/// 创建行
/// </summary>
/// <paramname="Obj"> 行中包含的控件 </param>

private void CreateTabeRow(Control[]Obj)
{
HtmlTableRowtr
= new HtmlTableRow();
HtmlTableCelltd
= new HtmlTableCell();
foreach (Controlc in Obj)
{
if (c != null )
{
td.Controls.Add(c);
}


}

tr.Cells.Add(td);
uiTable.Rows.Add(tr);
}


protected override void OnPreRender(EventArgse)
{
RegisterClientScriptBlockJavaScript();
base .OnPreRender(e);
}


发出客户端脚本RegisterClientScriptBlockJavaScript() #region 发出客户端脚本RegisterClientScriptBlockJavaScript()
private void RegisterClientScriptBlockJavaScript()
{
// 如果已经注册了脚本则不再注册
if (Page.ClientScript.IsClientScriptBlockRegistered( " SetValue " ))
{
return ;
}

else
{
Page.ClientScript.RegisterClientScriptBlock(
this .GetType(), " SetValue " ,SetValue().ToString());
}


}


public StringBuilderSetValue()
{
StringBuilderbuilder
= new StringBuilder();
builder.Append(
" <scriptlanguage=\ " javascript\ " >\n " );
builder.Append(
" functionSetValue(Url,Name,Id){\n " );
builder.Append(
" varvDialog;\n " );
builder.Append(
" vDialog=window.showModalDialog(Url,window,\ " dialogHeight:500px;dialogWidth:320px;status:no;resizable:yes;scroll:no;\ " );\n " );
builder.Append(
" if(vDialog!=null){ " );
builder.Append(
" if(document.getElementById(Name))document.getElementById(Name).value=vDialog.oSelectName;\n " );
builder.Append(
" if(document.getElementById(Id))document.getElementById(Id).value=vDialog.oSelectNameID;\n " );
builder.Append(
" }}</script>\n " );
return builder;

}


#endregion


protected override void CreateChildControls()
{
uiTable
= new HtmlTable();
uiTable.ID
= " uiTable " ;
uiTable.Width
= " 100% " ;
uiTable.Border
= 0 ;

// txtObjectName=newTextBox();
txtObjectName.ID = " ObjectName " ;
txtObjectName.Visible
= this .IsVisable;

// hiddenObjectId=newHtmlInputHidden();
hiddenObjectId.ID = " ObjectId " ;

this .button = new Button();
this .button.ID = " btnSelect " ;
this .button.Attributes.Add( " width " , " 100 " );
this .button.Text = " 选择 " ;
this .button.Attributes.Add( " onclick " , string .Format( " javascript:SetValue('{0}','{1}','{2}'); " ,PageUrl, this .ClientID + " _ObjectName " , this .ClientID + " _ObjectId " ));
this .button.CausesValidation = false ;

this .Controls.Add(uiTable);
this .Controls.Add(hiddenObjectId);
this .Controls.Add(txtObjectName);
this .Controls.Add(button);
}

}

}


具体使用 :

<cc1:SelectObject ID="PowerFlag" IsVisable="true" PageUrl="../../../../CommonPage/GetGroupInfo.aspx" runat="server">
</cc1:SelectObject>
通过属性ObjectName,ObjectId获取选择返回的值.

原文: http://shanyou.cnblogs.com/archive/2005/12/31/309171.html

模态窗体选择文本控件


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论