如题,
开发工具:Vs2003
目的:用户登陆控件(ascx文件)--各个页面共用;
实现方式:在单元格内插入一个表格,该表格内装登陆的几个控件,登陆之后删除该表格,插入一个新的htmltable显示欢迎消息;
代码:
<LINK href="../css/css1.css" type="text/css" rel="stylesheet">
<table id="logo" height="109" width="1002" cellSpacing=0 cellPadding=0 border=0>
    <tr>
       <td class="logo_right_bottom" id="loginView" width="400" valign="middle">
<table id="loginview" cellpadding=0 cellspacing=0 height="27px">//问题在这里
  <tr>
    <td>帐号
                 <asp:textbox id="UserName" runat="server" Width="80px"></asp:textbox>
        密码<asp:textbox id="Password" runat="server" TextMode="Password" Width="80px" Height="16px" Font-Size="XX-Small"></asp:textbox>
                 <asp:checkbox id="Auto" runat="server" Checked="true" Width="64px" Height="16px" Font-Size="XX-Small"></asp:checkbox>
                 保存
<asp:button id="ForumLogin" runat="server" Width="40px" Height="16px" Font-Size="X-Small"></asp:button>
    </td>
  </tr>
</table>
       </td>
    </tr>
</table>问题:将loginview表格插入单元格时,单元格立刻被撑高,调节该tr,td,table的高度都无济于事,而且社了表格的cellspace,cellpadding,border=0,但是也不行,如果直接在td内插入那几个控件,就不会撑大.但是在cs文件下写删除该单元格,插入一个htmltablecell就不行,而且如果插入tablecell的话,就没有innertext属性了.
谢各位老大了,

