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

I have 2 questions

  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

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

有帮助吗?

解决方案

<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 ?

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 ?

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

其他提示

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

<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.

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.

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

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.

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

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

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;
        }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top