我写的服务器控件(未完,模型如此)

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls; namespace DecColorPicker
{
[DefaultProperty("DecColorPickerControl")]
[ToolboxData("<{0}:DecColorPickerControl runat=server></{0}:DecColorPickerControl>")]
public class DecColorPickerControl : WebControl, IPostBackDataHandler
{ public string ColorValue
{
get
{
string viewstr = this.ID + "_ColorValue";
object text = ViewState[viewstr];
if (text == null)
return string.Empty;
else
return (string)text;
}
set
{
string viewstr = this.ID + "_ColorValue";
ViewState[viewstr] = value;
}
} public string DivContranerID
{
get
{
string viewstr = this.ID + "_DivContranerID";
String s = (String)ViewState[viewstr];
return ((s == null) ? this.ID + "DecTextBox" : s);
} set
{
string viewstr = this.ID + "_DivContranerID";
ViewState[viewstr] = value;
}
} public string PickerBtnID
{
get
{
string viewstr = this.ID + "_PickerBtnID";
String s = (String)ViewState[viewstr];
return ((s == null) ? this.ID + "_PickerBtn" : s);
} set
{
string viewstr = this.ID + "_PickerBtnID";
ViewState[viewstr] = value;
}
} [Description("设置按钮的文本")]
public string PickerBtnText
{
get
{
string viewstr = this.ID + "_PickerBtnText";
String s = (String)ViewState[viewstr];
return ((s == null) ? "选择颜色" : s);
} set
{
string viewstr = this.ID + "_PickerBtnText";
ViewState[viewstr] = value;
}
} [Description("是否显示按钮")]
public bool ShowPickerBtn
{
get
{
string viewstr = this.ID + "_ShowPickerBtn";
var s = ViewState[viewstr];
return s == null ? true : (Convert.ToBoolean(s));
} set
{
string viewstr = this.ID + "_ShowPickerBtn";
ViewState[viewstr] = value;
}
} #region 选择器配置 [Bindable(false), DefaultValue(""), Browsable(true), Description("颜色选择器的宽度"), Category("选择器设置")]
public string PickerWidth
{
get
{
string viewstr = this.ID + "_PickerWidth";
String s = (String)ViewState[viewstr];
return ((s == null) ? "" : s);
}
set
{
string viewstr = this.ID + "_PickerWidth";
ViewState[viewstr] = value;
}
}
[Bindable(false), DefaultValue(""), Browsable(true), Description("颜色选择器的高度"), Category("选择器设置")]
public string PickerHeight
{
get
{
string viewstr = this.ID + "_PickerHeight";
String s = (String)ViewState[viewstr];
return ((s == null) ? "" : s);
}
set
{
string viewstr = this.ID + "_PickerHeight";
ViewState[viewstr] = value;
}
} #endregion public string Text
{
get
{
object text = ViewState["Text"];
if (text == null)
return string.Empty;
else
return (string)text;
}
set
{
ViewState["Text"] = value;
}
}
public event EventHandler TextChanged; protected void OnTextChanged(EventArgs e)
{
if (TextChanged != null)
TextChanged(this, e);
} public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string postedData = postCollection[postDataKey];//回发回来的字符串 if (!this.ColorValue.Equals(postedData))
{
this.ColorValue = postedData;
return true;
}
else
{
return false;
}
} public void RaisePostDataChangedEvent()
{
OnTextChanged(EventArgs.Empty);
}
protected override void Render(HtmlTextWriter writer)
{
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<div id=\"{0}\">", this.DivContranerID);
sb.AppendFormat("<script>{0}</script>", DecColorPicker.Properties.Resources.colorPicker);
//注意此处必须为UniqueID 原因是与LoadPostData的postDataKey 一一对应 lcc
sb.AppendFormat("<input type='text' onclick='colorPicker(event)' id='{0}' name='{0}' />", this.UniqueID);
if (this.ShowPickerBtn)
{
sb.AppendFormat("<input type=\"button\" value=\"{0}\" onclick=\"document.getElementById('{1}').click();\">", this.PickerBtnText, this.UniqueID); }
sb.Append("</div>");
writer.Write(sb.ToString()); }
}
}

注意:
sb.AppendFormat("<input type='text' onclick='colorPicker(event)' id='{0}' name='{0}' />", this.UniqueID);

这个textbox的ID必须为UniqueID,如果填写别的ID将无法进行PostData的回发绑定。

此问题我纠结了很久。才发现的。。。。

