我有按钮:
<asp:Button runat="server" OnClientClick="return ValidateNewMessage();" OnClick="PostComment" ID="AddCommentButton" CssClass="nice-button" Text="Add Your Comment" />
它位于URL:
blog/42/gregre-re-greg-er-g/comments-6#comments
当我点击按钮时,它会转到:
blog/42/gregre-re-greg-er-g/comments-6?ID=42&comments=1&page=6
这使我的脚本工作奇怪,我真的需要按钮来保持它的URL格式而不包括查询字符串数据,这可能很容易吗?因此,点击它,页面仍然是:
blog/42/gregre-re-greg-er-g/comments-6#comments
发表评论方法如下:
/// <summary>
/// Post a comment
/// </summary>
public void PostComment(object sender, EventArgs e)
{
CommentResponse CommentResp = CommentCommon.NewComment(NewComment.Text, this.ThisUser.UserID, this.Anchor);
if (!this.ThisUser.IsLoggedIn)
CommentResp.Status = CommentError.NotLoggedIn;
// Error messages
if (CommentResp.Status == CommentError.CommentsPostedTooQuick)
{
DiscussError.Visible = true;
DiscussErrorMessage.Text = "You are posting comments too quickly";
}
else if (CommentResp.Status == CommentError.ExceededCommentsPer3Mins)
{
DiscussError.Visible = true;
DiscussErrorMessage.Text = " You are posting comments too quickly";
}
else if (CommentResp.Status == CommentError.NotEnoughChars)
{
DiscussError.Visible = true;
DiscussErrorMessage.Text = "Comment is not long enough";
}
else if (CommentResp.Status == CommentError.NotLoggedIn)
{
DiscussError.Visible = true;
DiscussErrorMessage.Text = "You are not logged in";
}
else if (CommentResp.Status == CommentError.UnspecifiedError)
{
DiscussError.Visible = true;
DiscussErrorMessage.Text = "Unspecified error.";
}
// Posted ok, redirect to last page
if (CommentResp.Status == CommentError.Success)
{
int TotalComments = CommentCommon.CountComments(this.Anchor);
int TotalPages = (TotalComments + Settings.CommentsPerPage - 1) / Settings.CommentsPerPage;
Response.Redirect(this.PageNavURL.Replace("$1", TotalPages.ToString()) + "#comments");
}
}
问题发生在状态不成功时,重定向时工作正常。
答案 0 :(得分:1)
以下代码执行重定向。
Response.Redirect(PageNavURL.Replace("$1", TotalPages.ToString()) + "#comments");
网址似乎基于PageNavURL
属性。您需要更改该属性或代码,以便生成不同的URL。