Request.Querystring(variablevalue) possible?

醉酒当歌 提交于 2019-11-28 05:50:10

问题


I'm creating an application which uses request.querystring to transfer variables between pages. However at the moment I am setting variable names in the URL dynamically in accordance with an array and I want to retrieve these values on another page using (essentially) the same array. So I came up with what I thought would be the simple solution:

For Each x In AnswerIDs
    response.write(x)
    ctest = Request.Querystring(x)
    response.write(ctest)
Next

However this doesn't seem to work as it looks like you can't use Request.Querystring() with a variable as it's parameter. Has anyone got any idea how I could do this?

This is the query string:

QuizMark.asp?11=1&12=1

In this case AnswerIDs consists of "11" & "12" so in my loop I want it to write "1" & "1".


回答1:


You can loop through the querystring like this:

For Each Item in Request.QueryString
    Response.Write Item & ": " & Request.QueryString(Item) & "<br/>"
Next

Item contains the name of the querystring parameter, with Request.Querystring(Item) you retrieve the value of the parameter.




回答2:


Your method will work with a simple modification:

For Each x In AnswerIDs
    response.write(x)
    ctest = Request.Querystring(CStr(x))
    response.write(ctest)
Next

If your array might have Null elements, then replace the Cstr(x) with x & "".

If, on the other hand, you can make sure that every element of AnswerIDs has a value (i.e. is neither Empty nor Null), then you can omit the string conversion. In other words, the problem isn't with calling Request.Querystring with a variable, but with calling Request.Querystring with an Empty or a Null.



来源:https://stackoverflow.com/questions/21969292/request-querystringvariablevalue-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!