Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add Querystring parameter from Code behind using javascript in asp.net?

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.

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.

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:

 <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?

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

like image 368
SHEKHAR SHETE Avatar asked Mar 28 '13 06:03

SHEKHAR SHETE


1 Answers

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.

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'");
like image 168
scartag Avatar answered Sep 23 '22 17:09

scartag