MasterPage中找尋控件

<script language="javascript">
    function ShowType(obj,flag)//需要傳入一個客戶端的ID號,這裡和正常網頁不一樣,Masterpage會在客戶ID中加"CTL00_Content1_",所以如此處理
    {
        var panel=document.getElementById(obj);
        if(flag==0)
            {
                panel.style.display="none";
            }
              else
              {
                panel.style.display="block";
              }
        //panel.style.dispaly='block';
    }
</script>
引用方式
<Input type="button" value="New Product Type" OnClick="ShowType('<% =pnlProductType.ClientID %>',1);" />
<asp:Panel ID="pnlProductType" runat="server">
                                      
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tr>
                                                <td>
                                                    <span>Product Type Name:</span>
                                                </td>
                                               </tr>
                                               <tr>
                                                <td>
                                                    <asp:TextBox ID="txtProductTypeName" runat="server" CssClass="txtField"></asp:TextBox>
                                                </td>                                                
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Button ID="btnConfirmtype" runat="server" Text="Sure" OnClick="btnConfirmtype_Click" />
                                                    <input type="button" value="Cancel" OnClick="ShowType('<% =pnlProductType.ClientID %>',0);document.getElementById('<% =txtProductTypeName.ClientID %>').value='';" id="Button1"/>
                                                </td>
                                            </tr>
                                        </table>
                                       
                                    </asp:Panel>


同時,Panel的屬性Visible不能使用,否則客戶端無法找到。
C#代碼中可以如此寫:
pnlProductType.Attributes.CssStyle.Add("display", "none");//不顯示
pnlProductType.Attributes.CssStyle.Add("display", "block");//顯示
posted @ 2008-02-13 16:57  马建康  阅读(364)  评论(0编辑  收藏  举报