0

Webページにボタンがあり、クリックするとSQLサーバーに接続し、ストアドプロシージャを実行します。ボタンは正常に機能します(データをデータベーステーブルにプッシュするだけです)。

私は.NETプログラミングに不慣れで、すでに持っているボタンの現在のコードに追加する適切なコードのアイデアを見つけるのに苦労しています。

理想的には、ボタンがクリックされたときにメッセージボックスが表示され、「OK」オプションだけで「データが保存されました」ことをユーザーに通知し、ユーザーがホームページにリダイレクトされるようにします。

また、ユーザーがボタンを複数回押してほしくないので、このボタンが1回だけ押されるか、その日に一度押されると非アクティブになるようにする必要があります。

ボタンの現在のコードは次のとおりです。

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 に答える