2009-08-14 68 views
0

我嘗試過,但我收到此錯誤:可以調用在ASP.NET中設置爲onclick函數的函數嗎?

Server Error in '/' Application. 
Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: BC30201: Expression expected. 

Source Error: 

Line 26:   password.Text = parseQuery("pass") 
Line 27:  End If 
Line 28:  If password.Text <> "" And username.Text <> "" Then btnLogin_Click(Dim sender as Object, Dim e as System.EventArgs) 
Line 29: End If 
Line 30:  


Source File: C:\Inetpub\wwwroot\devv\login.aspx.vb Line: 28 
+1

需要看你的源代碼... – 2009-08-14 22:53:11

+0

它已經太長時間,因爲我寫VB。你可以在函數調用中調暗變量嗎?爲什麼不使用Nothing? – Joel 2009-08-14 22:55:56

+0

@Joel:不,這就是爲什麼這不會編譯。 – 2009-08-14 23:01:44

回答

3

試着改變你的語句來讀

If password.Text <> "" And username.Text <> "" Then 
    btnLogin_Click(Nothing, Nothing) 
End If 

您當前的代碼使用的是簽名,如果你是創建按鈕點擊事件,你只需將它傳遞給方法中的一些僞參數,只要它已被寫入。但是,如果您通過各種方法觸發登錄,我建議您編寫第二種稱爲ProcessLogin的方法或其他方法,並將按鈕單擊事件簡單地重定向到那裏。這樣可以更輕鬆地爲您的登錄處理提供多個「輸入向量」。

+0

這就是我認爲應該是的,但我對VB知識還不夠自信。 +1推薦一個單獨的ProcessLogin方法。 – Joel 2009-08-14 23:08:32

0

你需要從

If password.Text <> "" And username.Text <> "" Then btnLogin_Click(Dim sender as Object, Dim e as System.EventArgs) 

線28更改爲

If password.Text <> "" And username.Text <> "" Then btnLogin_Click(Nothing, EventArgs.Empty) 
相關問題