c# Webform - Button.Visible=false; behaving oddly.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • somacore
    New Member
    • Apr 2008
    • 24

    c# Webform - Button.Visible=false; behaving oddly.

    I have a webform in C#. This form has both a gridview and a formview. The formview displays the details of the selected gridview index. No problem there.

    On the formview is a button. When this button is clicked it sends an email to the DBAs asking for a database request to be run. This works as well.

    However I would like to idiot proof this webform. I would like to restrict DBA requests to only the sql that is in Code submitted, testing, or pre prod status. Code that is in Hold, Failed, or Pending DBA should not be requested.

    The simplest way to do this (I guess) would be to make the button invisible if the code status is one of the three listed. Simple enough.

    The problem is that the button only goes invisible once it is clicked. I would like the button to not be there at all if the TicketStatus matches one of the three.

    Help?

    In my codebehind I have the following (I just set it up for the "Hold" status for now to test):
    Code:
    protected void Page_Load(object sender, EventArgs e)
        {
            string TicketStatus = ((Label)FormView1.FindControl("F5Label")).Text;
            Button EmailButton = ((Button)FormView1.FindControl("Button1"));
            
            if(TicketStatus.Equals("Hold"))
            {
                EmailButton.Visible = false;
            }
        }
    And the ASP portion
    Code:
    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Request DB" />
  • nateraaaa
    Recognized Expert Contributor
    • May 2007
    • 664

    #2
    You may want to try adding code that will hide your button to the OnPreRender event of the page. Just before the page loads this event will fire.

    Nathan

    Comment

    • somacore
      New Member
      • Apr 2008
      • 24

      #3
      Wow, that worked like a champ.

      Thanks!

      Comment

      Working...