解决方案 »

  1.   

    给你一个示例吧.....你看看,,肯定有用..
    <form id="form1" method="post" runat="server">
            <div style="text-align: center">
                <table class="tableborder" cellpadding="0" cellspacing="1" width="496" border="0"
                    style="position: relative; top: 40px">
                    <tbody>
                        <tr>
                            <td>
                                <div class="topheader" style="text-align: left">
                                    &nbsp;&nbsp;登录管理</div>
                                <div class="header_box">
                                    <img alt="" src="image/WORD_day.gif" style="height: 96px" /></div>
                                <div class="install_box">
                                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td align="center" colspan="3" style="height: 14px">
                                                <div>
                                                    <asp:Label ID="label1" Font-Names="宋体" runat="server" Visible="false" ForeColor="red">用户名或密码错误,请重新登陆!</asp:Label></div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" style="width: 48%; height: 19px">
                                                用户名:</td>
                                            <td align="left" style="width: 3%; height: 19px;">
                                                <asp:TextBox CssClass="LoginLine" ID="UserName" runat="server" Text=""></asp:TextBox>
                                            </td>
                                            <td align="left" style="width: 48%; height: 19px;">
                                                &nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td align="right" style="height: 19px; width: 48%">
                                                密码:</td>
                                            <td align="left" style="width: 3%; height: 19px;">
                                                <asp:TextBox CssClass="LoginLine" ID="UserPwd" runat="server" Text="" TextMode="password"
                                                    Font-Size="Larger"></asp:TextBox>
                                            </td>
                                            <td align="left" style="width: 48%; height: 19px;">
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right" style="height: 19px; width: 48%">
                                                用户类别:</td>
                                            <td align="left" style="width: 3%; height: 19px">
                                                <asp:DropDownList CssClass="LoginLine" ID="UserType" runat="server" Width="154px">
                                                    <asp:ListItem Selected="true">管理员</asp:ListItem>
                                                    <asp:ListItem>专家</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                &nbsp;</td>
                                        </tr>
                                    </table>
                                    <table cellspacing="0" cellpadding="2" width="100%" border="0">
                                        <tbody>
                                            <tr>
                                                <td>
                                                    <div class="firsthr" style="height: 1px;">
                                                        <img src="" height="1" alt="" width="1" /></div>
                                                    <div class="secondhr" style="height: 1px;">
                                                        <img src="" height="1" alt="" width="1" /></div>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                    <div>
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td align="right" style="height: 27px">
                                                    <asp:ImageButton ID="BtnLogin" runat="server" ImageUrl="image/dditem6.gif" />&nbsp;
                                                    &nbsp;&nbsp;&nbsp;
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height: 14px">
                                                    &nbsp;</td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </form>
      

  2.   

    楼上的老大,我知道tbody是表格的正文部分,但是我这里有三个单元格,登陆只是其中的一块,还有就是怎么用,谢谢.
      

  3.   

    to:我知道tbody是表格的正文部分,但是我这里有三个单元格,登陆只是其中的一块,还有就是怎么用,谢谢.能不能说的清楚一些...我没看懂....
    我给你的那个程序就是登录界面
      

  4.   

    你不就给了我一个"帐号","密码","是否保存"这三个吗??(Button不算)
      

  5.   

    to gezichong:我还是没看懂,奥妙在哪,能否指点一二.:)
      

  6.   

    我用了一下,但是并没有改观,还是会撑大,不知道这样用对不对:
    <body bgColor="#66c6b0" MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
      <tbody>
         <table id="logo" height="109" cellSpacing="0" cellPadding="0" width="1002" border="0">
           <tr>
     <td class="logo_top" colSpan="3" height="82"><FONT face="宋体"></FONT></td>
           </tr>
           <tr>
    <td class="logo_left_bottom" width="175" height="15"></td>
    <td class="logo_middle_bottom" width="427"></td>
    <td class="logo_right_bottom" id="loginView" vAlign="middle" width="400">
       <div>
          <table id="loginview" cellSpacing="0" cellPadding="0">
                      <tr>   <td>帐号<asp:textbox id="UserName" Font-Size="Small" Height="18px" Width="80px" runat="server"></asp:textbox> 密码<asp:textbox id="Password" Font-Size="XX-Small" Height="16px" Width="80px" runat="server" TextMode="Password"></asp:textbox>
                    <asp:checkbox id="Auto" Font-Size="XX-Small" Height="16px" width="64px" runat="server" Checked="true"></asp:checkbox>保存
    <asp:button id="ForumLogin" Font-Size="X-Small" Height="16px" Width="40px" runat="server"></asp:button>
                      </td>      </tr>
              </table>
    </div>
           </td>
         </tr>
      </table>
    </tbody>
    </FONT>
    </form>
    </body>
    可是第二行第三个单元格里面的表格下面还是空了一块空白
      

  7.   

    这个用CSS控制一下不就行了,表象出来的东西都是在客户端的,你不用再cs文件做的。
      

  8.   

    把这一行:<table id="logo" height="109" cellSpacing="0" cellPadding="0" width="1002" border="0">中的height属性去除.看看
      

  9.   

    以你的代码..我试了一下....表格没有被撑大呀....要不你对表格loginview加个height发生看看
      

  10.   

    还有....
    修改如下:
    <table id="loginview" cellpadding=0 cellspacing=0 height="27px">//问题在这里
      <tr>
        <td>帐号
                     <asp:textbox id="UserName" runat="server" Width="80px"></asp:textbox>
            密码<asp:textbox id="Password" runat="server" TextMode="Password" Width="80px" Height="16px" Font-Size="XX-Small"></asp:textbox>
                     <asp:checkbox id="Auto" runat="server" Checked="true" Width="64px" Height="16px" Font-Size="XX-Small"></asp:checkbox>
                     保存
    <asp:button id="ForumLogin" runat="server" Width="40px" Height="16px" Font-Size="X-Small"></asp:button>
        </td>
      </tr>
    </table>
    <table id="table1" runat="server" cellpadding="0" cellspacing="0" border="0">
    </table>
    成功登录后即可设置loginview.visible=false..
    而在定义一个htmltablerow
    如:
    VB程序:
    dim R as new htmltablerow
    dim RC as new htmltablecell
    rc.innertext="欢迎进入我的网站"
    rc.height=25
    rc.colspan=3  //这个数字可能要修改一下..
    r.cells.add(rc)
    me.table2.rows.add(r)
    就可以了
      

  11.   

    //*****没得那么复杂吗//*****你在前台做一下处理就可以了<%if(LoginUserCode=="" || LoginUserCode==null)%>
    <%{%>
        显示用户登陆表单<%}%>
    <%else{%>
       显示登陆成功
    <%}%>
      

  12.   

    我觉得用CSS控制一下应该可以!
      

  13.   

    在TABLE标签中 加入 style=border-collapse:collapse 即可解决 接分,,,,,
      

  14.   

    谢谢各位老大了,接分,csdn真是好啊,在此也一并感谢csdn.
      

  15.   

    试了Edisoncat的方法,见效,不错.顶的人都有分,当然给的分不一样.
    to zhangxiaopin:显示表单是什么语句呢,visible=true吗?
    可是如果只是不可见的话,他们还是占地方的,还句话说,是不可以覆盖.因为我的登陆是放到导航栏上面的,所以要节省地方.另外,在这里再继续加分40分,实现注销功能以及修改用户资料功能(放心,给大家的分一定会给的,只是现在不能揭帖,要继续,所以,暂时记帐)
    我现在能实现登陆之后显示欢迎某某用户了,但是要做注销,所以加了一些代码,增加了一个注销按钮,但是这个按钮的事件不知怎么联系起来.还准备增加一个修改用户资料的链接,但是能显示出来,但是不能点击链接.
    代码:
    1 login.ascx:
    <asp:table id="logo" style="POSITION: absolute; TOP: 0px; BORDER-COLLAPSE: collapse" BackImageUrl="../css/css1/logo.jpg" runat="server" Width="1002px" Height="109px" HorizontalAlign="Center">
      <asp:TableRow Width="1002px" Height="109px">
         <asp:TableCell Height="82px" ColumnSpan="3" Width="1002px"></asp:TableCell>
      </asp:TableRow>
      <asp:TableRow Width="1002px" Height="27px">
          <asp:TableCell Height="27px" Width="175px"></asp:TableCell>
          <asp:TableCell Height="27px" Width="407px"></asp:TableCell>//留给导航栏
          <asp:TableCell VerticalAlign="Top" Height="27px" Width="420px" HorizontalAlign="Right" ID="loginview">帐号
    <asp:TextBox runat="server" Height="18px" Width="80px" Font-Size="Small" ID="UserName"></asp:TextBox>密码
    <asp:TextBox runat="server" Height="16px" TextMode="Password" Width="80px" Font-Size="XX-Small" ID="Password"></asp:TextBox>
    <asp:CheckBox runat="server" Width="10px" Checked="True" ID="Auto" Height="16px" Font-Size="XX-Small"></asp:CheckBox>保存
    <asp:Button runat="server" Text="登陆" Width="40px" ID="ForumLogin" Height="18px" Font-Size="X-Small"OnClick="ForumLogin_Click"></asp:Button>
           </asp:TableCell>
        </asp:TableRow>
    </asp:table>2 login.cs:
    private void Page_Load(object sender, System.EventArgs e)
    {
      if(!IsPostBack) 
      {
         string UserInfo=HttpContext.Current.User.Identity.Name;
         if(UserInfo!="")
         { logo.Rows[1].Cells[2].Controls.Clear();//清楚登陆的控件
    HtmlTable tb=new HtmlTable();
    HtmlTableRow tr=new HtmlTableRow();
    HtmlTableCell td=new HtmlTableCell();
    td.InnerText="欢迎回家,"+userInfo;//显示欢迎信息
    HtmlTableCell td2=new HtmlTableCell();
    td2.InnerHtml="<INPUT type=button value=loginout onclick='loginout' id=loginout name=loginout runat='server'>";//增加注销按钮-但是按钮没反应,去掉 onclick='loginout' 也不行
    HtmlTableCell td3=new HtmlTableCell();
    td3.InnerHtml="<asp:HyperLink id='HyperLink1' runat='server' NavigateUrl=www.163.com>用户中心</asp:HyperLink>";//增加用户资料中心-点击"用户中心"没反应
    tr.Cells.Add(td);
    tr.Cells.Add(td2);
    tr.Cells.Add(td3);
    tb.Rows.Add(tr);
    logo.Rows[1].Cells[2].Controls.Add(tb);
          }
       }
    }public void loginout()//换成loginout_click(object sender, System.EventArgs e)或者loginout_click()也不行
    {

    FormsAuthentication.SignOut();
    Session.Abandon();
    page.Redirect(default.aspx);
    }问题如上:
    1 是否是引号的嵌套问题
    2 是否是因为动态增加的注销控件与链接控件无法调用事件
    3 如果是注销之后,要再恢复原来的几个登陆控件,怎么做
    4 如果用visibel=false跟true控制,会不会不可以重复,撑大
      

  16.   

    to:td2.InnerHtml="<INPUT type=button value=loginout onclick='loginout' id=loginout name=loginout runat='server'>";//增加注销按钮-但是按钮没反应,去掉 onclick='loginout' 也不行改成:
    Button bt=new Button;
    bt.Text="注消";
    bt.Click+=new System.EventHandler(bt_Click);
    td2.Controls.Add(bt)下面再写一个函数:
    Private Void bt_Click(Object Sender,EventArgs e){}
      

  17.   

    to:gezichong(鸽子虫)没错,你的是对的.
    我昨晚后面也找到了,原来这个是动态控件的属性要用委托的.链接也是同样的道理:
    string UserInfo=HttpContext.Current.User.Identity.Name;
    if(UserInfo!="")
       {
    logo.Rows[1].Cells[2].Controls.Clear();
    HtmlTable tb=new HtmlTable();
    HtmlTableRow tr=new HtmlTableRow();
    HtmlTableCell td=new HtmlTableCell();
    td.InnerText="欢迎回家,"+user[2];
    td.Attributes.Add("Font-Size","XX-Small");
    Button btnLoginOut=new Button();
    btnLoginOut.Text="注销";
    btnLoginOut.Click+=new EventHandler(btnLoginOut_Click);
    HtmlTableCell td2=new HtmlTableCell();
    td2.Controls.Add(btnLoginOut);
    HyperLink linkUserInfo=new HyperLink();
    linkUserInfo.Text="用户中心";
    linkUserInfo.NavigateUrl="http://www.163.com";
    HtmlTableCell td3=new HtmlTableCell();
    td3.Controls.Add(linkUserInfo);
    tr.Cells.Add(td);
    tr.Cells.Add(td2);
    tr.Cells.Add(td3);
    tb.Rows.Add(tr);
    logo.Rows[1].Cells[2].Controls.Add(tb);
    } 至此,整个动态登陆,欢迎,注销控件已经完工,希望给有需要的人参考,同时也感谢所有顶贴的人,接分...