Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

how do I generate a random string with the current url in a asp:Hyperlink tag here-> NavigateUrl='<%# thispageURL?randomString %>'

How do I make a dynamic link to consistantly reload this page?

When a user comes to a page on my site I need them to interact with it and when they need to reset the page by reloading the url I need them to click on a link that will refresh the page. I need to do this from the declarative side and not the code behind page. Is there anyway to generate the current url and also generate a random string on the end of it from within the NavigateURL tag? I can put code in the App_Code directory if that is a way to do it.

<asp:HyperLink ID="HyperLink3" NavigateUrl='<%# thispageURL?randomString %>'  runat="server" CssClass="clearAll">Clear all </asp:HyperLink>
1 Solution
Ashish PatelCommented:
IF you are using SQL Server along with your project, then just use
Select NewID()
and fetch the result in a variable and attache it as randomString in the codebehind. The query will get you guid which can work as a random string for you. May be this help you.
@asvforce That is overkill

Just use the GUID class


THis will give you a unique guid every time called
jbrahyAuthor Commented:
how does that work within the asp:Hyperlink tag? and I would also need the current url and I can't find that.
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

>>when they need to reset the page by reloading the url I need them to click on a link that will refresh the page.

all you need is to reset the form?
        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="javascript:document.forms[0].reset();">Clear All</asp:LinkButton>
Add the following to your Page Load event

HyperLink3.NavigateUrl = string.Format("{0}?Unique={1}", Request.Url.AbsolutePath, System.Guid.NewGuid().ToString());
Pure aspx based solution below: -

<a href="<% =string.Format("{0}?Unique={1}", Request.Url.AbsolutePath, System.Guid.NewGuid().ToString()) %>" class="clearAll">Clear all</a>
jbrahyAuthor Commented:
you rock! thank you McExp, that's exactly what I needed

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now