ZeroShade Posted June 29, 2007 Share Posted June 29, 2007 I need to grab a portion of my url (http://localhost:2592/Replies.aspx?ThreadId=124&DiscussionId=54). The portion I need is the 54 which is a query string. After I grab it I need to put it into a href (Threads.aspx?DiscussionId=). How can I go about this using javascript? Link to comment Share on other sites More sharing options...
ZeroShade Posted June 29, 2007 Author Share Posted June 29, 2007 Why doesn't this work?<script type="text/javascript"> function GoBack() { var discussionId = Request.QueryString(DiscussionId); document.write("Threads.aspx?DiscussionId=" + discussionId); } </script> Link to comment Share on other sites More sharing options...
jesh Posted June 29, 2007 Share Posted June 29, 2007 It doesn't work because the client doesn't have access to the server-side Request object. You'll either have to manually parse the string in javascript or wrap that Request.QueryString part in tags to tell the page to run that code at the server. Perhaps something like this: <script type="text/javascript"> function GoBack() { var discussionId = <%=Request.QueryString("DiscussionId")%>; document.write("Threads.aspx?DiscussionId=" + discussionId); }</script> Since it looks like you're using .NET, the better way would probably be to take care of all of that on the server:ASPX: <asp:HyperLink id="ThreadLink" runat="server" Text="Read the Discussion" /> C# Code-behind: ThreadLink.NavigateUrl = "Threads.aspx?DiscussionId=" + Request.QueryString["DiscussionId"]; Link to comment Share on other sites More sharing options...
ZeroShade Posted June 29, 2007 Author Share Posted June 29, 2007 I guess I should of asked about the asp:HyperLink... would of saved me a lot of time. Now I know of it Thanks!! Link to comment Share on other sites More sharing options...
jesh Posted June 29, 2007 Share Posted June 29, 2007 You can also make most, if not all, of the traditional HTML tags runat server as well: <a id="ThreadLink" runat="server">Read the Discussion</a> ThreadLink.Href = "Threads.aspx?DiscussionId=" + Request.QueryString["DiscussionId"]; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.