string username;
            string userid;
            if (Session["UserName"] == null || CheckBox3.Checked==true)
            {
                username = "佚名";
                userid = "10000";
            }
            
            else
            {
                username = Session["UserName"].ToString();
                userid = Session["UserID"].ToString();
            }
这个if判断没效果,未登录用户执行if下面的语句,但是登陆用户选了checkbox却不能执行if下的语句
登陆用户不管是否选中checkbox都是执行else中的语句下面是html的code
            <asp:Panel ID="Panel3" runat="server" Visible="False">
                <div>无聊图:</div>
                <div  style="margin:10px 40px 0 50px"><asp:Label ID="Label5" runat="server" BackColor="#CC0000" ForeColor="#FFFFCC" 
                    style="text-align: center" Text="Label" Visible="False" Width="470px"></asp:Label>
                </div>
                <div>
                <span style="width:50px">图片:</span>
                <span>
                <asp:TextBox ID="TextBox5" runat="server" Height="100px" 
                    TextMode="MultiLine" Width="465px">&lt;img src=&quot;&quot;/&gt;</asp:TextBox>
                </span>
                </div>
                <div>
                <span style="width:50px">标签:</span>
                <span>
                <asp:TextBox ID="TextBox6" runat="server" Width="467px"></asp:TextBox>
                </span>
                </div>
                <div style="margin-top:5px">
                <span style="margin-left: 47px">
                <asp:Button ID="Button6" runat="server" Height="25px" onclick="Button6_Click" 
                    Text="提交" Width="200px" />
                    </span>
                    <span style="margin-left: 20px">
                        <asp:CheckBox ID="CheckBox3" runat="server" Text="匿名发表" /></span>
                </div>
            </asp:Panel>
页面用一个button来控制panel的visible为true

解决方案 »

  1.   

    之前其他页面都可以正常实现,其他页面没有放在panel中,不知道是不是panel的问题,难道panel中checkbox不能这样直接使用?
      

  2.   

    foreach (Control c in Panel3.Controls)
                {
                    CheckBox chb = (CheckBox)c.FindControl("CheckBox3");
                    if ( chb.Checked == false)
                    {
                        username = "佚名";
                        userid = "10000";
                    }                else
                    {
                        username = Session["UserName"].ToString();
                        userid = Session["UserID"].ToString();
                    }试过这样遍历也不行。。
      

  3.   

    你这里的判断语句if (Session["UserName"] == null || CheckBox3.Checked==true)
    else就等价Session["UserName"] != null && CheckBox3.Checked!=true
    看看是否成立