gpt4 book ai didi

c# - 单击超链接会导致更新面板执行完整回发?

转载 作者:太空宇宙 更新时间:2023-11-03 11:13:13 25 4
gpt4 key购买 nike

当我只是尝试进行部分回发时,更新面板会进行完整的回发。我只想在单击超链接上一页和下一页时能够更新 Repeater 而不是更新整个页面。

   protected void Page_Load(object sender, EventArgs e)
{
PagedDataSource objpd = new PagedDataSource();

string connStr = ConfigurationManager.ConnectionStrings["yafnet"].ConnectionString;
SqlConnection mySQLconnection = new SqlConnection(connStr);
if (mySQLconnection.State == ConnectionState.Closed)
{
mySQLconnection.Open();
}

SqlCommand mySqlSelect = new SqlCommand("SELECT * FROM [Comments]", mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataTable table = new DataTable();
mySqlAdapter.Fill(table);


objpd.DataSource = table.DefaultView;
objpd.AllowPaging = true;
objpd.PageSize = 1;

int currentPage;

if (Request.QueryString["page"] != null)
{
currentPage = Int32.Parse(Request.QueryString["page"]);
}
else
{
currentPage = 1;
}

objpd.CurrentPageIndex = currentPage - 1;
// Label1.Text = "Page " + currentPage + " of " + pds.PageCount;

if (!objpd.IsFirstPage)
{
linkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage - 1);



}

if (!objpd.IsLastPage)
{
linkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + (currentPage + 1);



}

Repeater1.DataSource = objpd;
Repeater1.DataBind();

}

这是我的HTML

<div class="comment">

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">

<ContentTemplate>
<asp:Repeater ID="Repeater1" runat="server">

<HeaderTemplate>
<table class="commentsx" cellspacing="0">
</HeaderTemplate>

<ItemTemplate>

<tr>
<td class="name">
<div class="right">
<%# Eval("CommentUserName") %>
</div>
<div class="left">
<%# Eval("CommentDateTime") %>
</div>
</td>


</tr>
<tr>
<td>
<div class="mess">
<%# Eval("CommentMessage") %>
</div>
</td>
</tr>


</ItemTemplate>


<FooterTemplate>
</table>
</FooterTemplate>


</asp:Repeater>

<asp:HyperLink ID="linkPrev" runat="server">Previous Page</asp:HyperLink>
<asp:HyperLink ID="linkNext" runat="server">Next Page</asp:HyperLink>
</ContentTemplate>



<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="DataBinding" />
</Triggers>



</asp:UpdatePanel>

</div>

最佳答案

Hyperlink 控件根本不执行回发,它们评估将执行 GET 而不是 POST 的常规链接。

既然您想要的东西看起来像一个链接,但执行回发而不是 GET,您需要的是 LinkBut​​ton。它看起来像一个链接,但实际上像一个按钮并执行回发。

关于c# - 单击超链接会导致更新面板执行完整回发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13366429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com