• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 683
  • Last Modified:

How to set a check box initial state to unchecked - VB.net

I have a check box on my page that I want to initially appear as unchecked. In my source code it looks like this:

&nbsp;Check here if this is a sub menu:&nbsp;<asp:CheckBox ID="chkMakeSubMenu"
                        runat="server" checked="False" />

but in the browser it looks like this:

<input id="ctl00_ContentPlaceHolder1_chkMakeSubMenu" type="checkbox" name="ctl00$ContentPlaceHolder1$chkMakeSubMenu" checked="checked">

somehow the checked property is turning into from false to checked.

I've included my source code below, any idea what is causing this?

Thanks
<%@ Page Title="" Language="VB" MasterPageFile="~/admin_MasterPage.master" AutoEventWireup="false" CodeFile="admin_manhw.aspx.vb" Inherits="admin_manhw" %>
<%@ MasterType VirtualPath="~/admin_MasterPage.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>

<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
 <div style="color:White">
       <h1 style=" text-align:center"> Class Editor</h1>
    
        <p>
            Add, Delete or Edit :<asp:DropDownList ID="ddlActionType" runat="server">
                <asp:ListItem Value="0">Select Action</asp:ListItem>
                <asp:ListItem Text="Create Class" Value="1"></asp:ListItem>
                <asp:ListItem Text="Edit Class" Value="2"></asp:ListItem>
                <asp:ListItem Text="Delete  Class" Value="3"></asp:ListItem>
            </asp:DropDownList>
                <asp:UpdateProgress ID="uprog1" AssociatedUpdatePanelID="up1"  runat="server"><ProgressTemplate>
        <img src="images/smallldr.gif" alt="progress" />
    </ProgressTemplate></asp:UpdateProgress>
            
            <asp:Button ID="btnSelectFunction" runat="server" Text="Select" OnClick="btnSelectFunction_Click" />

            <p>
                &nbsp;<asp:PlaceHolder ID="phMenuDetails" runat="server"></asp:PlaceHolder>
            </p>
            <p>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:stluke %>" 
                    SelectCommand="SELECT * FROM [tblHomeWork]"></asp:SqlDataSource>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:stluke %>" 
                    SelectCommand="SELECT [menuname], [autono] FROM [tblHomeWork] WHERE ([submenu] &lt;= @submenu)">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="1" Name="submenu" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:Panel ID="pnlEditMenu" runat="server">
                    Select Homework Menu to Edit
                    <asp:DropDownList ID="ddlEditMenuList" runat="server" 
                        DataSourceID="SqlDataSource1" DataTextField="menuname" DataValueField="autono">
                    </asp:DropDownList>
                    &nbsp;&nbsp;
                    <asp:Button ID="btnEditSelMenu" runat="server" Text="Select Menu" />
                </asp:Panel>
                
                <asp:Panel ID="pnlNewMenu" runat="server" Width="100%">
                    <asp:Label ID="lblMenuCreate" runat="server" Text="Class Name:"></asp:Label>
                    &nbsp;
                    <asp:TextBox ID="txtMenuText" runat="server"></asp:TextBox>
                    <br />
                    &nbsp;Enter Position in Menu (number):
                    <asp:TextBox ID="txtMenuCode" runat="server" Width="20px"></asp:TextBox>
                    <br />
                    <asp:Label ID="lblMenuCodeTake" runat="server" Font-Size="8pt" ForeColor="red"></asp:Label>
                    <br />
                    &nbsp;Check here if this is a sub menu:&nbsp;<asp:CheckBox ID="chkMakeSubMenu" 
                        runat="server" checked="False" />
                        <br />
                    What is the parent menu:
                    <asp:DropDownList ID="ddlMenuList1" runat="server" 
                        DataSourceID="SqlDataSource2" DataTextField="menuname" 
                        DataValueField="autono">
                    </asp:DropDownList>
                    &nbsp;
                    <br />
                    <asp:Button ID="btnMenuCreate" runat="server" Text="Create" />
                    <br /> 
                    <asp:Label ID="lblShow" Font-Underline="true" style="cursor:pointer" runat="server" Text="Show Positions"></asp:Label>
                    <br />
                    <cc1:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" TextLabelID="lblShow" TargetControlID="pnlPosition"
                     ExpandControlID="lblShow" CollapseControlID="lblShow" CollapsedText="Show Positions" ExpandedText="Hide" Collapsed="true"
                     runat="server">
                    </cc1:CollapsiblePanelExtender>
                    <asp:Panel ID="pnlPosition" runat="server">
                    <div align="center">
                        <asp:GridView ID="GridView1" runat="server" AllowPaging="False" 
                            AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource3" 
                            ForeColor="#333333" GridLines="None">
                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                            <Columns>
                                <asp:BoundField DataField="menuname" HeaderText="menuname" 
                                    SortExpression="menuname" />
                                <asp:BoundField DataField="position" HeaderText="position" 
                                    SortExpression="position" />
                            </Columns>
                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                            <EditRowStyle BackColor="#999999" />
                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
                            ConnectionString="<%$ ConnectionStrings:dbConn %>" 
                            SelectCommand="SELECT [menuname], [position] FROM [tblHomeWork]"></asp:SqlDataSource>
                    </div></asp:Panel>
                </asp:Panel>
                <asp:Panel ID="pnlDeleteMenu" runat="server">
                    Select Menu to Delete :<asp:DropDownList ID="ddlDeleteMenuList" runat="server" 
                        DataSourceID="SqlDataSource1" DataTextField="menuname" DataValueField="autono">
                    </asp:DropDownList>
                    <br />
                    <asp:Button ID="btnDeleteMenu" runat="server" Text="Delete Menu" />
                </asp:Panel>
                <br />
                <asp:Label ID="lblMessage" runat="server" ForeColor="#C00000"></asp:Label>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
                <p>
                </p>
                <p>
                </p>
                
            </p>
       </p>
    </div>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>

Open in new window

0
elliottbenzle
Asked:
elliottbenzle
  • 2
2 Solutions
 
Alfred A.Commented:
I tried your source code in my test website and it seems to be rendering the checkbox quite okay.  I used IE7 and Firefox 3.6 to test it out.  Which browser are you using by the way?

Also, try removing the checked="False" attribute in there.  By default, the checkbox should be unticked anyway.  Or you could just set it in code behind something like this:

chkMakeSubMenu.Checked = False
0
 
Alfred A.Commented:
By the way, in Page Load you could do it this way:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not IsPostBack Then
          chkMakeSubMenu.Checked = False
    End If

End Sub
0
 
HainKurtSr. System AnalystCommented:
did you check your code not aspx, I mean vb or C# code... check for chkMakeSubMenu, somewhere you should have a code to set it to true... maybe in master page maybe in javascript...
0
 
elliottbenzleAuthor Commented:
Thanks guys, it was indeed in my .vb behind code.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now