当visible设置为true时,不显示Asp:Label吗? [英] Asp:Label is not shown when visible is set to true?

查看:78
本文介绍了当visible设置为true时,不显示Asp:Label吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Web表单,其中包含几个列表框和一个搜索按钮.单击该按钮时,它将返回一个数据集.如果数据集包含记录,则将最初设置为false的asp:label设置为true,但这没有发生.如果数据集具有记录,并且visible属性设置为true,则标签仍然不会显示.

I have a simple web form which has a couple list boxes and a search button. When the button is clicked, it returns a DataSet. If the dataset contains records, I set the asp:label which is initially set to false to true, but this is not happening. If the dataset has records and the visible property is set to true, the label still does not show up.

我也尝试过将标签和其他几个控件放在html表中,并在表上设置runat ="server"属性,并更改其可见性,但是两者均不显示.

I have also tried putting the label and a couple other controls in an html table and setting a runat="server" attribute on the table and changing the visibility on that, but it does not show either.

这是aspx代码:

<table>
    <tr>
        <td>
        <asp:Label ID="lblSortBy" runat="server" Text="Sort By:" Visible="false">   
        </asp:Label>
        <asp:DropDownList
                        ID="ddlSortBy" 
                        runat="server" 
                        AutoPostBack="True" 
                        OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged">
        <asp:ListItem Value="Gross">Gross</asp:ListItem>
        <asp:ListItem Value="Population">Population</asp:ListItem>
        </asp:DropDownList>
        </td>
    </tr>
</table>

下面是单击按钮时的简化代码:

Here is simplified code behind when a button is clicked:

public void GetData()
{
    DataView dv = GetReportData().DefaultView;

    if(dv.ToTable().Rows.Count > 0)
     {
        lblSortBy.Visible = true;
     }
     else
     {
        lblSortBy.Visible = false;
     }
  }

我在一些ListBoxes和GridView周围有几个Update Panel,但没有Label and Dropdown.这会引起问题吗?

I have a couple Update Panels around some ListBoxes and a GridView, but not the Label and Dropdown. Would this cause an issue?

我做了一个测试,如果找到记录并且标签消失了,我将位于更新面板中的标签设置为false,因此如果它位于更新面板中,则它可以正常工作.

I did a test, I set a label that was in an update panel to false if records were found and the label disappeared, so it is working if it is in an update panel.

推荐答案

如果我没记错的话,您的标签应该存在于updatepanel上,因为就静态HTML页面而言,这是您唯一的一次当前标签存在,因此设置为不可见.您必须重新加载整个页面才能使其再次可见.

If I'm not mistaken, your label should exist on an updatepanel, because as far as the static HTML page is concerned, the one and only time that your current label exists, it's set to be not visible. You would have to reload the whole page to make it visible again.

这篇关于当visible设置为true时,不显示Asp:Label吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