admin管理员组文章数量:1386669
I would like to show a confirmation Box
with the message when the user check the CheckBox
.
So i have a GridView
and there is a column for CheckBoxes
.
So whenever user check the CheckBox
i would like to show a confirmation box and when user click cancel on that box i would like to uncheck that CheckBox
.
when user press OK then i would like to fire a standard asp CheckBox_CheckedChanged
where i am doing some database work.
I dont know how to do that in javascript
or Jquery
.
I found it on google where there is only one CheckBox
and you can use the ID
and using the Jquery
you can show the popup.
BUT i have a GridView and there are lots of CheckBoxes
for each row.
Please suggest me some working example or Code.
Thanks
***** EDITS ******* here is the code i have got so far.
$('#gvOrders').click(function () {
var checked = $(this).is(':checked');
if (checked) {
document.getElementById("confirm_value").value = "Yes";
if (!confirm('Are you sure you want to mark this order as received?')) {
$(this).removeAttr('checked');
}
}
else {
document.getElementById("confirm_value").value = "No";
if (!confirm('Are you sure you want to mark this order as not received?')) {
$(this).removeAttr('checked');
}
});
This is not working so far when CheckBox
checked. I am not sure what i am doing wrong here.
*** HTML FOR GRIDVIEW *******
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="gvClickCollectOrders"
DataKeyNames="ac_OrderId" OnRowDataBound="gvOrders_RowDataBound" AllowPaging="true">
<Columns>
<asp:BoundField DataField="ac_OrderId" Visible="false" />
<asp:BoundField DataField="ac_OrderNumber" HeaderText="Order No" DataFormatString="WWW{0}" />
<asp:TemplateField HeaderText="Order Date">
<ItemTemplate>
<%# GetOrderDate(AlwaysConvert.ToInt(Eval("ac_OrderId"))) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<%# Eval("CustomerFirstName") %> <%# Eval("CustomerLastName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Received In Store">
<ItemTemplate>
<asp:CheckBox ID="cbIsReceived" runat="server" AutoPostBack="true" Checked='<%# Eval("IsReceived") %>'
OnCheckedChanged="cbIsReceived_CheckedChanged"/>
<asp:Label ID="receivedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Collected By Customer">
<ItemTemplate>
<asp:CheckBox ID="cbIsCollected" runat="server" AutoPostBack="true" Checked='<%# Eval("IsCollected") %>'
OnCheckedChanged="cbIsCollected_CheckedChanged" />
<asp:Label ID="collectedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="emptyGrid" runat="server" Text="there are no Click and Collect orders placed for the selected store."
CssClass="emptyGridMessage"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
I would like to show a confirmation Box
with the message when the user check the CheckBox
.
So i have a GridView
and there is a column for CheckBoxes
.
So whenever user check the CheckBox
i would like to show a confirmation box and when user click cancel on that box i would like to uncheck that CheckBox
.
when user press OK then i would like to fire a standard asp CheckBox_CheckedChanged
where i am doing some database work.
I dont know how to do that in javascript
or Jquery
.
I found it on google where there is only one CheckBox
and you can use the ID
and using the Jquery
you can show the popup.
BUT i have a GridView and there are lots of CheckBoxes
for each row.
Please suggest me some working example or Code.
Thanks
***** EDITS ******* here is the code i have got so far.
$('#gvOrders').click(function () {
var checked = $(this).is(':checked');
if (checked) {
document.getElementById("confirm_value").value = "Yes";
if (!confirm('Are you sure you want to mark this order as received?')) {
$(this).removeAttr('checked');
}
}
else {
document.getElementById("confirm_value").value = "No";
if (!confirm('Are you sure you want to mark this order as not received?')) {
$(this).removeAttr('checked');
}
});
This is not working so far when CheckBox
checked. I am not sure what i am doing wrong here.
*** HTML FOR GRIDVIEW *******
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="gvClickCollectOrders"
DataKeyNames="ac_OrderId" OnRowDataBound="gvOrders_RowDataBound" AllowPaging="true">
<Columns>
<asp:BoundField DataField="ac_OrderId" Visible="false" />
<asp:BoundField DataField="ac_OrderNumber" HeaderText="Order No" DataFormatString="WWW{0}" />
<asp:TemplateField HeaderText="Order Date">
<ItemTemplate>
<%# GetOrderDate(AlwaysConvert.ToInt(Eval("ac_OrderId"))) %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<%# Eval("CustomerFirstName") %> <%# Eval("CustomerLastName") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Received In Store">
<ItemTemplate>
<asp:CheckBox ID="cbIsReceived" runat="server" AutoPostBack="true" Checked='<%# Eval("IsReceived") %>'
OnCheckedChanged="cbIsReceived_CheckedChanged"/>
<asp:Label ID="receivedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Collected By Customer">
<ItemTemplate>
<asp:CheckBox ID="cbIsCollected" runat="server" AutoPostBack="true" Checked='<%# Eval("IsCollected") %>'
OnCheckedChanged="cbIsCollected_CheckedChanged" />
<asp:Label ID="collectedDateText" Text="" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EmptyDataTemplate>
<asp:Label ID="emptyGrid" runat="server" Text="there are no Click and Collect orders placed for the selected store."
CssClass="emptyGridMessage"></asp:Label>
</EmptyDataTemplate>
</asp:GridView>
Share
Improve this question
edited Feb 4, 2013 at 10:23
patel.milanb
asked Feb 4, 2013 at 10:16
patel.milanbpatel.milanb
5,99215 gold badges61 silver badges95 bronze badges
3
- put your html of your gridview – शेखर Commented Feb 4, 2013 at 10:21
- see my edits. I have put my code but its not working – patel.milanb Commented Feb 4, 2013 at 10:24
-
gvOrders
is your grid-view id? – शेखर Commented Feb 4, 2013 at 10:40
3 Answers
Reset to default 3Using jQuery
Assign some class to your gridview checkbox and bind the event on that class.
<asp:CheckBox id="chkChoice" runat="server" class="some-class" ></asp:CheckBox>
$('.some-class').click(function () {
var checked = $(this).is(':checked');
if (checked) {
document.getElementById("confirm_value").value = "Yes";
if (!confirm('Are you sure you want to mark this order as received?')) {
$(this).removeAttr('checked');
}
}
else {
document.getElementById("confirm_value").value = "No";
if (!confirm('Are you sure you want to mark this order as not received?')) {
$(this).removeAttr('checked');
}
}
//return someVariableHoldTrueOrFalseForPostBack
//return true of false from here.
});
Using javascript
You can bind the javascript event on check box and it will be applied to all generated checkboxes of each row of grid automatically.
<asp:CheckBox id="chkChoice" runat="server" OnClientClick="return yourFunction(this)" ></asp:CheckBox>
function yourFunction(source)
{
return confirm("your message");
}
To show a pop on checkbox checked
1.Create a div and design a popup as per your wish in your aspx page.
2.check if the checkbox is checked or not.
3.If it is checked then call the div as popup using its id.
c# Code:
if(checkedbox.checked==true)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "showpopup();", true);
}
Script:
function showpopup() {
$("#popup").fadeIn('slow');
}
where #popup is the id of the popup div which u have created.
use the following code
$(document).ready(function() {
$("#gvOrders input:checkbox").click(function(e) {
if ($(this).is(":checked")) {
var m= confirm("your message");
if(m !=true)
{
$(this).removeAttr('checked');
e.preventDefault();
}
});
});
本文标签: cPopup window when checkbox checked in aspnetStack Overflow
版权声明:本文标题:c# - Popup window when checkbox checked in asp.net - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744545851a2611892.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论