问题描述
在我的网页上,我使用< asp:label>填充页面标题。它运行良好,但在我的网格视图中,用户点击第一个 - 上一个 - 下一个 - 最后一个,标签不断添加页面标题一遍又一遍
LABEL
< asp:Label ID =Label2runat =serverText =问题与CssClass =lblTitle>< / asp:Label>
在页面加载中作为示例显示:问题与所有问题相关
单击分页方向时:
首次点击返回:问题所有相关问题所有问题
第二次点击返回:问题相关所有问题所有问题所有问题
每次点击它都会发生这种情况。页面刷新时保持不变。只有重置为应显示的文本的方法(问题与所有问题相关)是单击加载页面的链接。
我以为这可能会触及使用IsPostBack,但这也不起作用。
我尝试过:
mainForum.aspx.vb
On my pages I am using a <asp:label> to populate the page title. It works good, but when in my grid view a user clicks First - Previous - Next - Last, the label keeps adding the page title over and over
LABEL
<asp:Label ID="Label2" runat="server" Text="Question's Related To " CssClass="lblTitle"></asp:Label>
On page load as an example shows: Question's Related To All Questions
When paging direction is clicked:
First click returns: Question's Related To All Questions All Questions
Second click returns: Question's Related To All Questions All Questions All Questions
Each time it is clicked this happens. When the page is refreshed it stays the same. Only way to reset to the text the should display (Question's Related To All Questions) is to click the link that loads the page.
I was thinking that this might deal with using IsPostBack, but that is not working either.
What I have tried:
mainForum.aspx.vb
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.QueryString("cat") <> Nothing Then
ForumDataSource.FilterExpression = "Category='" & Request.QueryString("cat") & "'"
Label2.Text &= " " & Request.QueryString("cat")
Else
Label2.Text &= " All Questions"
End If
If Not IsPostBack Then
' Validate initially to force the asterisks
' to appear before the first roundtrip.
Validate()
End If
End Sub
mainForum .aspx
mainForum.aspx
<asp:GridView ID="GridView1" runat="server" BorderWidth="0" Width="100%" AllowPaging="True" AllowSorting="True" PageIndex="4" PageSize="30" AutoGenerateColumns="False" DataKeyNames="QID" DataSourceID="ForumDataSource" EnableModelValidation="True">
<RowStyle BackColor="#dde8ed" />
<AlternatingRowStyle BackColor="#beced5" />
<PagerSettings PageButtonCount="4" Mode="NextPreviousFirstLast" Position="TopAndBottom" FirstPageText="First " PreviousPageText=" Previous " NextPageText=" Next " LastPageText=" End" />
<PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#233f5e" Font-Underline="false" ForeColor="#c7d1e0" Font-Names="Arial" Font-Size="9pt" Font-Bold="true" Width="100%" Height="22px" />
<EmptyDataTemplate>
Now Questions were found
</EmptyDataTemplate>
<FooterStyle CssClass="gridbg" />
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="Category" DataNavigateUrlFormatString="mainForum.aspx?cat={0}" DataTextField="Category" HeaderText="Category" NavigateUrl="mainForum.aspx?cat=" SortExpression="Category" Text="Category" >
<HeaderStyle BackColor="#5B6776" Font-Names="Arial" Font-Size="9pt" ForeColor="#C7DEE9" HorizontalAlign="Center" VerticalAlign="Middle" Width="17%" />
<ItemStyle Font-Names="Arial" Font-Size="8pt" ForeColor="#022638" HorizontalAlign="Left" VerticalAlign="Middle" Width="17%" Height="20px" CssClass="ingrid" />
</asp:HyperLinkField>
<asp:HyperLinkField DataNavigateUrlFields="QID" DataNavigateUrlFormatString="AnswerList.aspx?qid={0}" DataTextField="Question" HeaderText="Question(s) Asked" NavigateUrl="AnswerList.aspx?qid=" SortExpression="Question" Text="Question" >
<HeaderStyle BackColor="#5B6776" Font-Names="Arial" Font-Size="9pt" ForeColor="#C7DEE9" HorizontalAlign="Center" VerticalAlign="Middle" Width="56%" />
<ItemStyle Font-Names="Arial" Font-Size="8pt" ForeColor="#022638" HorizontalAlign="Left" VerticalAlign="Middle" Width="56%" Height="20px" CssClass="ingrid" />
</asp:HyperLinkField>
<asp:HyperLinkField DataNavigateUrlFields="PostedBy" DataNavigateUrlFormatString="Profile.aspx?mem={0}" DataTextField="PostedBy" HeaderText="Posted By" NavigateUrl="Profile.aspx?mem=" SortExpression="PostedBy">
<HeaderStyle BackColor="#5B6776" Font-Names="Arial" Font-Size="9pt" ForeColor="#C7DEE9" HorizontalAlign="Center" VerticalAlign="Middle" Width="17%" />
<ItemStyle Font-Names="Arial" Font-Size="8pt" ForeColor="#022638" HorizontalAlign="Left" VerticalAlign="Middle" Width="15%" Height="20px" CssClass="ingrid" />
</asp:HyperLinkField>
<asp:BoundField DataField="PostedDate" HeaderText="Post Date" DataFormatString="{0}" SortExpression="PostedDate" >
<HeaderStyle BackColor="#5B6776" Font-Names="Arial" Font-Size="9pt" ForeColor="#C7DEE9" HorizontalAlign="Center" VerticalAlign="Middle" Width="12%" />
<ItemStyle Font-Names="Arial" Font-Size="8pt" ForeColor="#022638" HorizontalAlign="Center" VerticalAlign="Middle" Width="12%" Height="20px" />
</asp:BoundField>
</Columns>
</asp:GridView>
推荐答案
If Not IsPostBack Then
' Validate initially to force the asterisks
' to appear before the first roundtrip.
Label2.Text &= " " & Request.QueryString("cat")
' OR
Label2.Text &= " All Questions"
Validate()
End If
Label2.Text &= " All Questions"
对此:
To this:
If Not String.IsNullOrEmpty(Label2.Text) And Label2.Text <> "All Questions" Then
Label2.Text &= " All Questions"
Else
Label2.Text = "All Questions"
End If
这篇关于停止ASP:重复标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!