0

我在 aspx 页面上有服务器端控件,如文本框、dropdownlsit 等,我的目标是在页面加载期间隐藏它们。

使用下面的代码,控件在页面加载期间被隐藏,但我注意到闪烁。所需的输出应消除此控制闪烁。任何帮助是极大的赞赏。

var ispostBack =false;
function pageLoad() {
    $(document).ready(function () {
        HideCtrls();
//Some other code here
     }

function HideCtrls()
{
    document.getElementById("cph1_divSear").style.setAttribute('display', '')
    if (document.getElementById("cph1_txtSearch"))
    {
        document.getElementById("cph1_txtSearch").style.setAttribute('display', 'none')
        document.getElementById("cph1_txtkey").style.setAttribute('display', 'none')
        document.getElementById("cph1_hypProjNo").style.setAttribute('display', 'none')
        document.getElementById("cph1_ddlSeaSingle").style.setAttribute('display', 'none')
         document.getElementById("cph1_txtSeaStart").style.setAttribute('display', 'none')
        document.getElementById("cph1_txtSeaEnd").style.setAttribute('display', 'none')
        document.getElementById("cph1_txtSeFLike").style.setAttribute('display', 'none')
        document.getElementById("cph1_imgSeaSt").style.setAttribute('display', 'none')
        document.getElementById("cph1_txtSeTLike").style.setAttribute('display', 'none')
        document.getElementById("cph1_imgSeaEnd").style.setAttribute('display', 'none')
        document.getElementById("cph1_txtPersonnel3").style.setAttribute('display', 'none')
        document.getElementById("cph1_ImageButton3").style.setAttribute('display', 'none')
        document.getElementById("likeFID").style.setAttribute('display', 'none')
        document.getElementById("likeTID").style.setAttribute('display', 'none')
        document.getElementById("dtFID").style.setAttribute('display', 'none')
        document.getElementById("dtTID").style.setAttribute('display', 'none')
    }
}

<div id="divSear" runat="server" class="cols4Search">
                            <span>
                                <asp:TextBox ID="txtSearch" runat="server" Width="350px"></asp:TextBox>
                                <asp:TextBox ID="txtkey" runat="server" onblur="ClearHelp()" onfocus="JavaScript:showhelp('Search_1001')"
                                    Width="400px" MaxLength="150"></asp:TextBox></span> <span style="display: none;">
                                        <asp:HyperLink ID="hypProjNo" runat="server" Target="_blank" ForeColor="Blue">View</asp:HyperLink>
                                    </span><span>
                                        <asp:DropDownList ID="ddlSeaSingle" runat="server" AutoPostBack="True">
                                        </asp:DropDownList>
                                    </span><span id="likeFID">>=<asp:TextBox ID="txtSeFLike" runat="server" MaxLength="9"></asp:TextBox></span>
                            <span id="likeTID"><=<asp:TextBox ID="txtSeTLike" runat="server" MaxLength="9"></asp:TextBox></span>
                            <span id="dtFID">>=<asp:TextBox ID="txtSeaStart" runat="server" Width="85px"></asp:TextBox></span>
                            <span>
                                <asp:ImageButton ID="imgSeaSt" runat="server" CssClass="dateicon" ImageUrl="~/Images/date_icon.png" /></span>
                            <span id="dtTID"><=<asp:TextBox ID="txtSeaEnd" runat="server" Width="85px"></asp:TextBox></span>
                            <span>
                                <asp:ImageButton ID="imgSeaEnd" runat="server" CssClass="dateicon" ImageUrl="~/Images/date_icon.png" /></span>
                            <span>
                                <asp:TextBox ID="txtPersonnel3" runat="server" CssClass="textbox" onblur="ClearHelp()"
                                    Width="160px" onfocus="JavaScript:showhelp('AdminUserDetails_1001')"></asp:TextBox></span>
                            <span>
                                <asp:ImageButton ID="ImageButton3" runat="server" ImageUrl="~/Images/searchtool.png"
                                    ToolTip="Select User" CssClass="iconalign" /></span>
                            <br />
                            <asp:Label ID="lblNote" Visible="false" CssClass="Notelabel" runat="server" />
                        </div>
4

1 回答 1

0

隐藏服务器上的所有控件,在需要时在客户端显示它们,这样就不会出现显示一段时间后隐藏控件的问题

在 HTML 中

 <asp:TextBox ID="txtSearch" style="display:none" Visible="False" Width="350px"></asp:TextBox> 

或在代码后面

 txtSearch.Attributes.Add("style", "display:none"); = "false";

并在需要时用 javascript 显示它们

if (document.getElementById("cph1_txtSearch"))
{
    document.getElementById("cph1_txtSearch").style.setAttribute('display', 'block')
    //Similarly you can show all field which are required to be shown
    // .........
}
于 2012-05-08T04:54:14.573 回答