0
我有一個網頁上的按鈕,當點擊連接到我的SQL服務器並運行存儲過程。按鈕工作正常(它只是將數據推入數據庫表)。asp.net onClick事件按鈕
我是.NET新手,我很難找到正確的代碼想法添加到我已有的按鈕的當前代碼。
理想情況下,我只想單擊按鈕時出現一個消息框,以通知用戶「數據已保存」,只需「確定」選項,然後將用戶重定向到主頁。
我還需要確保該按鈕只按一次或取消激活,一旦它被按下,因爲我不希望用戶多次按下按鈕。
這裏是我的按鈕當前代碼:
Protected Sub btnAddRawData_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddRawData.Click
'database conn, this is linked to the web config file .AppSettings
Using dbconnection As New SqlConnection(ConfigurationManager.AppSettings("dbconnection"))
dbconnection.Open()
'command to state the stored procedure and the name of the stored procedure
Using dbcommand As SqlCommand = dbconnection.CreateCommand
With dbcommand
.CommandType = CommandType.StoredProcedure
.CommandText = "GasNominationsRawData_Insert"
'simply execute the query
dbcommand.ExecuteNonQuery()
'I need to add some code for the button here and...
'redirect to the main home page
Response.Redirect("~/default.aspx?")
End With
End Using
End Using
End Sub
任何意見和建議,將不勝感激。
Regards, Betty。
了window.location將無法正常工作。使用'window.location.href =「default.aspx」' – Deeptechtons
@Deeptechtons感謝您的更正! – Icarus
嘿傢伙,非常感謝以上。它工作的一種享受。我確實遇到了window.location.href代碼部分的問題,但是用'Response.Redirect(「〜/ default.aspx?」)代替了這個,並且這個工作原理也是一樣的。 – Betty