Tommehh
Tommehh

Reputation: 956

UpdatePanel and panel visibility asp.net c#

I have two panels. Each panel contains an updatepanel. The first panel is a password Textbox.

I set the second panel's visibility on page_load to false. If the user enters the correct password, the second panel should be visible and the first panel shouldnd.

The code:

<asp:Panel ID="passwordPanel" runat="server">
      <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
      <ContentTemplate> 
          Geben Sie das Passwort ein:<br />
          <br />
          <asp:TextBox ID="txtPassword" AutoPostBack="false" runat="server" TextMode="Password"></asp:TextBox>
          <br />
          <br />
          <asp:Button ID="btnConfirmPassword" runat="server" AutoPostBack="true" Text="Senden" CssClass="button" OnClick="btnConfirmPassword_Click"/>
      </ContentTemplate>
      </asp:UpdatePanel>
  </asp:Panel>



  <asp:Panel ID="panelUploadDownload" runat="server">
    <h2>Upload Paketformeln CSV</h2>

    <input type="file" id="myFile" name="myFile" />

    <asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" CssClass="button" Text="Upload" />
    <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
        <ContentTemplate> 
            <br />
            <asp:Label ID="lblStatus" runat="server" Text="statusLabel"></asp:Label>
            <br />

            <asp:Panel ID="panelChanges" runat="server" CssClass="pnlCSS">
                <asp:Label ID="lblChangesHeader" runat="server" Font-Bold="True" ForeColor="Black" Text="Änderungen"></asp:Label>
                <br />
                <asp:Label ID="lblChanges" runat="server" ForeColor="#009900" Text="changes"></asp:Label>
                <br />
                <br />
                <asp:Button ID="btnConfirm" runat="server" OnClick="btnConfirm_Click" CSSClass="button" Text="Änderungen bestätigen" />
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <br />
    <br />
    <br />
      <h2>Download Paketformeln CSV</h2>
    <p><asp:Button ID="btnDownloadCsv" runat="server" OnClick="btnDownloadCsv_Click" Text="Download CSV" CSSClass="button"/></p>
  </asp:Panel>

And the C# code:

 protected void btnConfirmPassword_Click(object sender, EventArgs e)
        {
            if (txtPassword.Text == "XX")
            {
                uploadDownloadPanel.Visible = true;
                passwordPanel.Visible = false;
            }
        }

Load Event

protected void Page_Load(object sender, EventArgs e)
    {
        mainController = new MainController();
        setStatus("", Color.Black);
        lblChanges.Visible = false;
        lblChangesHeader.Visible = false;
        btnConfirm.Visible = false;
        panelChanges.Visible = false;
        panelUploadDownload.Visible = false;


    }

For some reason it doesnt work. Any clues? Triggers?

Upvotes: 1

Views: 2142

Answers (4)

sp_m
sp_m

Reputation: 2707

You can set your UpdateMode to Always of update panel within panelUploadDownload panel.It will work.

 <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">

Upvotes: 0

Tommehh
Tommehh

Reputation: 956

i just removed the updatepanel from the passwordPanel and it worked.

Upvotes: 1

Lali
Lali

Reputation: 2866

In your load event, do the following

if(IsPostback)
{
    uploadDownloadPanel.Visible = false;
}

Actually, every time when you press button, you load event also triggered

Upvotes: 0

DieVeenman
DieVeenman

Reputation: 457

The SecureString class doesn't allow you to see the value; that's the whole point of it. If you want to be able to work with the value entered into the PasswordBox, use the Password member of PasswordBox instead of the SecurePassword member:

 protected void btnConfirmPassword_Click(object sender, EventArgs e)
        {
            if (txtPassword.Password == "XX")
            {
                uploadDownloadPanel.Visible = true;
                passwordPanel.Visible = false;
            }
        }

Upvotes: 1

Related Questions