473,761 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox autopostback in datagrid

I have a datagrid with checkboxes and I can check/uncheck the
checkboxes to update a database by calling my oncheckchanged function.

I would like to add popup asking the users if they are sure they want
to proceed.

I have written a javascript function named confirm_duplica te and it
works as expected - it checks/unchecks checkboxes depending on user
response.

The problem is when I use the javascript alert the checkbox
autopostback does not occurr and my oncheckchanged function is never
called. Can anyone provide any clues of what I need to do? Thanks

asp code:

function confirm_duplica te()
{
if (confirm("Are you sure you want to \nchange this
selection?")==t rue)
return true;
else
return false;
}
<ItemTemplate >
<asp:CheckBox id=chk runat="server" AutoPostBack="t rue"
onCheckedChange d="oncheckchang ed"
Checked='<%#IsC heck(DataBinder .EvalContainer. DataItem, "Duplicate" ))
%>'>
</asp:CheckBox>
</ItemTemplate>

C# code:
void myDataGrid_Item Created(object
sender,System.W eb.UI.WebContro ls.DataGridItem EventArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
CheckBox _chk = (CheckBox)e.Ite m.FindControl(" chk");
_chk.Attributes .Add("onclick", "return confirm_duplica te();");

}
}
public void oncheckchanged( object source, System.EventArg s e)
{
code to update database
}
protected bool IsCheck(object objInc)
{
helper code to check/uncheck datagrid column on page load
}

Aug 15 '06 #1
1 2716
I can provide you with a work arround that worked fine with me:
1) 1st the javascript function that is similar to yours with small
modifications:
function MyConfirm(event Target,eventArg ument)
{
theForm = document.form1
var bool = confirm('are you sure?');
if(bool)
{
if (!theForm.onsub mit || (theForm.onsubm it() != false)) {
theForm.__EVENT TARGET.value = eventTarget;
theForm.__EVENT ARGUMENT.value = eventArgument;
theForm.submit( );
}
}
else
{
return false
}
}
2) 2nd You need to use ItemDataBound Inseated of ItemCreated Event as the
following:
protected void DataGrid1_ItemD ataBound(object sender, DataGridItemEve ntArgs e)
{
CheckBox chk = (CheckBox)e.Ite m.FindControl(" chk");
if (chk != null)
{
string f = "javascript:ret urn MyConfirm('{0}' ,'{1}');";
f = string.Format(f , chk.ClientID,"" );
chk.Attributes. Add("onclick", f);
}
}
3) keep AutoPostBack of your checkbox as true.

the rest of your code supposed to work correctly.

Please if anyone has better solution share it with us.

Note:
I've tried the ClientScript.Cl ientScript.GetP ostBackEventRef erence instead
of my work arround, but it produced some javascript that I couldn't resolve.

Regards,
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
"pl************ ***@yahoo.com" wrote:
I have a datagrid with checkboxes and I can check/uncheck the
checkboxes to update a database by calling my oncheckchanged function.

I would like to add popup asking the users if they are sure they want
to proceed.

I have written a javascript function named confirm_duplica te and it
works as expected - it checks/unchecks checkboxes depending on user
response.

The problem is when I use the javascript alert the checkbox
autopostback does not occurr and my oncheckchanged function is never
called. Can anyone provide any clues of what I need to do? Thanks

asp code:

function confirm_duplica te()
{
if (confirm("Are you sure you want to \nchange this
selection?")==t rue)
return true;
else
return false;
}
<ItemTemplate >
<asp:CheckBox id=chk runat="server" AutoPostBack="t rue"
onCheckedChange d="oncheckchang ed"
Checked='<%#IsC heck(DataBinder .EvalContainer. DataItem, "Duplicate" ))
%>'>
</asp:CheckBox>
</ItemTemplate>

C# code:
void myDataGrid_Item Created(object
sender,System.W eb.UI.WebContro ls.DataGridItem EventArgs e)
{
if (e.Item.ItemTyp e == ListItemType.It em || e.Item.ItemType ==
ListItemType.Al ternatingItem)
{
CheckBox _chk = (CheckBox)e.Ite m.FindControl(" chk");
_chk.Attributes .Add("onclick", "return confirm_duplica te();");

}
}
public void oncheckchanged( object source, System.EventArg s e)
{
code to update database
}
protected bool IsCheck(object objInc)
{
helper code to check/uncheck datagrid column on page load
}

Aug 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4498
by: Stephen | last post by:
I have the following asp:checkbox as a row in my datagrid. and im trying to write code on the onCheckedChanged event of it. The code im trying to write is incorrect as im getting build errors. What im trying to do is populate a label on my aspx page with the contents of the row in the database which I have checked. When I uncheck the checkbox I want the label to be set to blank so as it can be populated again when another checkbox in the...
1
1222
by: Andre | last post by:
Hi, I need some help with automatically generated checkbox in my datagrid, i'm searching everywhere and can't find a way to do this. In my datagrid i will always have more than one line, with one checkbox on each line (each line is an option for our costumers). But i want to : - have autopostback set to true only on the first (or any other,
2
3335
by: buran | last post by:
Dear ASP.NET Programmers, I have the following problem. I have a datagrid (ID: grdAllActions). This datagrid has two template columns: one column with the dropdownlist control (ID: ddlPS) and another with a checkbox control (ID: cbPS). My goal is to enable or disable the dropdownlist control when the user checks or unchecks the checkbox. I am trying the following code: <asp:TemplateColumn HeaderText="Payment Status"> <ItemTemplate>
7
2277
by: Lars Netzel | last post by:
If I put a checkbox in a datagrid (ASP.NET) and set the Autopostback to true I can catch OnChange event on checkbox but how do I then catch what DataGridItemIndex is? Can I use some Event in the Datagrid that will fire off when the Checkbox is changed? regards /Lars
2
6565
by: Asha | last post by:
greetings, i'm loading a datagrid and my gird has checkbox, i want these checkboxex to be check based on the value from the db? can someone please show me the code for it? thanks
4
2926
by: Sileesh | last post by:
Hi I have datagrid with 8 items. Out of which 2 items are checkboxes. Data is binded dynamically to the datagrid Based on some values from the database I have to check or uncheck the checkbox in the datatgrid. Does any one know how to do this?
2
3050
by: Adam Knight | last post by:
Hi all, I have a datagrid with a checkbox in one column. The checkbox is set to autopostback and calls a method named UpdateMailSubscribers. The first click on the checkbox cause the page to post but doesn't seem to haven't any affect. It doesn't appear to call the UpdateMailSubscribers method.
0
1612
by: pleaseexplaintome | last post by:
I have a datagrid with checkboxes and I am able check/uncheck the checkboxes to update a database by calling my oncheckchanged function. I would like to add popup asking the users if they are sure they want to proceed. I have written a javascript function named confirm_duplicate and it works as expected - it checks/unchecks checkboxes depending on user response.
0
1415
by: rn5a | last post by:
I have a DataGrid where in the first column of each row is a CheckBox (the CheckBoxes reside in the TemplateColumn of the DataGrid). The CheckBox's AutoPostBack property is set to True & its CheckedChanged event invokes a sub named 'CheckChanged'. The ID of the CheckBox in the DataGrid is 'chk'. This is the sub 'CheckChanged': Sub CheckChanged(ByVal obj As Object, ByVal ea As EventArgs) Dim cbox As CheckBox Dim dgiRow As DataGridItem
0
9353
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
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
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...
0
8794
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
7342
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
5241
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
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2765
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.