473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DataGrid with Checkbox: Need both OnCheckedChanged and onclick client script

Hi,

I have a Datagrid that uses as a shopping cart and have a checkbox
template column in it. I can't add both OnCheckedChanged Event and
onclick client script for it.
I want to do two things:

1. I want the checkbox fires CheckedChanged event. I did this as
follows:

In the DataGrid:
<templateColumn>
....
<asp:CheckBox id="chk" runat="server" AutoPostBack=True
OnCheckedChanged="handler" />
....
</templateColumn>

This works fine.....by itself

2. I want to show a confirm box:

In the same CheckBox:
<asp:CheckBox ... onclick="javascript:return confirm('Are you
Sure?');" />

This again, works fine by itself.

But when these two code goes together. Only the confirm button will
show without doing the postback.

When I look that the source, I saw both of them use the onclick,
resulting both javascript combined together:
name="dg:_ctl2:chk"
language="javascript"
onclick="javascript:return confirm('Are you
sure?');__doPostBack('dg$_ctl2$chk','')"
Can anyone give me some idea about how to solves this?

Thanks,
Homa Wong
Nov 17 '05 #1
2 11634
Hi -
I'm actually trying to solve this same problem. Has anyone found any
solution to this? It's driving me nuts!
Thanks!

ho******@yahoo.com (Homa) wrote in message news:<a9**************************@posting.google. com>...
Hi,

I have a Datagrid that uses as a shopping cart and have a checkbox
template column in it. I can't add both OnCheckedChanged Event and
onclick client script for it.
I want to do two things:

1. I want the checkbox fires CheckedChanged event. I did this as
follows:

In the DataGrid:
<templateColumn>
...
<asp:CheckBox id="chk" runat="server" AutoPostBack=True
OnCheckedChanged="handler" />
...
</templateColumn>

This works fine.....by itself

2. I want to show a confirm box:

In the same CheckBox:
<asp:CheckBox ... onclick="javascript:return confirm('Are you
Sure?');" />

This again, works fine by itself.

But when these two code goes together. Only the confirm button will
show without doing the postback.

When I look that the source, I saw both of them use the onclick,
resulting both javascript combined together:
name="dg:_ctl2:chk"
language="javascript"
onclick="javascript:return confirm('Are you
sure?');__doPostBack('dg$_ctl2$chk','')"
Can anyone give me some idea about how to solves this?

Thanks,
Homa Wong

Nov 18 '05 #2
I ran into the same problem, and couldn't find a solution here, so I
managed to find a workaround.

You are correct that .net seems to combine the two functions into one
which creates the problem.

My stategy here was to manually call the autopostback.
First, I set the autopostback on the checkbox to false.

Note: If you now have no controls on the form with sutopostback set
to true, then the __doPostBack function will not be autogenerated.

The easy solution to this is to create a control (give it height=0 and
width=0) with autopostback=true

Or you can copy and paste a __doPostBack method by viewing the source
before you remove the autopostback, but I personally would just create
an extra control

In my .vb file

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.CheckBox1.Attributes.Add("OnClick", "javasctipt:CheckConfirm();")
End Sub

Protected Sub Blah(ByVal Sender As Object, ByVal E As
System.EventArgs)
'do whatever
'Me.Label1.Text = "Blah"
End Sub
In my .aspx file

<script language="javascript">
function CheckConfirm() {

if (confirm("Are you Sure?"))
__doPostBack('CheckBox1','');
}
</script>

<asp:CheckBox OnCheckedChanged="blah" id="CheckBox1" style="Z-INDEX:
102; LEFT: 31px; POSITION: absolute; TOP: 28px"
runat="server"></asp:CheckBox>
Hope that helps
James

P.S. I have by hotmail filter set to junk all emails which are not in
my address book, so if you have any questions, please reply to the
newsgroup
Nov 18 '05 #3

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

Similar topics

1
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....
4
by: Jim Heavey | last post by:
Hello, I am starting to learn how to use the Datagrid and I have a couple of questions. My datagrid as a checkbox in it. It looks like the following in the datagrid... <asp:TemplateColumn...
2
by: Niclas Lindblom | last post by:
Hi, I have a datagrid with linkbuttons. I would like to catch the click event when a link button has been clicked and use the string from the text value of the link button in a clientside Java...
7
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...
19
by: Sjaakie Helderhorst | last post by:
Hello, I need to add a Javascript event (onClick) to a servercontrol (asp:checkbox). Checkbox is named 'cbDoMail'. Assumed that 'cbDoMail.Attributes.Add("onClick", "doJavascriptThing()") would do...
6
by: jiangyh | last post by:
hi there: I have a datagrid in my web form that contain a templet column.And in this templet column have a checkbox web control.I will get the checkbox state in my serverside. My question is...
2
by: Andre Ranieri | last post by:
Hi folks, I have a datagrid which contains a template item checkbox column. I've included a checkbox as a HeaderTemplate item which fires a server-side function to check or uncheck all the...
1
by: pleaseexplaintome | last post by:
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...
1
by: RN1 | last post by:
Consider the following DataGrid: -------------------------------------------------------------------------------- <asp:DataGrid ID="dgMarks" AutoGenerateColumns="false" runat="server"> <Columns>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.