?
Solved

How to access the code return confirm('Are you sure to Delete?') results (c# asp.net)

Posted on 2010-01-12
5
Medium Priority
?
197 Views
Last Modified: 2013-11-26
Hi All,

I am using an asp:Button with the CommandName=Delete in the <ItemTemplate> in the <FormView> controls.   The button works and the (JavaScript) prompt appears and deletes the selected record. I am not using the code behind file to populate the button in the template.  I just added it to the .aspx page.  It works and it's great.

The problem is that I want to access the results of the button on the prompt.  I would like to know if the users selected ok or if the user selected cancel.  If the user selected cancel, I don't want to do anything.  If the user selected ok:

I want to create a function to do a calculation and conversion and access a textbox in the page similar to the one iin the code behind file attached but I want to do the reverse and subtract 1).  I am using c#.

Thanks,

J
===========================================================
Delete Button in .aspx page:
===========================================================
<asp:Button ID="btnDelete" runat="Server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure to Delete?');" Font-Size="10px" Font-Names="tahoma" />

============================================================
code behind file for similar task
============================================================
Insert command code in code behind file from the insert button (with no prompt):

protected void Button_Clicked(object sender, EventArgs e)
    {

        string newRows = RecordCounter.Text;
        int myRows = Int32.Parse(newRows);
        myRows = myRows + 1;
        newRows = myRows.ToString();
        RecordCounter.Text = newRows;
    }

Open in new window

0
Comment
Question by:Justice75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Accepted Solution

by:
krunal_shah earned 2000 total points
ID: 26300462
Hi,

you can do it like this,


in your aspx file,

<asp:Button ID="btnDelete" runat="Server" CommandName="btnDelete" OnCommand="Button1_Command" Text="Delete" OnClientClick="return confirm('Are you sure to Delete?');" Font-Size="10px" Font-Names="tahoma" />


and in your code file,

protected void Button1_Command(object sender, EventArgs e)
 {

        string newRows = RecordCounter.Text;
        int myRows = Int32.Parse(newRows);
        myRows = myRows + 1;
        newRows = myRows.ToString();
        RecordCounter.Text = newRows;
 }

in this case Button1_Command will fire only if user clicks OK

Thanks
Krunal
0
 

Author Closing Comment

by:Justice75
ID: 31676471
Thank you so much.. This was straight to the point with no flaws!
0
 

Author Comment

by:Justice75
ID: 26307977
This was incredible and fast.. Can you explain to me what we just did tough a bit..

J
0
 

Author Comment

by:Justice75
ID: 26307983
This was incredible and fast.. Can you explain to me what we just did though a bit..

J
0
 
LVL 10

Expert Comment

by:krunal_shah
ID: 26315409
Hi,

Sorry for the late reply,

In this we just have Called one Javascript method to take the confirmation of the use, if the user clicks on OK then it will return true and then only the OnCommand event will fire.
If the user clicks on cancel then the method will return false and the OnCommand event will not fire.

Thanks
Krunal
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question