Last post Jun 01, 2011 09:57 AM by Zheeph
Jun 01, 2011 08:01 AM|Zheeph|LINK
Hey all. Here's some code I developed since I've grown tired of wasting time by typing down the page's name when I want to go to the same page and inserting weird code like "?id=" just to get sent to a new page with querystring attached. I thought I could
share it since it's become really useful to me by saving lots of typing time.
This allows you to redirect yourself to a new page with or without QueryString (by passing the value down in the second field of the sub) or to the same page you're in by typing "myself" on the first field of the sub.
This only allows ONE querystring value.
Shared Sub Into(ByVal destiny As String, Optional ByVal valuetotransport As String = "")
If Trim(LCase(destiny)) <> "myself" And Trim(LCase(destiny)) <> "" Then
If valuetotransport <> "" Then
HttpContext.Current.Response.Redirect(destiny + "?value=" + valuetotransport)
ElseIf Trim(LCase(destiny)) = "myself" And Trim(LCase(destiny)) <> "" Then
HttpContext.Current.Response.Redirect(GetCurrentPageName() + "?value=" + valuetotransport)
Shared Function GetCurrentPageName() As String
Dim sPath As String = System.Web.HttpContext.Current.Request.Url.AbsolutePath
Dim oInfo As System.IO.FileInfo = New System.IO.FileInfo(sPath)
Dim sRet As String = oInfo.Name
Jun 01, 2011 08:49 AM|Lateef045|LINK
Hi, The methods you have developed are good.
But what if
1. the user doesnt have the query string name as "Value". Maybe the user want some other name.
2. the user wants to send multiple values in the query string.
I think with little more effort you can come up with a better solution.
Jun 01, 2011 09:09 AM|Zheeph|LINK
The first one is easy to do, but for the second one, I'd need to have specific number of values passed onto the sub, otherwise the only choice is to use an array, and that would take more or the same number of characters as writing a querystring line. Do
you really think it's worth doing it?
Jun 01, 2011 09:15 AM|Zheeph|LINK
Public Class Travel
Shared Sub Into(ByVal destiny As String, Optional ByVal valuetotransport As String = "", Optional ByVal valuename As String = "value")
Dim VN As String = Trim(valuename)
HttpContext.Current.Response.Redirect(destiny + "?" + VN + "=" + valuetotransport)
HttpContext.Current.Response.Redirect(GetCurrentPageName() + "?" + VN + "=" + valuetotransport)
^ Now with value names
Jun 01, 2011 09:31 AM|Zheeph|LINK
I thought I should also prevent the user from traveling to other non-existant pages with something not very annoying like an exception so I'm working on it too.
Jun 01, 2011 09:45 AM|Lateef045|LINK
How are you planning to make sure the page is non-existant?
Jun 01, 2011 09:57 AM|Zheeph|LINK
Good point. I can't. That would stop them from going to web pages on the internet or their computer. I didn't consider that.