如何在asp.net中使用控件状态
发布时间:2020-12-16 07:10:04 所属栏目:asp.Net 来源:网络整理
导读:下面是我在自定义控件中使用控件状态的简单代码, [DefaultProperty("Text")][ToolboxData("{0}:WebCustomControl1 runat=server/{0}:WebCustomControl1")]public class WebCustomControl1 : WebControl{ [Bindable(true)] [Category("Appearance")] [Default
下面是我在自定义控件中使用控件状态的简单代码,
[DefaultProperty("Text")] [ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")] public class WebCustomControl1 : WebControl { [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { return text; } set { text = value; } } private string text; protected override void RenderContents(HtmlTextWriter output) { output.Write(Text); } protected override void OnInit(System.EventArgs e) { base.OnInit(e); Page.RequiresControlState(this); } protected override object SaveControlState() { object baseSate = base.SaveControlState(); return new Pair(baseSate,Text); } protected override void LoadControlState(object savedState) { Pair value = savedState as Pair; text = value.Second; } } 但它似乎不起作用.. SaveControlState和LoadControlState没有触发.有人能帮我吗..? 下面是aspx代码.这是我使用自定义控件的地方. <%@ Page Language="C#" AutoEventWireup="true" EnableViewState="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %> <%@ Register Assembly="WebApplication1" Namespace="WebApplication1" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head>`enter code here` <body> <form id="form1" runat="server"> <div> <cc1:WebCustomControl1 ID="WebCustomControl1_1" runat="server" /> <asp:Button ID="Button1" runat="server" Text="Button" /></div> </form> </body> </html> 解决方法
你已经调用了RequiresControlState
但是你应该调用RegisterRequiresControlState
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 在ASP.NET MVC ContactsManager教程中是否有
- asp.net-mvc-4 – MVC 4 Html.EditorFor无效
- ASP.Net WCF服务的Thread.CurrentPrincipal被联邦(WIF)环境
- 修改FCKEditor实现将图片、文件等保存到数据库
- asp.net-mvc – 是否由Razor支持lambda表达式?
- asp.net-mvc-4 – 如何配置使用Authorize(Roles)属性时会发
- asp.net core高级EF Core2.0数据模型设计创建
- 编辑并在ASP.NET Web项目中继续
- ASP.NET MVC身份验证Cookie未被检索
- Asp.net – 空QueryString参数
推荐文章
站长推荐
- ASP.NET MVC 开源项目Kigg解读(1)
- asp.net-web-api – .Net Web API未找到与请求UR
- asp.net – 为.Net使用HighchartsExport库我得到
- ASP.Net使用DBNULL检查值
- asp.net-mvc-3 – 将整个页面从MVC3 Razor iFram
- asp.net-mvc-3 – 增加ASP.NET MVC 3中的超时值
- ASP.net控件在实现资源时在代码背后找不到
- asp.net – 如何实现跨数据库外键约束?
- asp.net-mvc-3 – SelectList不显示所选项目
- 在asp.net mvc应用程序中从Javascript访问C#变量
热点阅读