Question

Can someone help me with this:

I want to send a confirm message to the user if a button is clicked. But the problem is that I want server data on the message.

For Example:

|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|
|  You are going to delete  |
| 4 messages, are you sure? |
|                           |
|   |OK|        |Cancel|    |
|___________________________|

The number 4 is brought from database with a Stored Procedure. If the user clicks OK it should do some other code, if cancel is clicked, it should just return...

This is for a website on ASP.net using Visual Basic.

Please help!

Update:

After @T.S. answer I came up with this:

'Method for receiving the number...
'messages = numberReceived
Page.ClientScript.RegisterStartupScript(Me.GetType, "Confirmation", "<script> if (confirm('You will delete " & messages.ToString & " messages, are you sure?')) { ConfirmOnClean() }; </script>", False)

And the javascript function ConfirmOnClean() gets called correctly. What can I do to call a method on the codebehind after the user clicked OK?

Update:

I Finally solved it by Just adding a hidden field on the form:

<asp:HiddenField ID="cleanStatus" Value="dontClean" runat="server" />

And then on the Confirm on clean function I just did:

function ConfirmOnClean() {
    $('#<%=cleanStatus.ClientId %>').val('clean');
    __doPostBack('<%=btnClean %>','');
}

And on the Page_Load method on my codebehind I added:

If cleanStatus.Value.Equals("clean") Then
    OnConfirm() 'Method for calling the stored procedure for deleting the messages.
End If

I hope this helps someone!

Was it helpful?

Solution

Your question is lacking concrete code. So here is one option:

Assume you have some Id. You call stored proc

Dim message as String
Using cmd as new SqlCommand(...
    cmd.ExecuteNoQuery()
    ' retrieve your parameters here
    message = cmd.Parameters(0).Value
End Using

Now code returns to the user with the values you retrieved. You can register script block to show the message immediately on the page http://msdn.microsoft.com/en-us/library/z9h4dk8y%28v=vs.110%29.aspx

When user User clicks Ok, you can, for example, set a hidden field with a value and invoke postback. YOur aspx page will read the value and invoke DB-call to delete values.

You need to provide more details to get more concrete solution here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top