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");//顯示
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");//顯示
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步