0

我在网页上有一个按钮,单击该按钮会连接到我的 SQL 服务器并运行存储过程。按钮工作正常(它只是将数据推送到数据库表中)。

我是 .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

任何想法和建议将不胜感激。

问候,贝蒂。

4

1 回答 1

0
function success()
{

 alert('Your data has been saved successfully)';
 window.location.href='Default.aspx';
}

在后面的代码上,就在这一行之后:

dbcommand.ExecuteNonQuery()

做这个:

Dim cs As ClientScriptManager = Page.ClientScript
Dim csname1 As [String] = "PopupScript"
Dim cstype As Type = Me.[GetType]()
Dim cstext1 As New StringBuilder()
cstext1.Append("success();")
cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
于 2011-10-28T11:46:33.683 回答