日期:2014-05-17  浏览次数:20420 次

ascx里面的textbox取不到值怎么办?
各位大侠,我有一个aspx,里面放了一个自定义的分页控件,ascx格式的。
该ascx里面有上一页,下一页和跳转,跳转就是一个textbox输入页码,点击按钮转向。
问题是,不管输入什么,点跳转后,在ascx的page_load都取不到textbox的值,这是为啥?

这是ascx的前台代码:
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="FoxPager.ascx.cs" Inherits="FoxSite.Page.FoxPager" %>
<asp:LinkButton ID="lbtnFirstPage" runat="server" CssClass="lbtnCommon" OnCommand="PagerButton_Click"
CommandName="FirstPage" resourcekey="FirstPage" CausesValidation="False">首页</asp:LinkButton>
<asp:LinkButton ID="lbtnPreviousPage" runat="server" CssClass="lbtnCommon" OnCommand="PagerButton_Click"
CommandName="PreviousPage" resourcekey="PreviousPage" CausesValidation="False">上一页</asp:LinkButton>
<asp:LinkButton ID="lbtnNextPage" runat="server" CssClass="lbtnCommon" OnCommand="PagerButton_Click"
CommandName="NextPage" resourcekey="NextPage" CausesValidation="False">下一页</asp:LinkButton>
<asp:LinkButton ID="lbtnLastPage" runat="server" CssClass="lbtnCommon" OnCommand="PagerButton_Click"
CommandName="LastPage" resourcekey="LastPage" CausesValidation="False">尾页</asp:LinkButton>
<asp:TextBox ID="txtPageNum" runat="server" Width="41px"></asp:TextBox>
<asp:CompareValidator ID="cmpValPageNum" CssClass="NormalRed" runat="server" ControlToValidate="txtPageNum"
Display="Dynamic" ErrorMessage=">0" Operator="GreaterThan" Type="Integer" ValidationGroup="InfoPager"
ValueToCompare="0"></asp:CompareValidator><asp:RequiredFieldValidator ID="reqValPageNum" runat="server" CssClass="NormalRed" ControlToValidate="txtPageNum"
Display="Dynamic" ErrorMessage="*" ValidationGroup="InfoPager"></asp:RequiredFieldValidator>
<asp:LinkButton ID="lbtnGoto" runat="server" CssClass="lbtnCommon" OnCommand="PagerButton_Click"
CommandName="Go" resourcekey="Go" ValidationGroup="InfoPager">跳转</asp:LinkButton>
<asp:Label ID="lblPageInfo" runat="server" Text=""></asp:Label>

这是后台cs代码,page_load和点击事件的
protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
  ViewState["PageCount"] = PageCount;
  ViewState["PageIndex"] = PageIndex;
  RefreshPager(PageIndex, PageSize, DataCount, PageCount);
  }
  }
  protected void PagerButton_Click(object sender, CommandEventArgs e)
  {
  int OldPageIndex = this.PageIndex;
  switch (e.CommandName)
  {
  case "FirstPage":
  NewIndex = 1;
  break;
  case "PreviousPage":
  NewIndex = PageIndex - 1;
  break;
  case "NextPage":
  NewIndex = PageIndex + 1;
  break;
  case "LastPage":
  NewIndex = Int32.Parse(ViewState["PageCount"].ToString());