1.当自定义的服务器控件中有复杂属性时,子属性的变更,怎样更新到父属性中,另外父属性初始化时怎么样显示为空?
我的代码如下:既不不能子属性变化,父属性跟着变化,并且附属性初始化时并不为空 显示为XXX.size
public class MyControl: WebControl
{
private Size _size;
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
[NotifyParentProperty (true)]
public Size Size
{
get {
if (_size == null)
{
_size = new Size(0, 0);
}
return _size;
}
set { _size = value; }
} }
[TypeConverter (typeof(ExpandableObjectConverter))]
public class Size
{
private int _width;
private int _height; public Size(int w, int h)
{
_width = w;
_height = h;
} [NotifyParentProperty (true)]
public int Width
{
get { return _width; }
set { _width = value; }
} [NotifyParentProperty (true )]
public int Height
{
get { return _height; }
set { _height = value; }
}
}
2.另外一个问题:比如自定义一个TextBox控件,这个Textbox我使用Input实现的,
我想的是,这样在设计视图中在这个input中输入一些值,这样Textbox的Text属性值也随着变化,就跟Asp.net的效果一样。这个如何实现?
另外这个TextBox具有回调功能,在input的onblur事件中会有回调。怎么样保持input中输入的值(在运行时),我用了viewstate来保存,在RaiseCallbackEvent事件之获得input的输入值,并保存到viewstate,但这不行,每次都会掉,应该是保存的时期没对,但我又不知错出在哪里?希望各位能帮帮忙。public class AjaxTextBox : WebControl , ICallbackEventHandler
{
private string _text;
public string _clientCallBackScript = string.Empty ;
private string returnStr; public string Text
{
get {
return (string)ViewState["_text"];
}
set {
_text = value;
ViewState["_text"] = _text;
}
} public string ClientCallBackScript
{
get { return _clientCallBackScript; }
set { _clientCallBackScript = value; }
}
public override void RenderControl(HtmlTextWriter writer)
{
if (_clientCallBackScript == null)
{
writer.Write("<input type='text' value=\"" + Text + "\"/>");
}
else
{
string callbackScript = Page.ClientScript.GetCallbackEventReference(this, "this.value", _clientCallBackScript, null);
writer.Write("<input type='text' onblur=\"" + callbackScript + "\" value=\"" + Text + "\"/>");
}
base.RenderControl(writer);
} #region ICallbackEventHandler Members string ICallbackEventHandler.GetCallbackResult()
{
return returnStr;
} void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
returnStr = eventArgument; Text = eventArgument; //相当于存入viewstate中
}
#endregion
}
问题有点多,谢谢各位帮帮忙。
我的代码如下:既不不能子属性变化,父属性跟着变化,并且附属性初始化时并不为空 显示为XXX.size
public class MyControl: WebControl
{
private Size _size;
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
[NotifyParentProperty (true)]
public Size Size
{
get {
if (_size == null)
{
_size = new Size(0, 0);
}
return _size;
}
set { _size = value; }
} }
[TypeConverter (typeof(ExpandableObjectConverter))]
public class Size
{
private int _width;
private int _height; public Size(int w, int h)
{
_width = w;
_height = h;
} [NotifyParentProperty (true)]
public int Width
{
get { return _width; }
set { _width = value; }
} [NotifyParentProperty (true )]
public int Height
{
get { return _height; }
set { _height = value; }
}
}
2.另外一个问题:比如自定义一个TextBox控件,这个Textbox我使用Input实现的,
我想的是,这样在设计视图中在这个input中输入一些值,这样Textbox的Text属性值也随着变化,就跟Asp.net的效果一样。这个如何实现?
另外这个TextBox具有回调功能,在input的onblur事件中会有回调。怎么样保持input中输入的值(在运行时),我用了viewstate来保存,在RaiseCallbackEvent事件之获得input的输入值,并保存到viewstate,但这不行,每次都会掉,应该是保存的时期没对,但我又不知错出在哪里?希望各位能帮帮忙。public class AjaxTextBox : WebControl , ICallbackEventHandler
{
private string _text;
public string _clientCallBackScript = string.Empty ;
private string returnStr; public string Text
{
get {
return (string)ViewState["_text"];
}
set {
_text = value;
ViewState["_text"] = _text;
}
} public string ClientCallBackScript
{
get { return _clientCallBackScript; }
set { _clientCallBackScript = value; }
}
public override void RenderControl(HtmlTextWriter writer)
{
if (_clientCallBackScript == null)
{
writer.Write("<input type='text' value=\"" + Text + "\"/>");
}
else
{
string callbackScript = Page.ClientScript.GetCallbackEventReference(this, "this.value", _clientCallBackScript, null);
writer.Write("<input type='text' onblur=\"" + callbackScript + "\" value=\"" + Text + "\"/>");
}
base.RenderControl(writer);
} #region ICallbackEventHandler Members string ICallbackEventHandler.GetCallbackResult()
{
return returnStr;
} void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
returnStr = eventArgument; Text = eventArgument; //相当于存入viewstate中
}
#endregion
}
问题有点多,谢谢各位帮帮忙。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货