aspnet confirmation from Client

S

sweetpotatop

Hi,

I have a page written in C# asp.net, which allow users to select and
delete records.

Once user selects the record to be deleted, I will confirm with the
user, something like "Are you sure you want to delete the selected
records?"

If yes, I will go and delete the record from SQL. How can this
confirmation and deleting process be done?
From what I understand, I need javascript to confirm with the user,
but then how can I transfer the response back to the server and delete
those selected records from the server?

Thanks in advance. Your advice and help would be greatly appreciated.
 
M

Mark Rae [MVP]

I have a page written in C# asp.net, which allow users to select and
delete records.

How are the records presented to the user?
Once user selects the record to be deleted, I will confirm with the
user, something like "Are you sure you want to delete the selected
records?"

If yes, I will go and delete the record from SQL. How can this
confirmation and deleting process be done?

<asp:Button ID="MyButton" runat="server" Text="Delete"
OnClick="MyButton_Click" OnClientClick="return confirm('Are you sure you
want to delete this record?');" />
but then how can I transfer the response back to the server and delete
those selected records from the server?

That's what a postback is for... When the user clicks the above button, a
JavaScript alert will ask them to confirm that they want to continue. If
they don't, nothing further will happen. If they do, the server-side
MyButton_Click event will fire - that's where you write the code to delete
the record...
 
S

sweetpotatop

How are the records presented to the user?



<asp:Button ID="MyButton" runat="server" Text="Delete"
OnClick="MyButton_Click" OnClientClick="return confirm('Are you sure you
want to delete this record?');" />


That's what a postback is for... When the user clicks the above button, a
JavaScript alert will ask them to confirm that they want to continue. If
they don't, nothing further will happen. If they do, the server-side
MyButton_Click event will fire - that's where you write the code to delete
the record...

The button is setup in the way that you described above. But how do I
get the return value from the server side? What variable does the
return value go?
 
M

Mark Rae [MVP]

The button is setup in the way that you described above. But how do I
get the return value from the server side? What variable does the
return value go?

What return value are you talking about...?
 
S

sweetpotatop

What return value are you talking about...?

Return value is the actual response from the user, e.g "Yes" to
delete , or "No" (client-side respond)

Since I am going to delete the record from the server-side, is there a
server-side variable that capture the respond from the user (client-
side)?
 
M

Mark Rae [MVP]

Return value is the actual response from the user, e.g "Yes" to
delete , or "No" (client-side respond)

OnClientClick="return confirm('Are you sure...?');

Note the word "return" before "confirm"...
Since I am going to delete the record from the server-side, is there a
server-side variable that capture the respond from the user (client-
side)?

None is needed - if the user chooses not to continue, the postback doesn't
happen...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top