http://odetocode.com/Blogs/scott/archive/2006/03/21/3153.aspx
http://odetocode.com/Blogs/scott/archive/2006/03/20/3145.aspx
http://recordsome.blogsome.com/2006/05/30
问题描述: EnableEventValidation="true"
Event validation is a feature designed to help prevent injection attacks (of course it can't prevent attacks all by itself).
如果我们往服务器端生成的代码加入了客户端生成的数据,如果参考页面中提出的,下拉菜单的问题。
这样会提示出错信息
我是在做GridView的分页时,出现的问题。我把代码贴出来,大家看看。
<
asp:GridView
ID
="gvDB"
runat
="server"
CssSelectorClass
="PrettyGridView"
SkinID
="GridView"
OnPageIndexChanging ="gvDB_PageIndexChanging" > //这里用到一个CSS适配器
< EmptyDataTemplate >
< div align ="center" >
没有相关资源
</
div
>
</ EmptyDataTemplate >
< Columns >
< asp:TemplateField HeaderText ="状态" ItemStyle-Width ="35px" >
< ItemTemplate >
<% # CheckUserRight( Eval ( " RS_ID " ).ToString()) %>
</ ItemTemplate >
< ItemStyle BorderColor ="#BFCCE1" HorizontalAlign ="Center" Width ="30px" />
</ asp:TemplateField >
< asp:TemplateField HeaderText ="资源名称" >
< ItemTemplate >
< a target ="_blank" href ="SingleSearch.aspx?rsid=<%# Eval(" RS_ID")% > " title=" <% #DataBinder.Eval(Container.DataItem, " RS_Intro " ) %> ">
<% #DataBinder.Eval(Container.DataItem, " RS_Name " ) %> </ a >
</ ItemTemplate >
< ItemStyle BorderColor ="#BFCCE1" />
</ asp:TemplateField >
</ Columns >
</ asp:GridView >
OnPageIndexChanging ="gvDB_PageIndexChanging" > //这里用到一个CSS适配器
< EmptyDataTemplate >
< div align ="center" >
没有相关资源
![dot.gif](https://www.cnblogs.com/Images/dot.gif)
</ EmptyDataTemplate >
< Columns >
< asp:TemplateField HeaderText ="状态" ItemStyle-Width ="35px" >
< ItemTemplate >
<% # CheckUserRight( Eval ( " RS_ID " ).ToString()) %>
</ ItemTemplate >
< ItemStyle BorderColor ="#BFCCE1" HorizontalAlign ="Center" Width ="30px" />
</ asp:TemplateField >
< asp:TemplateField HeaderText ="资源名称" >
< ItemTemplate >
< a target ="_blank" href ="SingleSearch.aspx?rsid=<%# Eval(" RS_ID")% > " title=" <% #DataBinder.Eval(Container.DataItem, " RS_Intro " ) %> ">
<% #DataBinder.Eval(Container.DataItem, " RS_Name " ) %> </ a >
</ ItemTemplate >
< ItemStyle BorderColor ="#BFCCE1" />
</ asp:TemplateField >
</ Columns >
</ asp:GridView >
这是.SKIN文件下的设置
<
asp:GridView
SkinID
="GridView"
Runat
="server"
CellPadding ="3"
GridLines ="None"
BorderStyle ="solid"
BorderWidth ="2px"
BorderColor ="#465239"
PagerSettings-Mode ="NextPreviousFirstLast"
AllowPaging ="True"
PageSize ="12"
Width ="100%"
AutoGenerateColumns ="False" >
< PagerSettings PreviousPageImageUrl ="~/images/resBrowser/button_previous.gif" NextPageImageUrl ="~/images/resBrowser/button_next.gif"
FirstPageImageUrl ="~/images/resBrowser/button_first.gif" LastPageImageUrl ="~/images/resBrowser/button_last.gif"
FirstPageText ="第一页" LastPageText ="最后一页" Mode ="NextPreviousFirstLast"
NextPageText ="下一页" PreviousPageText ="前一页" />
< PagerStyle HorizontalAlign ="Right" BackColor ="#F9FAFD" ForeColor ="#0099FF" Height ="10px"
BorderStyle ="Solid" BorderWidth ="1px" BorderColor ="#BFCEE1" />
</ asp:GridView >
CellPadding ="3"
GridLines ="None"
BorderStyle ="solid"
BorderWidth ="2px"
BorderColor ="#465239"
PagerSettings-Mode ="NextPreviousFirstLast"
AllowPaging ="True"
PageSize ="12"
Width ="100%"
AutoGenerateColumns ="False" >
< PagerSettings PreviousPageImageUrl ="~/images/resBrowser/button_previous.gif" NextPageImageUrl ="~/images/resBrowser/button_next.gif"
FirstPageImageUrl ="~/images/resBrowser/button_first.gif" LastPageImageUrl ="~/images/resBrowser/button_last.gif"
FirstPageText ="第一页" LastPageText ="最后一页" Mode ="NextPreviousFirstLast"
NextPageText ="下一页" PreviousPageText ="前一页" />
< PagerStyle HorizontalAlign ="Right" BackColor ="#F9FAFD" ForeColor ="#0099FF" Height ="10px"
BorderStyle ="Solid" BorderWidth ="1px" BorderColor ="#BFCEE1" />
</ asp:GridView >
这是加到GridView后面的分页代码
<
div
style
="text-align: center; font-size:small;"
>
<% if (lblcurPage.Text ! = " 1 " )
{
%>
< input type ="image" src ="../images/resBrowser/button_first.gif" alt ="首页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$First')" />
< input type ="image" src ="../images/resBrowser/button_previous.gif" alt ="前一页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Prev')" />
<% } %>
第 < asp:Label ID ="lblcurPage" runat ="server" Text ='' ></ asp:Label > 页/共 < asp:Label
ID ="lblPageCount" runat ="server" Text ='' ></ asp:Label > 页
<% if (lblcurPage.Text ! = lblPageCount.Text)
{
%>
< input type ="image" src ="../images/resBrowser/button_next.gif" alt ="后一页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Next')" />
< input type ="image" src ="../images/resBrowser/button_last.gif" alt ="尾页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Last')" />
<% } %>
跳转到第 < asp:textbox id ="txtNewPageIndex" runat ="server" width ="20px" text ='<%=gvDB.PageIndex+1 % > ' />页
< a href ="#" onclick ="GoToPage()" > 跳转 </ a >
</ div >
<% if (lblcurPage.Text ! = " 1 " )
{
%>
< input type ="image" src ="../images/resBrowser/button_first.gif" alt ="首页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$First')" />
< input type ="image" src ="../images/resBrowser/button_previous.gif" alt ="前一页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Prev')" />
<% } %>
第 < asp:Label ID ="lblcurPage" runat ="server" Text ='' ></ asp:Label > 页/共 < asp:Label
ID ="lblPageCount" runat ="server" Text ='' ></ asp:Label > 页
<% if (lblcurPage.Text ! = lblPageCount.Text)
{
%>
< input type ="image" src ="../images/resBrowser/button_next.gif" alt ="后一页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Next')" />
< input type ="image" src ="../images/resBrowser/button_last.gif" alt ="尾页"
onclick ="javascript:__doPostBack('ctl00$MainContent$gvDB','Page$Last')" />
<% } %>
跳转到第 < asp:textbox id ="txtNewPageIndex" runat ="server" width ="20px" text ='<%=gvDB.PageIndex+1 % > ' />页
< a href ="#" onclick ="GoToPage()" > 跳转 </ a >
</ div >
//javascript代码
function GoToPage()
{
var curPage=$get('ctl00_MainContent_lblcurPage').innerHTML;
var newPage=$get('ctl00_MainContent_txtNewPageIndex').value;
if(curPage==newPage)
{
return;
}
__doPostBack('ctl00$MainContent$gvDB','Page$First');
}
function GoToPage()
{
var curPage=$get('ctl00_MainContent_lblcurPage').innerHTML;
var newPage=$get('ctl00_MainContent_txtNewPageIndex').value;
if(curPage==newPage)
{
return;
}
__doPostBack('ctl00$MainContent$gvDB','Page$First');
}
解决方案:
在.CS页面中加了一个事件注册处理:
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(gvDB.UniqueID, "Page$First");
base.Render(writer);
}
关于分页的做法,网上有很多做法。
我的任务是在原来的基础上加上分页的功能,这次改动不算太多。
欢迎大家讨论。