javascript 如何显示和隐藏 html 字段集以及从 Asp.Net 代码后面设置图例文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19828649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 16:57:24  来源:igfitidea点击:

How to show and hide html fieldset And also Set legend text from Asp.Net Code behind

c#javascripthtmlasp.netrad

提问by Arun CM

I have a filedset and legend inside that with "some text" and inside this fieldset i have a GRID

我有一个带有“一些文本”的文件集和图例,在这个字段集内我有一个 GRID

I have 2 questions

我有2个问题

  1. How to show ? hide html filedset from code behind, i tried the following way to show and hide the field set

    a) set runat="server"--but it didnt work b) i pasted the fieldset inside an asp.net panel and tried to show/hide the panel, it also didnt work

  2. How to set text for legend from code behind , ie I want to set "some text" + Value_Form_Code Behind AS leged text
  1. 如何显示?从后面的代码中隐藏 html 文件集,我尝试了以下方法来显示和隐藏字段集

    a) 设置 runat="server"--但它不起作用 b) 我将字段集粘贴到 asp.net 面板中并尝试显示/隐藏面板,它也不起作用

  2. 如何从后面的代码中设置图例的文本,即我想设置“一些文本”+ Value_Form_Code 在 AS 后边的文本

Note :I am using "Rad Ajax Manager" and Rad Ajax LoadingPanel

注意:我正在使用“Rad Ajax Manager”和 Rad Ajax LoadingPanel

回答by meda

<asp:Panel ID="Panel1" runat="server" >                
<fieldlset>
<legend><asp:Label id="Label1" runat="server" /></legend>
</fieldset>
</asp:Panel>

How to show /hide html filedset from code behind ?

如何从后面的代码中显示/隐藏 html 文件集?

Panel1.Visible = true; // or false

How to set text for legend from code behind , ie I want to set "some text" + Value_Form_Code Behind AS legend text ?

如何从后面的代码设置图例文本,即我想在 AS 图例文本后面设置“一些文本”+ Value_Form_Code?

Label1.Text = String.Format("some text {0}",Value_Form_Code);

回答by Nils

it should also be possible to add an IDand runat="server"to your fieldset and control visibility through code-behind. Just remember to write 'ID' in upper letters.

还应该可以向您的字段集添加IDrunat="server",并通过代码隐藏控制可见性。请记住用大写字母写“ID”。

<fieldset ID="myFieldset" runat="server">

You won't be able to control the legend text, unless you give it an ID and runat itself. But visibility is absolutely possible.

您将无法控制图例文本,除非您为其提供 ID 和 runat 本身。但是可见性是绝对可能的。

The upside of this approach is: no needless html markup (Panel would be extra div). The downside: fieldsets are not really asp-controls, so some things might give you exceptions, so use carefully.

这种方法的优点是:没有不必要的 html 标记(面板将是额外的 div)。缺点:fieldsets 并不是真正的 asp 控件,所以有些东西可能会给你例外,所以要小心使用。

I use this approach only when I want to prevent controls from rendering at all in certain cases (visibility does that).

仅当我想在某些情况下完全阻止控件呈现时才使用这种方法(可见性就是这样做的)。

回答by milan m

1:I think you should put your fieldset inside an asp:panel and then hide/show the panel from your code-behind. This will automatically hide/show your fieldset.

1:我认为您应该将字段集放在 asp:panel 中,然后从代码隐藏中隐藏/显示面板。这将自动隐藏/显示您的字段集。

2:As far as setting the legend text is concerned, just set the legend with runat="server" and set the code from codebehind.

2:就设置图例文本而言,只需将图例设置为 runat="server" 并从 codebehind 设置代码。

回答by Bhavesh Kachhadiya

When you set the 'GroupingText'property of the asp:panelcontrol then It will render as the 'fieldset'tag in HTML and whatever set in the 'GroupingText'property value is rendered as the <legend>tag.

当您设置asp:panel控件的“GroupingText”属性时,它将呈现为HTML 中的“fieldset”标记,并且“GroupingText”属性值中设置的任何内容都将 呈现为标记。<legend>

I think following code will help you as per your requirement.

我认为以下代码将根据您的要求帮助您。

For Design side,

对于设计方面,

<asp:Panel runat="server" ID="Panel1" GroupingText="This is legend">
       <h4>Your Content Goes Here</h4>
    </asp:Panel>
    <br />
    <asp:Button ID="btnHidePanel" runat="server" Text ="Hide FieldSet" onclick="btnHidePanel_Click" />
    <asp:Button ID="btnShowPanel" runat="server" Text ="Show FieldSet" onclick="btnShowPanel_Click" Visible="false" />

For Code-behind try this,

对于代码隐藏试试这个,

protected void btnHidePanel_Click(object sender, EventArgs e)
        {
            Panel1.Visible = false;
            btnHidePanel.Visible = false;
            btnShowPanel.Visible = true;
        }

        protected void btnShowPanel_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
            Panel1.GroupingText = "This Legend Text Has been Changed";
            btnHidePanel.Visible = true;
            btnShowPanel.Visible = false;
        }