首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.net按钮onclick发送查询字符串

ASP.net按钮onclick发送查询字符串
EN

Stack Overflow用户
提问于 2011-07-10 20:46:25
回答 1查看 2.1K关注 0票数 1

我有按钮:

代码语言:javascript
复制
<asp:Button runat="server" OnClientClick="return ValidateNewMessage();" OnClick="PostComment" ID="AddCommentButton" CssClass="nice-button" Text="Add Your Comment" />

它在URL上:

代码语言:javascript
复制
blog/42/gregre-re-greg-er-g/comments-6#comments

当我单击该按钮时,它会将我带到:

代码语言:javascript
复制
blog/42/gregre-re-greg-er-g/comments-6?ID=42&comments=1&page=6

这让我的脚本工作起来很奇怪,我真的需要这个按钮来保持它的URL格式,而不包括查询字符串数据,这很容易实现吗?所以在点击之后,页面仍然是:

代码语言:javascript
复制
blog/42/gregre-re-greg-er-g/comments-6#comments

post评论方法如下:

代码语言:javascript
复制
/// <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时,问题就出现了,当它重定向时,它工作得很好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-10 20:56:37

下面的代码执行重定向。

代码语言:javascript
复制
Response.Redirect(PageNavURL.Replace("$1", TotalPages.ToString()) + "#comments");

该URL似乎基于PageNavURL属性。您需要更改该属性或代码,以便生成不同的URL。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6641178

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档