2012-10-15 52 views
2

我有一個來自結果集的變量標籤<%test_variable%>。使用變量的經典ASP重定向URL

我想用這個<%= test_variable%>重定向到一個鏈接,說

http://www.helloworld.someurl.com/testUrl?somevariable=<%=test_variable%>&test=ok 

我怎樣才能在<%%>標籤做到這一點?例如,

<%=test_variable%> 

<% 
' I want to redirect the url with the above tag, something like: 

Response.Redirect(" http://www.helloworld.someurl.com/testUrl?somevariable=<%=test_variable%>&test=ok") 
%> 

但我不認爲我們可以有「嵌套標籤」,對不對?

我很新的ASP。

+0

讓你的問題clear.You要重定向到一些頁。如果有什麼你想發送到該網址? – polin

回答

3

<%= %><% Response.Write(" ... "); %>簡寫:

http://www.helloworld.someurl.com/testUrl?somevariable=<%=test_variable%>&test=ok 

你澄清後:

<% 
    Response.Redirect("http://www.helloworld.someurl.com/testUrl?somevariable=" 
        + test_variable 
        + "&test=ok"); 
%> 
+0

你忘了'='標記 – xandercoded

+0

呃,我不認爲你理解我的問題...我想這樣做:變量:<%test_variable%><%Response.Redirect(「helloworld.someurl.com/。 。<%= test_variable%>;)%>但我們不能有2個連續的標籤? - 編程飯碗1分鐘前編輯 –

+0

請注意,如果您使用VBScript作爲您的服務器端語言(這是更常見在經典的ASP中),那麼你應該使用'&'而不是'+'來連接字符串。 –

1

你的代碼應該是

Response.Redirect("http://www.helloworld.someurl.com/testUrl?somevariable=" & test_variable & "&test=ok") 
1

感謝所有爲您的建議...

我決定改用此:

<script type="text/javascript"> 
    window.location = "http://www.helloworld.someurl.com/testUrl?somevariable="+<%=test_variable%>+"&test=ok" 
</script> 
+0

這會起作用,但是請注意,你現在正在做一個客戶端重定向,而不是服務器端的重定向。 – AardVark71