62,269
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 注册客户端脚本
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
string strJSPath = base.ResolveUrl(Path.Combine(this.ClientPath, @"Js\RefrenceControl.js"));
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "RefControlJS"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RefControlJS",
"<script type='text/javascript' src='" + strJSPath + "'></script>", false);
}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("id", this.ClientID);
writer.AddAttribute("name", this.UniqueID);
string strClientClickMethod = "ClientRefClick();";
StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\">");
sb.AppendFormat(" window.{0} = new RefrenceControl('{0}');", this.ClientID);
sb.AppendFormat("{0}.BtnElementId = '{1}';", this.ClientID, this.btn.ClientID);
sb.AppendFormat("{0}.TxtElementId = '{1}';", this.ClientID, this.txt.ClientID);
sb.AppendFormat("{0}.HidElementId = '{1}';", this.ClientID, this.hid.ClientID);
sb.AppendFormat("{0}.DataSource = '{1}';", this.ClientID, this.DataSource.ToString());
sb.AppendFormat("{0}.RefPage = '{1}';", this.ClientID, this.RefPage.Replace("\\", "/"));
sb.AppendFormat("{0}.RefWhere = \"{1}\";", this.ClientID, this.RefWhere);
sb.AppendFormat("{0}.ClientClickMethod = \"{1}\";", this.ClientID, strClientClickMethod);
sb.AppendFormat("{0}.ClientAcceptValueMethod = '{1}';", this.ClientID, this.ClientAcceptValueMethod.Trim());
//启动脚本
sb.AppendFormat("window.{0}.Start();", this.ClientID);
sb.Append("</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "Start",
sb.ToString(), false);
if (this.Height != Unit.Empty)
{
writer.AddAttribute("Height", this.Height.ToString());
}
if (this.Width != Unit.Empty)
{
writer.AddAttribute("Width", this.Width.ToString());
}
txt.Width = this.Width;
writer.AddAttribute("cellspacing", "0");
writer.AddAttribute("cellpadding", "0");
writer.AddAttribute("scale", "1");
writer.AddStyleAttribute("display", "inline");
writer.AddStyleAttribute("vertical-align", "middle");
writer.AddStyleAttribute("position", "relative");
if (this.Enabled == false)
{
writer.AddAttribute("disabled", "true");
txt.Attributes.Add("disabled", "true");
}
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
if (this.EnableTextBox == true)
{
txt.ReadOnly = false;
txt.Style.Add("background-color", "#ffffff");
}
else
{
txt.ReadOnly = true;
txt.Style.Add("background-color", "#f4f4f4");
}
txt.Style.Add("Height", "100%");
txt.RenderControl(writer);
string strRefImageUrl = base.ResolveUrl( Path.Combine(this.ClientPath, @"Images\ref.jpg") );
btn.ImageUrl = strRefImageUrl;
btn.Style.Add(HtmlTextWriterStyle.Cursor, "hand");
btn.Style.Add(HtmlTextWriterStyle.Position, "absolute");
btn.Style.Add("right", "1px");
btn.Style.Add("top", "2px");
btn.Style.Add("z-index", "9999");
btn.Style.Add("float", "right");
if (this.EnableButton == false)
{
btn.Attributes.Add("disabled", "true");
}
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
btn.RenderControl(writer);
hid.RenderControl(writer);
writer.RenderEndTag(); //</TD>
writer.RenderEndTag(); //</TR>
writer.RenderEndTag();
}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public enum DataSourceType
{
/// <summary>
/// 往来单位
/// </summary>
Customer,
/// <summary>
/// 部门
/// </summary>
Department
}
/// <summary>
/// 注册客户端脚本
/// </summary>
/// <param name="e"></param>
protected override void OnPreRender(EventArgs e)
{
string strJSPath = base.ResolveUrl(Path.Combine(this.ClientPath, @"Js\RefrenceControl.js"));
if (!Page.ClientScript.IsClientScriptBlockRegistered(this.GetType(), "RefControlJS"))
{
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "RefControlJS",
"<script type='text/javascript' src='" + strJSPath + "'></script>", false);
}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute("id", this.ClientID);
writer.AddAttribute("name", this.UniqueID);
string strClientClickMethod = "ClientRefClick();";
StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\">");
sb.AppendFormat(" window.{0} = new RefrenceControl('{0}');", this.ClientID);
sb.AppendFormat("{0}.BtnElementId = '{1}';", this.ClientID, this.btn.ClientID);
sb.AppendFormat("{0}.TxtElementId = '{1}';", this.ClientID, this.txt.ClientID);
sb.AppendFormat("{0}.HidElementId = '{1}';", this.ClientID, this.hid.ClientID);
sb.AppendFormat("{0}.DataSource = '{1}';", this.ClientID, this.DataSource.ToString());
sb.AppendFormat("{0}.RefPage = '{1}';", this.ClientID, this.RefPage.Replace("\\", "/"));
sb.AppendFormat("{0}.RefWhere = \"{1}\";", this.ClientID, this.RefWhere);
sb.AppendFormat("{0}.ClientClickMethod = \"{1}\";", this.ClientID, strClientClickMethod);
sb.AppendFormat("{0}.ClientAcceptValueMethod = '{1}';", this.ClientID, this.ClientAcceptValueMethod.Trim());
//启动脚本
sb.AppendFormat("window.{0}.Start();", this.ClientID);
sb.Append("</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID + "Start",
sb.ToString(), false);
if (this.Height != Unit.Empty)
{
writer.AddAttribute("Height", this.Height.ToString());
}
if (this.Width != Unit.Empty)
{
writer.AddAttribute("Width", this.Width.ToString());
}
txt.Width = this.Width;
writer.AddAttribute("cellspacing", "0");
writer.AddAttribute("cellpadding", "0");
writer.AddAttribute("scale", "1");
writer.AddStyleAttribute("display", "inline");
writer.AddStyleAttribute("vertical-align", "middle");
writer.AddStyleAttribute("position", "relative");
if (this.Enabled == false)
{
writer.AddAttribute("disabled", "true");
txt.Attributes.Add("disabled", "true");
}
writer.RenderBeginTag(HtmlTextWriterTag.Table);
writer.RenderBeginTag(HtmlTextWriterTag.Tr);
writer.RenderBeginTag(HtmlTextWriterTag.Td);
if (this.EnableTextBox == true)
{
txt.ReadOnly = false;
txt.Style.Add("background-color", "#ffffff");
}
else
{
txt.ReadOnly = true;
txt.Style.Add("background-color", "#f4f4f4");
}
txt.Style.Add("Height", "100%");
txt.RenderControl(writer);
string strRefImageUrl = base.ResolveUrl( Path.Combine(this.ClientPath, @"Images\ref.jpg") );
btn.ImageUrl = strRefImageUrl;
btn.Style.Add(HtmlTextWriterStyle.Cursor, "hand");
btn.Style.Add(HtmlTextWriterStyle.Position, "absolute");
btn.Style.Add("right", "1px");
btn.Style.Add("top", "2px");
btn.Style.Add("z-index", "9999");
btn.Style.Add("float", "right");
if (this.EnableButton == false)
{
btn.Attributes.Add("disabled", "true");
}
writer.RenderEndTag();
writer.RenderBeginTag(HtmlTextWriterTag.Td);
btn.RenderControl(writer);
hid.RenderControl(writer);
writer.RenderEndTag(); //</TD>
writer.RenderEndTag(); //</TR>
writer.RenderEndTag();
}
}
//http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
public enum DataSourceType
{
/// <summary>
/// 往来单位
/// </summary>
Customer,
/// <summary>
/// 部门
/// </summary>
Department
}
namespace KingControls
{
/// <summary>
/// Author: 【夜战鹰】【专注于DotNet技术】【ChengKing(ZhengJian)】
/// 获得本书的更多章节:【http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx】
/// 声明: 【本链接为进阶Asp.net技术的一些文章】【转载时请保留本链接源】
/// </summary>
[DefaultProperty("Text")]
[ValidationProperty("Text")]
[ToolboxData("<{0}:RefrenceControl runat=server></{0}:RefrenceControl>")]
public class RefrenceControl : CompositeControl
{
private Image btn = new Image();
private TextBox txt = new TextBox();
private HiddenField hid = new HiddenField();
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的值")]
public string Value
{
get
{
this.EnsureChildControls();
if (hid.Value == null)
{
return null;
}
return hid.Value;
}
set
{
this.EnsureChildControls();
hid.Value = value;
}
}
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的显示文本")]
[ReadOnly(true)]
public string Text
{
get
{
this.EnsureChildControls();
return txt.Text;
}
set
{
this.EnsureChildControls();
txt.Text = value;
}
}
private DataSourceType dstDataSource = DataSourceType.Customer;
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置控件的数据源")]
[TypeConverter(typeof(EnumConverter))]
public DataSourceType DataSource
{
get
{
return dstDataSource;
}
set
{
dstDataSource = value;
}
}
[Category("参照客户端事件")]
[Description("获取或设置返回值处理客户端函数名")]
public string ClientAcceptValueMethod
{
get
{
string s = (string)ViewState["ClientAcceptValueMethod"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["ClientAcceptValueMethod"] = value;
}
}
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置数据选择页面地址")]
public string RefPage
{
get
{
string s = (string)ViewState["RefPage"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["RefPage"] = value;
}
}
[Bindable(true)]
[Category("参数控件属性")]
[DefaultValue("")]
[Localizable(true)]
[Description("获取或设置过滤条件")]
public string RefWhere
{
get
{
string s = (string)ViewState["RefWhere"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["RefWhere"] = value;
}
}
private bool blnEnableTextBox = true;
[DefaultValue("true")]
[Category("行为控制")]
[Description("获取或设置文本框可用性")]
public bool EnableTextBox
{
get
{
return blnEnableTextBox;
}
set
{
blnEnableTextBox = value;
}
}
private bool blnEnableButton = true;
[DefaultValue("true")]
[Category("行为控制")]
[Description("获取或设置参照控件按钮的可用性")]
public bool EnableButton
{
get
{
return blnEnableButton;
}
set
{
blnEnableButton = value;
}
}
/// <summary>
/// 设置或获取资源文件夹目录
/// </summary>
[Bindable(true)]
[Category("客户端路径")]
[DefaultValue("")]
[Localizable(true)]
[Description("资源(image/css/js)的客户端根目录")]
public string ClientPath
{
get
{
string s = (string)ViewState["ClientPath"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["ClientPath"] = value;
}
}
public RefrenceControl()
{
this.Width = Unit.Pixel(100);
this.ViewState["RefPage"] = @".\RefPage.aspx";
this.ViewState["ClientPath"] = @".\";
}
protected override void CreateChildControls()
{
hid.ID = "id";
btn.ID = "btn";
txt.ID = "txt";
this.Controls.Add(hid);
this.Controls.Add(txt);
this.Controls.Add(btn);
}
page1
function Edit()
{
GetItems();
if(arr.length == 1)
{//returnValue 为弹出页面返回值
var returnValue = window.showModalDialog("AddOtherPeopleInfo.aspx?iCustomerID=" + arr[0] + "|" +Form1.txtCustomerID.value, "window", "dialogWidth:950px;dialogHeight:600px;fullscreen:yes;status:no;resizable:no;help:no");
if(returnValue == "1")
{
document.location.reload();
}
}
else
{
if(arr.length == 0)
{
alert("请选择人员后再更新!");
}
else
{
alert("选择条目过多,请重新选择修改项!");
}
}
}
page2
//更新
function Update()
{
var value = checkContent();
if(value)
{
getTerm();
arr.push(Form1.txtCustomerID.value);
var strError = huiyuan.AddOtherPeopleInfo.Update(arr).value;
if(strError == "")
{
alert("更新成功");
window.returnValue = "1";//此处返回值给主窗体
window.close();
}
else
{
alert(strError);
}
}
}