__dopostback无法使用代码C#.NET

时间:2014-06-07 01:51:55

标签: c# asp.net

我有这样的转发器:

<telerik:RadAjaxPanel ID="RadAjaxPanel1"  runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
<asp:Repeater ID="rptstudent" runat="server">
   <HeaderTemplate>
      <table id="table1">
         <tr class="repeater_bg">
             <th width="40px">order</th>
             <th width="300px">Name</th>
             <th width="300px">Card</th>
        </tr>
  </HeaderTemplate>
  <ItemTemplate>
        <tr class="repeater_item">
            <td align="center">
                <%# Container.ItemIndex + 1 %>
            </td>
            <td align="center">
                <asp:HiddenField ID="Id" Value='<%# Eval("IdStudent") %>' runat="server" />
                <%# Eval("Name") %>
            </td>
             <td align="center">
                <%# Eval("IdStudent") %>
            </td>
        </tr>
  </ItemTemplate>
  <FooterTemplate>
        </table>
  </FooterTemplate>
</asp:Repeater>
<asp:Label ID="lblPagination" CssClass="pagination" runat="server" Visible="false"></asp:Label>
</telerik:RadAjaxPanel>

查看源代码:

order     name                                         Card
1         Alex (hidden field value is idstudent=1)     1
2         Alex2 (hidden field value is idstudent=2)    2
3         Alex3 (hidden field value is idstudent=3)    4
4         Alex4 (hidden field value is idstudent=4)    3
5         Alex5 (hidden field value is idstudent=5)    5

                             first page 1 2 3 4 last page

和一个用于分页的标签(使用后面的代码绑定值),所有这些都嵌套了rad ajax面板。 现在,当我点击链接转到第2页

<ul>
<li><a href="javascript:__doPostBack('page0','0')">First Page</a></li>
<li><a id="page1" href="javascript:__doPostBack('page1','1')">1</a></li>
<li><a id="page2" href="javascript:__doPostBack('page2','2')">2</a></li>
<li><a style="font-size:8pt;" href="javascript:__doPostBack('page2','2')">Last Page</a></li>
</ul>

正常工作,数据传输到第二页。但是当我看到页面的源代码时,转发器中的隐藏字段不会重新加载数据。卡和名称是核心 查看源代码:

order     name                                                             Card
6         Alex6 (hidden field value remains constant =1, must be 6)         6
7         Alex7 (hidden field value remains constant =2, must be 7)         7
8         Alex8 (hidden field value remains constant =3, must be 8)         8
9         Alex8 (hidden field value remains constant =4, must be 9)         9
10        Alex8 (hidden field value remains constant =5, must be 10)        10
                                                         first page 1 2 3 4 last page

背后的代码

if (!IsPostBack)
{

}
else
{
// when you click a link, it's called event __dopostback
   string postBackControlName = Request.Params.Get("__EVENTTARGET");
   string eventArgument = Request.Params.Get("__EVENTARGUMENT");
   if (postBackControlName == "page"+eventArgument)
   {
      LoadData(int.Parse(eventArgument));
   }
}

为什么会发生这种情况,有什么方法可以解决这个问题。

感谢提前 Sory关于我的英语!

1 个答案:

答案 0 :(得分:0)

尝试以下

if (!isPostBack)
{
    //do something
}

else if (Request.Form["__EVENTTARGET"].ToLower().IndexOf("myevent") >= 0)
{
    //call appropriate function.
}

检查您是否以这种方式接听电话