Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi

i want to redirect to another page when button is clicked & only if the checkbox.checked.here is my .aspx and aspx.cs

XML
<%@ Page Language="C#" MasterPageFile="~/HostMasterPage.master" AutoEventWireup="true"CodeFile="~/DomainHomePageN.aspx.cs" Inherits="DomainHomePageN" Title="Web hosting in India,web hosting  hyderabad" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <table>
        <tr>
            <td align="center" valign="bottom">
                <table width="980" align="center" cellpadding="0" cellspacing="0" bgcolor="#ffffff"class="border"><tr>
 <td align="center" valign="top" bgcolor="#ffffff" style="height: 20px;">
 </td></tr> <tr>
  <td align="left" style="padding-left: 100px;">
   <table style="font-family: Verdana; font-size: 12px; width: 400px;" cellpadding="0"cellspacing="0"><tr>
 <td style="width: 421px;">
 <asp:GridView ID="gvNotAvail" runat="server" Caption="Not Available" Width="300px" CaptionAlign="left" GridLines="None" ShowHeader="false" AutoGenerateColumns="false"CellPadding="3" CellSpacing="3">
<Columns>
 <asp:BoundField DataField="domain" HeaderText="Domain" />
 </Columns>
 </asp:GridView>
 </td> </tr> <tr>
 <td style="height: 30px;"></td> </tr> <tr>
<td align="center" style="border-width: 1px; border-color: #cacaca; border-bottom-color: #cacaca;
 width: 421px;">
<div style='color: #996699; font-weight: bold; font-size: 16px;'>
<table style="width: 522px;" cellpadding="0" cellspacing="0">
<tr>
<td style="height: 25px; width: 232px;" class="style2" align="left">
<img height="13" src="images/getImage[8].gif" width="13" />Available (Domains)
</td></tr></table>
</div>
<div style="overflow: scroll; overflow-x: hidden; height: 130px; border: solid 2px #cacaca;
scrollbar-face-color: #cacaca; scrollbar-highlight-color: #cacaca; scrollbar-3dlight-color: #cacaca;
scrollbar-darkshadow-color: #cacaca; scrollbar-shadow-color: #cacaca; scrollbar-arrow-color: #000000;
scrollbar-track-color: #ffffff;">
<br />
<asp:GridView ID="gvAvail" Width="500px" CssClass="tableView" runat="server" ShowHeader="False"ShowFooter="True" GridLines="None" AutoGenerateColumns="False" CellPadding="4"CellSpacing="1" AllowSorting="True">
<Columns>
<asp:TemplateField>
<%--<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("selected") %>' />
</EditItemTemplate>--%>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("selected") %>' Enabled="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="domain" HeaderText="Domain">
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
 <asp:TemplateField HeaderText="Price" ItemStyle-VerticalAlign="Top">
  <%--<EditItemTemplate>
   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("price") %>'></asp:TextBox></EditItemTemplate>--%>
<ItemStyle HorizontalAlign="Left" VerticalAlign="Middle" />
<ItemTemplate>
 <img src="images/rupeesymbol.jpg" alt="" />
<asp:Label ID="Label1" runat="server" Text='<%# Bind("price") %>'></asp:Label> /-
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle HorizontalAlign="Left" />
<FooterStyle HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="WhiteSmoke" Wrap="True" />
 </asp:GridView>
</div>
</td>
</tr>
<tr>
<td align="center">
<br />
<asp:Button ID="btnAddcart" runat="server" Text="Add To Cart" Font-Bold="True" Font-Names="Verdana"Font-Size="Medium" Height="36px" OnClick="btnAddcart_Click" Width="128px" />
<asp:HiddenField ID="hidden" runat="server" />
<asp:TextBox ID="txttotal" runat="server"></asp:TextBox>
</td>
</tr>
</table>

XML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(function () {
            //Column index value of price field (Column index start from 1)
            var columnIndexValue = 3;

            var checked = $('input:checkbox').click(function (e) {

                var total = 0;
                $("tr:has(:checkbox:checked) td:nth-child(" + columnIndexValue + ")").each(function () {
                    total += parseInt($(this).text());
                });

                $('#hidden').val(total.toFixed());


            });

        });


 </script>


</asp:Content



C#
protected void btnAddcart_Click(object sender, EventArgs e)
   {
       Session["Dtotal"] = hidden.Value;
       Response.Redirect("CustSignUpPage.aspx");
       //txttotal.Text = Session["Dtotal"].ToString();
   }
Posted
Updated 12-Oct-11 4:32am
v5
Comments
imaa2amha 12-Oct-11 9:28am    
your Q is not clear please explain more and which check box u need , u have many of them in the page

First of all call a function from javascript on button clientclick to check whether checkbox is checked or not. If it is checked then return true otherwise false.

function checkboxChecked ()
{
var TargetBaseControl = document.getElementById('ctl00_ContentPlaceHolder1_gvAvail');
var TargetChildControl = "CheckBox1";
//get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
for (var n = 0; n < Inputs.length; ++n)
if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0 && Inputs[n].checked)
return true;
//alert('Select at least one checkbox!');
return false;

}

OnClientClick="javascript:return checkboxChecked ();"

in case your condition is not true, server side code will not get executed as it will return false and the other case will work as will return true.

Hope this will help you.

~Amol
 
Share this answer
 
Comments
yerrojumeher 12-Oct-11 10:17am    
thanks but i want to put the condition in buttonclick
on _RowDataBound event of the grid you can add an attribute for that button and call the function you want.

Button btn = new Button ();
btn = (Button )e.Row.FindControl("btn1");
btn.Attributes["OnClick"] = MyFunction();

and write your condition inside the function MyFunction()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900