在 ASP.NET 上隐藏面板和 Div 让我抓狂

发布于 2024-09-06 15:07:34 字数 185 浏览 4 评论 0原文

在谷歌上搜索,我肯定找不到非JavaScript的方式来显示和隐藏我的面板/更新面板。

我确实有面板和更新面板,我想在单击按钮后动态显示/隐藏它们,最好不使用 javascript,或者如果是的话,使用 jQuery。

我发现的所有示例都消耗了大量代码,老实说,我不想仅仅因为这个就毁掉我的代码。

有想法吗?

Searching on google, i deffinitly can't find a non-javascript way to show and hide my panel/updatepanel.

I do have panels and updatepanels, I want to show/hide them on the fly, after a button click, preferably without javascript, or if so, with jQuery.

All the examples I found consumes a lot of code and honestly I don't want to crap out my code just because of this.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

用心笑 2024-09-13 15:07:34

使用 jQuery 并不需要太多代码:

<input type="button" onclick="$('#blah').toggle();" />
<someelement id="blah"></someelement>

对于 ASP.NET(根据您的代码进行修改):

<asp:Button ID="btnSubmit" runat="server" CssClass="button-login" OnClientClick="$('#login').toggle();" />

It doesn't really take a lot of code with jQuery:

<input type="button" onclick="$('#blah').toggle();" />
<someelement id="blah"></someelement>

For ASP.NET (modified from your code):

<asp:Button ID="btnSubmit" runat="server" CssClass="button-login" OnClientClick="$('#login').toggle();" />
看透却不说透 2024-09-13 15:07:34

您也可以使用多视图和内部的几个视图。通过这样做,您可以使用按钮控件来选择要显示的视图(面板)。下面的代码将在包含两个图像标签的两个视图之间切换。
ASP.NET 表单 (HTML)

<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
<div>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
  <asp:View ID="View1" runat="server">
    <imgage = "my picture">    //add image tage here
  </view>
  <asp:View ID="View2" runat="server">
    <imgage = "your picture">  //add image tage here
  </view>
</asp: Multiview>
</div>

代码隐藏

Private button click toggleImageView

If multiview1.ActiveViewIndex=0 then
   multiview1.ActiveViewIndex=1
ElseIf 
   multiview1.ActiveViewIndex=1 then
   multiview1.ActiveViewIndex=0
EndIf

您还可以使用列表框来选择要动态显示的视图,如下所示
但请注意,您选择要显示的视图的控件应该位于多视图控件之外,并且也应该在页面加载时呈现

<asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                runat="server" AutoPostBack="True">
  <asp:ListItem Value="0">View 1</asp:ListItem>
  <asp:ListItem Value="1">View 2</asp:ListItem>
</asp:DropDownList><br />

You could as well use the multi view and a couple of views inside. By doing this you can use a button control to choose which view (panel) is to be displayed. The code below will toggle between two views containing two image tags.
ASP.NET Form (HTML)

<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
<div>
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
  <asp:View ID="View1" runat="server">
    <imgage = "my picture">    //add image tage here
  </view>
  <asp:View ID="View2" runat="server">
    <imgage = "your picture">  //add image tage here
  </view>
</asp: Multiview>
</div>

CODE BEHIND

Private button click toggleImageView

If multiview1.ActiveViewIndex=0 then
   multiview1.ActiveViewIndex=1
ElseIf 
   multiview1.ActiveViewIndex=1 then
   multiview1.ActiveViewIndex=0
EndIf

You may also use a list box to select which view to display on the fly like this
But note that your control o select which view to be displayed should be outside the multiview control and also be rendered on page load

<asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                runat="server" AutoPostBack="True">
  <asp:ListItem Value="0">View 1</asp:ListItem>
  <asp:ListItem Value="1">View 2</asp:ListItem>
</asp:DropDownList><br />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文