我有按钮:
<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#commentspost评论方法如下:
/// <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");
}
}当状态不是success时,问题就出现了,当它重定向时,它工作得很好。
发布于 2011-07-10 20:56:37
下面的代码执行重定向。
Response.Redirect(PageNavURL.Replace("$1", TotalPages.ToString()) + "#comments");该URL似乎基于PageNavURL属性。您需要更改该属性或代码,以便生成不同的URL。
https://stackoverflow.com/questions/6641178
复制相似问题