none
pass a querystring to a hyperlink on the page? C# ASP.net RRS feed

  • Question

  • I need something like:

    <a href="https://MyPageURl?UniqueId= + <%Request.QueryString["ID"]%> + ""  id="Myfile">  

    What is the correct synthex for inserting the query string on this tag please? 


    faye fouladi

    Wednesday, May 15, 2019 7:25 PM

Answers

  • How about below?

    <a href='<%= String.Format("yourpage.aspx?id1={0}",Request.QueryString["id"]) %>'id="dwnload"> >your link</a>


    faye fouladi

    Wednesday, May 15, 2019 8:08 PM

All replies

  • <a href='https://MyPageURl?UniqueId= "+ <%Request.QueryString[ID]%> +"&id=Myfile'>
    Wednesday, May 15, 2019 7:36 PM
  • How about below?

    <a href='<%= String.Format("yourpage.aspx?id1={0}",Request.QueryString["id"]) %>'id="dwnload"> >your link</a>


    faye fouladi

    Wednesday, May 15, 2019 8:08 PM
  • How about below?

    <a href='<%= String.Format("yourpage.aspx?id1={0}",Request.QueryString["id"]) %>'id="dwnload"> >your link</a>


    faye fouladi

    Hi faye,

    This one is also working, please check the render result in browser:

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, May 16, 2019 6:36 AM
  • I need the whole syntax before the _layouts to be dynamic:

    <a href='<%= String.Format("http://mydoamain.com/CRS/ERDG/_layouts/download.aspx?id1={0}",Request.QueryString["id"]) %>'id="dwnload"> >your link</a>

    Would the below code work?

    <a href='<%=String.Format("http://{0}{1}/_layouts/download.aspx?id1={2}", Request.host.url, Request.ApplicationPath, Request.QueryString["ID"])%>' id="download">your link</a>


    faye fouladi

    Thursday, May 16, 2019 10:18 PM
  • Hi,

    If the page is located in SharePoint layouts folder, no need to pass specific server relative url, just the site Host name is enough as the layout folder is a common folder for all sites:

    <a href='<%=String.Format("http://{0}/_layouts/download.aspx?id1={2}", HttpContext.Current.Request.Url.Host, Request.QueryString["ID"])%>' id="download">your link</a>

    And there is no host property in Request object, use HttpContext.Current.Request.Url.Host instead.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, May 17, 2019 5:55 AM
  • Request.ApplicationPath.TrimEnd('/') produced nothing.

    What can I place on the tag to get the portion of the link /sites/Library in https://mydomain.com/Sites/Library/_layouts.aspx please?

    Thanks


    faye fouladi

    Friday, May 17, 2019 5:12 PM
  • I need to have a tag like

    <a href='<%=String.Format("http://{0}/_layouts/download.aspx?id1={1}", _spPageContextInfo.webAbsoluteUrl,  Request.QueryString["ID"])%>' id="download">your link</a>

    How can I do it?


    faye fouladi


    Friday, May 17, 2019 7:08 PM
  • Hi,

    Use SPContext.Current.Site.Url:

    <a href='<%=String.Format("{0}/_layouts/download.aspx?id1={1}", SPContext.Current.Site.Url, Request.QueryString["ID"])%>' id="download">your link</a>

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, May 20, 2019 9:57 AM
  • Thank you, I will try it.


    faye fouladi

    Monday, May 20, 2019 12:59 PM
  • Hi,

    You are welcome and if it is helpful to your question, you could also Mark the reply as answer so that it could help others who stuck with the same question in the forum.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, May 20, 2019 2:11 PM