如何使用脚本根据aspx页面中的查询字符串隐藏用户控件。 我试过这个,但它没有用。
<%# (Request.QueryString["catl1"] == "ask_the_expert") ? ucTalkToExpert1.Visible = false : ucTalkToExpert1.Visible = true%>
<uc3:ucTalkToExpert ID="ucTalkToExpert1" runat="server" />
即使queryString是ask_the_expert,它仍然没有隐藏ucTalkToExpert1用户控件。
我无法触及后端代码。
更新
我没有源代码。
答案 0 :(得分:2)
在后面的代码中执行它会更清晰。
if(Request.QueryString["catl1"] == "ask_the_expert")
ucTalkToExpert1.Visible = false;
else
ucTalkToExpert1.Visible = true;
或者,如果您没有代码
<script language="c#" runat="server">
public void Page_Load(object sender, EventArgs e)
{
if(Request.QueryString["catl1"] == "ask_the_expert")
ucTalkToExpert1.Visible = false;
else
ucTalkToExpert1.Visible = true;
}
</script>
答案 1 :(得分:2)
您可以通过在其周围添加if
语句来破解aspx页面。
<% if (Request.QueryString["catl1"] != "ask_the_expert") { %>
<uc3:ucTalkToExpert ID="ucTalkToExpert1" runat="server" />
<% } %>
答案 2 :(得分:1)
ASPX:
<uc1:ucTalkToExpert1 ID="ucTalkToExpert11" runat="server" Visible=<%# Request.QueryString["catl1"] == "ask_the_expert" ? false : true %> />
代码背后:
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}
答案 3 :(得分:0)
更改
<uc3:ucTalkToExpert ID="ucTalkToExpert1" runat="server" />
到
<uc3:ucTalkToExpert Visible="false" ID="ucTalkToExpert1" runat="server" />