页面刷新时如何留住密码框的内容 Page_Load:if (Request["Textbox1"]!null) TextBox1.Attribues["value"]=Request["TextBox1"].Tostring() 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼上大侠:c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx.cs(213): “System.Web.UI.WebControls.TextBox”并不包含对“Attribues”的定义 不会不包含Attributes吧你也可以这样啊TextBox1.text="..."; this.DepartmentID.Attributes.Add("value","123456"); http://expert.csdn.net/Expert/TopicView1.asp?id=2561040使用里面的SafePwdBox 楼上很历害,可是我刚用ASP.NET,还不想使用第三方控件:) Attribues敲错了,是Attributes如loulanlouzhu(桃花潭水深千尺,不及阿勇念你情) 所说 这是原代码namespace Lostinet.Web{ using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; /// <summary> /// SafePwdBox is input box that value not be clear when postback /// </summary> [DefaultEvent("ValueChanged")] [DefaultProperty("Value")] [ValidationProperty("Value")] public class SafePwdBox : WebControl , IPostBackDataHandler { /// <summary> /// char for mask at client /// </summary> static public char MaskChar { get { return '~'; } } /// <summary> /// .ctor /// </summary> public SafePwdBox():base(HtmlTextWriterTag.Input) { } /// <summary> /// get the key for Cache /// </summary> protected string GetCacheKey() { string key=(string)ViewState["ck"]; if(key==null) { key=Guid.NewGuid().GetHashCode().ToString("x"); ViewState["ck"]=key; ViewState.SetItemDirty("ck",true); } return key; } /// <summary> /// CacheTimeout /// </summary> [DefaultValue(30)] public int CacheTimeout { get { return ct; } set { ct=value; } } int ct=30; /// <summary> /// is in design /// </summary> protected bool DesignMode { get { return (Site!=null&&Site.DesignMode)||Context==null||HttpContext.Current==null; } } /// <summary> /// password /// </summary> [DefaultValue("")] [Bindable(true)] public string Value { get { if(DesignMode) { string v=(string)ViewState["v"]; return v==null?"":v; } else { string v=(string)Context.Cache[GetCacheKey()]; return v==null?"":v; } } set { if(DesignMode) { ViewState["v"]=value; } else { Context.Cache.Insert(GetCacheKey(),value,null,DateTime.MaxValue,TimeSpan.FromMinutes(CacheTimeout),System.Web.Caching.CacheItemPriority.NotRemovable,null); } } } static object EventValueChanged=new object(); /// <summary> /// fired when value changed /// </summary> public event EventHandler ValueChanged { add { Events.AddHandler(EventValueChanged,value); } remove { Events.RemoveHandler(EventValueChanged,value); } } /// <summary> /// fire ValueChanged /// </summary> protected virtual void OnValueChanged(EventArgs e) { EventHandler handler=(EventHandler)Events[EventValueChanged]; if(handler!=null) handler(this,e); } /// <summary> /// override to render attributes /// </summary> protected override void AddAttributesToRender(HtmlTextWriter writer) { writer.AddAttribute(HtmlTextWriterAttribute.Name,UniqueID); writer.AddAttribute(HtmlTextWriterAttribute.Type,"password",false); writer.AddAttribute(HtmlTextWriterAttribute.Value,new string(MaskChar,Value.Length),false); base.AddAttributesToRender(writer); } void IPostBackDataHandler.RaisePostDataChangedEvent() { OnValueChanged(EventArgs.Empty); } bool IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection) { char mc=MaskChar; string v=Value; char[] nvs=postCollection[postDataKey].ToCharArray(); for(int i=0;i<v.Length&&i<nvs.Length;i++) { if(nvs[i]==mc) nvs[i]=v[i]; } string nv=new string(nvs); if(v!=nv) { Value=nv; return true; } return false; } }} to loulanlouzhu(桃花潭水深千尺,不及阿勇念你情) c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx.cs(213): “System.Web.UI.WebControls.TextBox”并不包含对“DepartmentID”的定义 to loulanlouzhu(桃花潭水深千尺,不及阿勇念你情) c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx.cs(213): “System.Web.UI.WebControls.TextBox”并不包含对“DepartmentID”的定义---》》晕!!!!!! DepartmentID是你的密码文本框的ID,改 下就好了! 在后台用JS切换表格背景图片的问题 脚本语言 急~~~ 如何让fckeditor实现多媒体功能 定制WSS页面的问题 询问如何接收post出的页面html代码 gridview更新记录问题,在线等!急! 高手之路 再次请求熟悉消息队列(msmq)的进来,谢谢! 运行Duwamish 7.0 例子时遇到的问题 办公系统中怎样显示给用户附件 好怪的问题
c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx.cs(213): “System.Web.UI.WebControls.TextBox”并不包含对“Attribues”的定义
使用里面的SafePwdBox
如loulanlouzhu(桃花潭水深千尺,不及阿勇念你情) 所说
{
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel; /// <summary>
/// SafePwdBox is input box that value not be clear when postback
/// </summary>
[DefaultEvent("ValueChanged")]
[DefaultProperty("Value")]
[ValidationProperty("Value")]
public class SafePwdBox : WebControl , IPostBackDataHandler
{
/// <summary>
/// char for mask at client
/// </summary>
static public char MaskChar
{
get
{
return '~';
}
} /// <summary>
/// .ctor
/// </summary>
public SafePwdBox():base(HtmlTextWriterTag.Input)
{
} /// <summary>
/// get the key for Cache
/// </summary>
protected string GetCacheKey()
{
string key=(string)ViewState["ck"];
if(key==null)
{
key=Guid.NewGuid().GetHashCode().ToString("x");
ViewState["ck"]=key;
ViewState.SetItemDirty("ck",true);
}
return key;
} /// <summary>
/// CacheTimeout
/// </summary>
[DefaultValue(30)]
public int CacheTimeout
{
get
{
return ct;
}
set
{
ct=value;
}
}
int ct=30; /// <summary>
/// is in design
/// </summary>
protected bool DesignMode
{
get
{
return (Site!=null&&Site.DesignMode)||Context==null||HttpContext.Current==null;
}
} /// <summary>
/// password
/// </summary>
[DefaultValue("")]
[Bindable(true)]
public string Value
{
get
{
if(DesignMode)
{
string v=(string)ViewState["v"];
return v==null?"":v;
}
else
{
string v=(string)Context.Cache[GetCacheKey()];
return v==null?"":v;
}
}
set
{
if(DesignMode)
{
ViewState["v"]=value;
}
else
{
Context.Cache.Insert(GetCacheKey(),value,null,DateTime.MaxValue,TimeSpan.FromMinutes(CacheTimeout),System.Web.Caching.CacheItemPriority.NotRemovable,null);
}
}
} static object EventValueChanged=new object(); /// <summary>
/// fired when value changed
/// </summary>
public event EventHandler ValueChanged
{
add
{
Events.AddHandler(EventValueChanged,value);
}
remove
{
Events.RemoveHandler(EventValueChanged,value);
}
} /// <summary>
/// fire ValueChanged
/// </summary>
protected virtual void OnValueChanged(EventArgs e)
{
EventHandler handler=(EventHandler)Events[EventValueChanged];
if(handler!=null)
handler(this,e);
} /// <summary>
/// override to render attributes
/// </summary>
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Name,UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Type,"password",false);
writer.AddAttribute(HtmlTextWriterAttribute.Value,new string(MaskChar,Value.Length),false);
base.AddAttributesToRender(writer);
}
void IPostBackDataHandler.RaisePostDataChangedEvent()
{
OnValueChanged(EventArgs.Empty);
} bool IPostBackDataHandler.LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
{
char mc=MaskChar;
string v=Value;
char[] nvs=postCollection[postDataKey].ToCharArray();
for(int i=0;i<v.Length&&i<nvs.Length;i++)
{
if(nvs[i]==mc)
nvs[i]=v[i];
}
string nv=new string(nvs);
if(v!=nv)
{
Value=nv;
return true;
}
return false;
}
}
}
---》》晕!!!!!!
DepartmentID是你的密码文本框的ID,改 下就好了!