服务器控件数据回发实现IPostBackDataHandler需注意的的更多相关文章

  1. 在 ASP.NET 网页中不经过回发而以编程方式实现客户端回调

    在 ASP.NET 网页的默认模型中,用户会与页交互,单击按钮或执行导致回发的一些其他操作.此时将重新创建页及其控件,并在服务器上运行页代码,且新版本的页被呈现到浏览器.但是,在有些情况下,需要从客户 ...

  2. 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。

    问题补充: “/Source”应用程序中的服务器错误. 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或 ...

  3. asp.net 回发或回调参数无效的各种情况分析及解决办法

    昨天,在实现级联菜单的时候,突然出现一下错误: 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中 ...

  4. 点击datalist中Button按钮出现“回发或回调参数无效......”

        遇到问题: 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page ...

  5. FineUIMvc随笔 - 不能忘却的回发(__doPostBack)

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户反馈 有网友在官方论坛抛出了这么一个问题,似乎对 FineUIMvc 中的浏览器端与服务器端的交互方式很有异议. 这里面的关 ...

  6. 转:运行page页面时的事件执行顺序及页面的回发与否深度了解

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  7. FineUIMvc随笔(3)不能忘却的回发(__doPostBack)

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 用户反馈 有网友在官方论坛抛出了这么一个问题,似乎对 FineUIMvc 中的浏览器端与服务器端的交互方式很有异议. 这里面的关 ...

  8. System.ArgumentException: 回发或回调参数无效。在配置中使用 < pages enableEventValidation="true"/>

    转载自http://blog.csdn.net/dongge825/article/details/7868151 关于在同一个页面中使用Gridview控件的时候发现气updaeting事件无法被服 ...

  9. 回发或回调参数无效。在配置中使用 pages enableEventValidation=true 或在页面中使用 %@ Page EnableEventValidation=true % 启用了事件验证

    WebForm中回发或回调参数无效问题的解决 解决 .NET中回发或回调参数无效问题的解 该错误的详细提示信息为: 回发或回调参数无效.在配置中使用 <pages enableEventVali ...

随机推荐

  1. Intent使用方法

    显示Intent 通过构造函数的重载,创建Intent对象,并用startActivity()启动目标活动. 目标活动需要在AndroidManifest.xml中注册 ...... Intent i ...

  2. UiAutomator viewer 在tools下启动、资源jar包在platforms下(如android22)

    1.UiAutomator viewer 在tools下启动. 2.资源jar包在platforms下(如android22):android.jar/ uiautomator.jar

  3. 1107 Social Clusters

    题意:给出n个人(编号为1~n)以及每个人的若干个爱好,把有一个或多个共同爱好的人归为一个集合,问共有多少个集合,每个集合里有多少个人? 思路:典型的并查集题目.并查集的模板init()函数,unio ...

  4. Unity Shader入门精要读书笔记(三)Shader必须的数学基础

    Xyz三维坐标系如下:左手坐标系 但是摄像机观察空间则是采用右手系: 右手法则判断叉乘的结果的方向: 正交矩阵(单位互相垂直的基矢量构成正交矩阵)具有逆与转置一致性: 列矩阵运算CBAv和行矩阵的运算 ...

  5. linux lcd设备驱动剖析一

    s3c2440 lcd驱动源码文件是:drivers/video/s3c2410fb.c 看驱动源码首先当然是先看入口函数,这里是s3c2410fb_init函数 [cpp] view plain? ...

  6. C++获取Lua全局变量和执行Lua多参数多返回值函数

    C++代码: // LuaAndC.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #i ...

  7. VMware虚拟机上网络连接模式bridged(桥接模式)

    VMware虚拟机上网络连接模式bridged(桥接模式)的实质就是虚拟机本身利用主机的网卡对外直接作为一个真实的物理主机存在. 也就是理论上此时的虚拟机和主机没什么关系,只是和主机公用了一块网卡,其 ...

  8. oracle下载地址

    12c 下载地址 http://www.oracle.com/technetwork/cn/database/enterprise-edition/downloads/index.html

  9. python' s fifth day for me dict

    字典 dict : key--vlaue 储存大量的数据,而且是关系型数据,查询速度快(二分查询) 数据类型分类: 可变数据类型(不可哈希):list(列表) , dict(字典), set(集合) ...

  10. Spring Cloud Feign 1(声明式服务调用Feign 简介)

    Spring Cloud Feign基于Netflix Feign 同时整合了Spring Cloud Ribbon和Spring Cloud Hytrix,除了提供两者的强大功能外,它还提供了一种声 ...