C#: Panel Won't (Un)Hide

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spamguy
    New Member
    • Sep 2007
    • 42

    #1

    C#: Panel Won't (Un)Hide

    I have a panel that I want to act as an extension of ValidationSumma ry. Some fields are simply too complex for a RegEx to analyse, so I check them on a button click event and pass error messages to a Label contained in the aforementioned Panel.

    Trouble is, the Panel doesn't unhide! A rougher alternative I tried, if (!IsPostBack), doesn't work either.

    [code=html]
    <form id="Form1" method="POST" action="" runat="server">
    <div style="width:10 0%">
    <asp:Validation Summary ID="ValidationS ummary1" CssClass="error Message" runat="server" ForeColor="Blac k" />
    </div>
    <div style="width:10 0%">
    <asp:Panel ID="customValid ationSummary" runat="server" CssClass="error Message">
    <asp:Label ID="msg" runat="server" />
    </asp:Panel>
    </div>[/code]

    [code=cpp]
    protected void btnSubmit_Click (object sender, EventArgs e)
    {
    msg.Text = ValidateFields( ); // currently set to do nothing but return an arbitrary nonempty string

    if (msg.Text == "")
    {
    // send data on its merry way
    }
    else
    {
    msg.Visible = true;
    }
    } // end function[/code]
    Last edited by Plater; Feb 27 '08, 06:03 PM. Reason: made code easier to read
  • spamguy
    New Member
    • Sep 2007
    • 42

    #2
    In addition:

    The Label inside the Panel doesn't seem to want to change, either. If I leave the Panel visible and tell the text to change to an arbitrary string on button click, it doesn't. Something's fishy, but I don't know what.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      EDIT: Double Oops. Will have to get back to you...

      An asp:panel maps back to an html DIV, do you need to nest them like that?

      Comment

      • spamguy
        New Member
        • Sep 2007
        • 42

        #4
        Originally posted by Plater
        EDIT: Double Oops. Will have to get back to you...

        An asp:panel maps back to an html DIV, do you need to nest them like that?
        <div> any thinner than 100% width centres differently from <span>. The only way I've found to centre a <div> is to nest them:

        [code=html]
        <div style="width:10 0%">
        <div style="margin-left:auto;margi n-right:auto">Hi there</div>
        </div>
        [/code]

        Comment

        • spamguy
          New Member
          • Sep 2007
          • 42

          #5
          I think I figured out the source of the problem.

          When there are validation controls in place, the page blocks a button click event when something isn't filled in right and pulls up a validation dialog using Javascript or somesuch. As long as there's a validation violation, there's no postback and no call of Button_Click() -- anything I put in the codebehind to check data myself won't get used.

          So now the question becomes: can I circumvent this to have personalised validation and ASP validation controls report at the same time?

          Comment

          Working...