2011-01-24 67 views
0

使用傳統的ASP,我想在提交表單之前執行一些代碼,下面是我的代碼。 我正在嘗試將登錄憑據存儲到Cookie中,然後將表單發佈到其他頁面。如何在使用傳統ASP發佈表單之前執行一些代碼

請注意,我發佈到一個獨立域中的ASP.NET頁面。

另一個例子,只是爲了使這個更清楚。假設我想在發佈之前驗證字段而不使用JavaScript。

<% 
dim uname 
uname= Request.Cookies("username") 
%> 

<FORM action="httppost_login.aspx" METHOD ="post" > 
<br />Username: <INPUT NAME ="username" SIZE ="30" maxlength="15" value="<% if uname <>"" then response.write(uname) %>" /> 
<br />Password: <INPUT NAME ="password" SIZE ="30" type=password maxlength="20" /> 
<br /> 
<INPUT TYPE ="SUBMIT" value="Login" name="btnSubmit" /> 
<input type="checkbox" name="remember" value="Remember my username" <%if uname <> "" then Response.Write("checked")%> />Remember my username 
</FORM> 

<% 

If Request.Form("btnSubmit") <> "" Then 
uname=Request.Form("username") 
dim rememberme 
rememberme = request.form("remember") 
if rememberme <> "" and uname <> "" then 
Response.Cookies("username") = uname 
Response.Cookies("username").Expires = Date() + 30 
end if 
end if 
%> 

回答

1

按下提交按鈕後,您不能運行代碼easilly

這歸結爲設計。你的表格操作是:

httppost_login.aspx 

實現你想要什麼的「標準」的方法是通過該頁面用來處理餅乾/別的上的代碼。

我通常給表單動作查詢字符串:

<FORM action="httppost_login.aspx?action=login" METHOD ="post" > 

然後在該網頁上,有:

Dim strPageAction 

strPageAction = request.querystring("action") 

if(strPageAction = "login" then 
    'Put your cookie code here, request.form("username") etc will still work! 
end if 
+0

是的,我知道,但我實際上發佈到一個單獨的域中的ASP.NET頁面,所以我將無法共享cookie! – 2011-01-24 10:22:12

0

是,重定向頁面可以張貼到使用XMLHTTP

第三方網頁
相關問題