Question Page Navigation Suggestions

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hello,

I have a web form and there are some text fields on the form. When user enters data to those fields and press submit button, on the code page INSERT statement runs and inserts those data into db. There is no problem until now. What i want to do is to inform user like "Transaction completed successfully" and redirect to default.aspx

Any good ideas?

Thanks in advance.

best Regards.
 
Alert user and redirect him to Default page

Use a Boolean function e.g.

PHP:
    Private Function TransactionCompleted(name As String, amount As String, etc. etc.) As Boolean
        Dim bool As Boolean = False
        Dim connection As New SqlConnection("connectionstringhere")
        Try
            connection.Open()
            Dim command As SqlCommand = connection.CreateCommand
            command.CommandType = CommandType.StoredProcedure
            command.CommandText = "InsertData_SP"
            command.Parameters.Add("@Name", SqlDbType.VarChar).Value = name
            ' more input parameters
            command.Parameters.Add("@Success", SqlDbType.Bit).Direction = ParameterDirection.ReturnValue
            command.ExecuteNonQuery()
            If Not IsDBNull(command.Parameters("@Success").Value) Then
                bool = True
            End If
        Catch ex As Exception
            Response.Write(ex.Message)
        Finally
            connection.Close()
        End Try

        Return bool
    End Function

Now you can just say:


PHP:
 If TransactionCompleted(NameTextBox.Text, AmountTextBox.Text, etc.etc.) = True Then
   
     ClientScript.RegisterClientScriptBlock(Me.GetType, "Alert", "<script>alert('Transaction completed successfully');</script>")
      Response.Redirect("Default.aspx")

  End If
 
Last edited:
Of course be aware that for this code you need to create a Stored Procedure with Return value e.g.
VB.NET:
CREATE PROCEDURE InsertData_SP
 (
    @Name varchar(256),
    @Amount money,
    -- etc etc.
)

AS

           DECLARE @Success bit;

	BEGIN TRANSACTION
	BEGIN TRY

		INSERT INTO Transactions(Name, Amount, etc. etc.) VALUES(@Name, @Amount, etc. etc.)
		COMMIT TRANSACTION
                      SET @Success = 1
	END TRY
	BEGIN CATCH
		ROLLBACK TRANSACTION
		SET @Success = 0
	END CATCH

           RETURN @Success
 
Hi,

I could not manage to show Alert message like below;

ClientScript.RegisterClientScriptBlock(Me.GetType, "Alert", "<script>alert('Transaction completed successfully');</script>")

How can i use this in code behind?
 
Just like it below; in my button_click event but there is no alert.

If value = True Then

ClientScript.RegisterClientScriptBlock(Me.GetType, "Alert", "<script>alert('Transaction completed successfully');</script>")


End If
 
Well it should work unless your value is not True :(
To be certain that it works create a test page with only ONE button and do not add any if statements. Just paste the code as is.
Then go back to your original project and try to find what's wrong. From here i can't help much. For me it works just fine!
 
Back
Top