So the complete url would be viewnews.aspx?newsid=4&logoff=1 if the person wants to log off on that page. However, I have yet to find any way to actually programmically add parameters to the url, not the horrible string concating. The reason is whether the left side of the param starts with ? or with &.
Is there any way to do this? Or some sort of query builder in VB.Net?Hi Shannara,
I don't think that there is a QueryBuilder inherent in the ASP.NET framework. (At least, not as far as I could discover.)
However, it's not hard to make one.
The following code does what you want.
<%@. Page Language="VB" %>
<script runat="server"
' Here is your normal code, which programmatically adds
' query string values with the method AddQuery( key, value )' When finished, we can get the resulting query string
' with the method GetQueryString()Sub GotoNewPage( ByVal sender As Object, ByVal eArgs As EventArgs )
If chkNewsId.Checked Then
AddQuery( "newsid", txtNewsId.Text )
End IfIf chkLogoff.Checked Then
AddQuery( "logoff", "1" )
End IfResponse.Redirect( "querystrings.aspx" & GetQueryString() )
End Sub
' Here then is the code for that AddQuery( key, value ) method
' and also the code to retrieve the QueryString with GetQueryString()Private Shared Queries As New ArrayList()
Public Shared Sub AddQuery( ByVal key As String, ByVal value As String )
Dim thisQuery As New DictionaryEntry( key, value )
Queries.Add( thisQuery )End Sub
Public Shared Function GetQueryString() As String
Dim strToReturn As String
Dim intNumberOfQueries As IntegerintNumberOfQueries = Queries.Count
If intNumberOfQueries > 0 ThenstrToReturn = "?"
Dim i As Integer
For i = 0 to (intNumberOfQueries - 1)
strToReturn &= Queries(i).Key & "=" & Queries(i).Value
If i < intNumberOfQueries - 1 Then
strToReturn &= "&"
End If
NextEnd If
Return strToReturn
End Function
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:CheckBox id="chkNewsId" text="News ID" runat="server"></asp:CheckBox>
<asp:Textbox id="txtNewsId" runat="server"></asp:Textbox>
<br />
<asp:CheckBox id="chkLogoff" text="Logoff" runat="server"></asp:CheckBox>
<br />
<asp:LinkButton id="submit" onclick="GotoNewPage" Text="Reload page with these querystring parameters" runat="server" />
</form>
</body>
</html>
This isrough code only to give you an idea of what you might do. This code, as it stands, is not suitable for use on a website.
Of course, I have no idea of your programming experience, and whether you understand this code or not. If not, let me know what parts you don't understand. (And "all of it" is an okay reply.)
That actually looks quite wonderful :) Thank you! I currently only have one ,,, u know what? I may have to do a bit of testing on that... anyways thank you! :)
Tried it out, couldnt get it to work at all w/ the templating system, and session variables isnt working properly either :) I ended up making an expensive work around... Thanks for the help anyways :)
Well, I did say it was rough code that you'd have to massage into your own system.
What was your "expensive work around"?
Expensive, I mean resource wise :)
Anyways, ended up making a blank logoff page that in the code behind, it will log person off, then redirect them to their last page.. ergh, a ugly hack, but works.
0 comments:
Post a Comment