'Return Function
SmartQuery = strQuerystring
End Function
right the above should, but not tested get the existing querystring ,
then using the querystring veriables and values it checks each
querystring parameter (strquerystrings), to see if it is within the
querystring if its not it then gets the value (strValues), and adds
"strquerystrings (value)=strValues (value)" to the querystring value
to activate it use
SmartQuery(strquerystrings, strValues)
SET strquerystrings to all the querystring parameters (shw)
SET strValues to all the wanted values for that querystring (cds)
seperate strQuerystrings with & (dont start with one but always end with one
Thx, your function is good, but still don't address my needs, what I need is a way to make a link and only tell in that link the new querystring to use, always preserving any existing queries and checking for the presence of a query like the new one being put in.
Example, for paging, I use bp=6, it should remove bp=5 if it's there and only apply my new bp=6 always preserving all other queries in there.
Your function is good nevertheless, but with it I would still have to declare all queries in the link, what I want is to make a link like [<a href="" & thisFile & "?" & smartQuery("bp=" & bp + 1) & ">Next</a>] then the function smartQuery should:
- Gather all existing queries.
- Remove any bp=? already there and apply my new bp=?
See the point?
This is the first app I do which has alot of queries to be processed at any one time, I am the only one facing this problem?
I could offcourse declare all queries in all links, but then everytime I had a new query (like a new feature) I have to manually update all links to preserve that new query, too much trouble, there's gotta be a function controlling all this.
Hi, no problem, I have tested your function and it works however I'm still required to declare all queries in the link, not what I want to do.
On each link I just want to declare 1 query by that link and then the function does calculate what other queries already exist and fix the repeats.
Basicaly, if the querystring is now: fun.asp?op=ab&bid=33&cid=21&bp=16&shw=ops and I press the paging button to go to the next page, it should then be: fun.asp?op=ab&bid=33&cid=21&bp=17&shw=ops only bp=17 changed all the rest remains the same, this paging button has only a call to the function("bp=17") and the function does the rest.
I have done some work on it, but I'm now a bit lost, check and run this please:
'// Get my variable not value with arrMyVar(0)
arrMyVar = Split(strMyQuery, "=")
For query = 0 to UBound(arrVarAndValue)
If LCase(arrVarAndValue(query)) = strMyQuery Then strMyQuery = ""
Response.Write(vbCrLf & "<b>Query: " & arrVarAndValue(query) & "</b><br>")
arrVar = Split(arrVarAndValue(query), "=")
For var = 0 to UBound(arrVar)
If var Mod 2 Then Response.Write(vbCrLf & "Var only: " & arrVar(var Mod 1) & "<br>")
Next
Response.Write("<br>")
Next
If strMyQuery = "" Then
sQuery = strQueryFull
ElseIf strQueryFull = "" Then
sQuery = strMyQuery
Else
sQuery = strQueryFull & "&" & strMyQuery
End If
End Function
'// --------------------------| End of function: sQuery
%>
See what I need is to make a link like: Response.Write(vbCrLf & "<a href=""" & thisFile & "?" & sQuery("shw=cds") & """>Query</a>") -- Then the function will decimate what's already in the querystring by the & sign, then for each found it will seperate var/value by the = sign, then compare the var with the var I'm passing to the function and it is there already change only the value, so if the URL already contains and shw=ops and my link has shw=cds the old shw=ops should disappear in favor of my one.
This code should solve all your problems, plus. The first method depends on the other two, which are equally useful on their own. You'll need to remove the &nnbs p; that the board added in the one function.
/// <summary> /// Appends string items together with a specific string separating the items. Unless false is /// specified for AppenWhenListItemIsEmpty, an empty ListItem item will be appended. If true is /// specified for AppendWhenListItemIsNull, a null ListItem will be appended as an empty string. /// </summary> /// <param name="List">The list to append to</param> /// <param name="ListItem">The item to be appended to the list</param> /// <param name="ListItemSeparator">The string that will separate the list from the new item</param> /// <param name="AppendWhenListItemIsNull"> /// If true, a null ListItem should be appened as an empty string. /// If false, a null ListItem will cause the List to be returned as-is without any modification. /// </param> /// <param name="AppendWhenListItemIsEmpty"> /// If true, an empty ListItem should be appened. /// If false, an empty ListItem will cause the List to be returned as-is without any modification. /// </param> /// <returns>A separated string</returns> public static string AppendListItems(string List, string ListItem, string ListItemSeparator, bool AppendWhenListItemIsNull, bool AppendWhenListItemIsEmpty) { string ret = string.Empty;
if ((!AppendWhenListItemIsNull && ListItem == null) || (!AppendWhenListItemIsEmpty && ListItem.Trim().Length == 0)) { ret = List; } else {
// Validate the ListItemSeparator argument if (ListItemSeparator == null) { &nbs p; throw new System.ArgumentNullException("ListItemSeparator"); }
// Clean the ListItem argument if (ListItem == null) { &nbs p; ListItem = string.Empty; }
// Append the list items if (List == null || List == string.Empty) { &nbs p; ret = ListItem; } else { &nbs p; if (List.EndsWith(ListItemSeparator)) &nbs p; { &nbs p; ret = List + ListItem; &nbs p; } &nbs p; else &nbs p; { &nbs p; ret = List + ListItemSeparator + ListItem; &nbs p; } } }
// Return the result return ret; }
/// <summary> /// Appends a name and value onto a querystring as a name=value pair. /// </summary> /// <param name="QueryString">The Querystring to add the items to</param> /// <param name="Name">The Name part of the pair</param> /// <param name="Value">The Value part of the pair</param> /// <param name="ReplaceNameValuePairIfNameAlreadyPresent">Whether or not to replace the /// name value pair with the new name value pair if the name already exists</param> /// <param name="AppendValueToNameIfNameAlreadyPresent">Whether or not to include the /// value as a subvalue of Name if Name already exists in the querystring. If /// ReplaceNameValuePairIfNameAlreadyPresent is true, this value is ignored</param> /// <returns></returns> public static string AppendNameValuePairToQueryString(string QueryString, string Name, string Value, bool ReplaceNameValuePairIfNameAlreadyPresent, bool AppendValueToNameIfNameAlreadyPresent) { string ret = string.Empty;
if (!(Name == null || Value == null || Name.Trim().Length ==0 || Value.Trim().Length == 0)) { // Clean the querystring if (QueryString == null) { &nbs p; QueryString = string.Empty; } else { &nbs p; QueryString.Trim(' ', '&'); }
// Add the value onto the end of the existing name=value pair with a comma between // the added value and the previous value if (nameAlreadyPresent && (ReplaceNameValuePairIfNameAlreadyPresent || AppendValueToNameIfNameAlreadyPresent))
I prefer not to use any client side javascript as it can be turned off, so rendering my app useless, I don't even do form validation that way any more for the same reason, and, I hate not being able to access a web site or link because it relies on javascript, which I always have off, and so most security consciencious people.
If it is server side javascript, all my code is in VBSCript so can't use it either.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum
Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.
Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.