如何在asp.net中使用javascript从Code后面添加Querystring参数?

时间:2022-08-25 22:14:48

I am opening a page onClick event using javascript from code behind. But i want to pass querystring parameter and access it on another page.

我正在使用后面的代码中的javascript打开一个页面onClick事件。但我想传递querystring参数并在另一个页面*问它。

string id=1;
    teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "'");

The above code works fine!

上面的代码工作正常!

Now i want to append QueryString using Javascript and Access it on another page from CodeBehind.

现在我想使用Javascript追加QueryString并在CodeBehind的另一个页面*问它。

I Tried :

我试过了 :

teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "'" + "&isabout=true");

but it does'nt work!

但它不起作用!

How to Conditional Redirect using HTML Anchor:

如何使用HTML Anchor进行条件重定向:

 <a style="border: 0px none; float: left;" href="TeamMember.aspx">

            <img alt="<--" src="Images/ArrowLeft.png" style="display: inline-block; cursor: pointer;
                border: 0 none;" />
        </a>

In above I want to set conditional Redirect depending on Querystring Parameter?

在上面我想根据Querystring参数设置条件重定向?

Eg: if isabout=true then redirect to TeamMember.aspx else Other.aspx Help Appreciated! Thanks

例如:if isabout = true然后重定向到TeamMember.aspx else Other.aspx帮助感谢!谢谢

1 个解决方案

#1


5  

You have a single quote ' within the query string. You have to change the location of the quote ' to the end of the href string.

您在查询字符串中有一个单引号。您必须将引号的位置更改为href字符串的末尾。

change this.

改变这一点。

teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "'" + "&isabout=true");

To this.

对此。

teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "&isabout=true'");

#1


5  

You have a single quote ' within the query string. You have to change the location of the quote ' to the end of the href string.

您在查询字符串中有一个单引号。您必须将引号的位置更改为href字符串的末尾。

change this.

改变这一点。

teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "'" + "&isabout=true");

To this.

对此。

teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "&isabout=true'");