473,789 Members | 2,925 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asking for confirmation before deleting records in GridView of ASP.NET 2005

19 New Member
Hello everyone,


I have a Gridview , whose first column is template colums which contains checkboxes , outside my GridView I a have a delete button.
So in this application,whe n the user check any checkbox ,and when click on the delete button , it should ask for the confirmation 'Are you sure you want to delete these records'.

But you Know my problem is that:

I have added the following line to page_load event:

btnDelete.Attri butes.Add["onclick"]="return confirm('Are you sure you want to delete these records')";

On running it works but it also asks for confirmation when I have not selected any of the checkboxes.

So please give me the solution ,whether I should add any javascript function for checking whether the checkbox has been checked or not.

But I don't know how to make that javacript function for checking whether the checkbox of the GridView are selected or not .Plese help me.
Dec 2 '07 #1
4 1300
kenobewan
4,871 Recognized Expert Specialist
One one would be to use a separate event and not use the page_load. HTH.
Dec 2 '07 #2
ITCraze
19 New Member
Thank you for replying.But it will be better if you will explain me more precisely.


what I asked was:

I have a Gridview , whose first column is template colums which contains checkboxes , outside my GridView I a have a delete button.
So in this application,whe n the user check any checkbox ,and when click on the delete button , it should ask for the confirmation 'Are you sure you want to delete these records'.

But you Know my problem is that:

I have added the following line to page_load event:

btnDelete.Attri butes.Add["onclick"]="return confirm('Are you sure you want to delete these records')";

On running it works but it also asks for confirmation when I have not selected any of the checkboxes.

So please give me the solution ,whether I should add any javascript function for checking whether the checkbox has been checked or not.

But I don't know how to make that javacript function for checking whether the checkbox of the GridView are selected or not .Plese help me.
Dec 3 '07 #3
mzmishra
390 Recognized Expert Contributor
something like this


//This will be part of your aspx /ascx file


<INPUT id="btnDelete" type="button" value="Delete" name="btnDelete "
runat="server">


function ConfirmSave(msg )
{
var confirmationval ue = confirm(msg);
}

//This will be part of your aspx.cs /ascx.cs file

private void btnDelete_Serve rClick(object sender, EventArgs e)
{


int cnt;
cnt= Grid.Items.Coun t;

for (int i=0; i<cnt; i++)
{
CheckBox chkBox = Grid.Items[i].Cells[0].Controls[1] as CheckBox;
if (chkBox.Checked )
{
ExecuteScript(t his.Page, "ConfirmSave('Y our message text');");
}
}


}


public static void ExecuteScript(P age webpage_, string script_)
{
StringBuilder scriptBuilder = new StringBuilder( @"<script language=JavaSc ript>");
scriptBuilder.A ppend(script_);
scriptBuilder.A ppend(@"</script>");
JavaScriptUtil. RegisterScript( webpage_, "2", scriptBuilder.T oString());
webpage_.Respon se.Write(script Builder.ToStrin g());

}
Dec 3 '07 #4
ITCraze
19 New Member
Thank you for replying to my query.

But when I used what u have suggested but my application gives me error like:

JavaScriptUtil is not in the current context.

Please help me.
Dec 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2001
by: Mike Turco | last post by:
I'm working on an application that imports and exports tons of CSV data, like 64,000 records per file, and six or seven files in a set. First off, by the tine I import a few hundred thousand records the database is _huge_. Like 500 meg, although the csv files are only 25 meg in total. When I compact the database its still 100meg. How do I keep the size down? Second, I did a manual delete of 300,000 records yesterday by doing a...
2
2490
by: mpenev | last post by:
Hi, Is there a way to make the GridView ask for a confirmation (something similar to javascript: window.confirm ) before deleting a row? Thanks
0
1373
by: ASMJ | last post by:
Hi, I have a gridview in my page, which displays all records from an sqldatasource. The delete row command is available to the user, through which he can perform deletion. I want to trap the gridview_RowDeleting event to display a confirmation msg to the user. Is there a msgbox kind of facility where I can get confirmation from the user before deletion?
5
2657
by: Randy Smith | last post by:
Hi ALL, I wonder if anyone has been using n-tier to bind to a GridView control by using the ObjectDataSource. This is our first OOP web application, and we have no tables. Right now we are simply working with objects in memory. So, it appears as though Microsoft requires that our datamapper classes reside inside a folder called "App_Code", and NO WHERE ELSE. So, has anyone successfully been able to place their datamappers in a...
24
21654
by: Frank Swarbrick | last post by:
We have a batch process that inserts large numbers (100,000 - 1,000,000) of records into a database each day. (DL/I database.) We're considering converting it to a DB2 table. Currently we have logic in place that, prior to inserting any data, reads the first input record and checks to see if it already exists in the table. If the record already exists there are two options: 1) Don't continue, because you already ran this job today! 2)...
3
3744
by: Ronald S. Cook | last post by:
I was told that if calling lots of records from the database (let's say 100,000), that the GridView's paging feature would automatically "handle" everything. But the 100,000 records are still coming to the client, right? I mean, the paging feature isn't somehow making calls to the database for 25 records at a time or anything like that is it? I remember in the past having to write nasty stored procedures that took in
0
2013
by: johnmott | last post by:
Hi all, One of the limitations of the GridView control is that the built-in delete processing doesn't prompt for confirmation -- something thats very important for a user interface. True, you can add server side logic for this, but its much more reassuring to have a Javascript confirmation window open up and prompt. There are several techniques for doing this, just google 'Gridview delete confirm' to see them. I've figured out one which...
5
1590
by: sweetpotatop | last post by:
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
1
854
by: ITCraze | last post by:
Thank you for replying. It is giving the error: : The name 'JavaScriptUtil' does not exist in the current context Iam using ASP.NET 2005
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.