I am working on ASP: NET C #. I have an imageButton hidden in my MasterPage, for this I used a class defined in a style sheet. In the design mode I see that the control is hidden but when loading the page, the control appears visible.
What I want to do is that if the user is not logged in, do not see the button and in case you are logged in you can see it.
I already tried with:
ImageButton.visible = false; // but it does not work
<asp:UpdatePanel ID="updMiImageButton" runat="server">
<ContentTemplate>
<div class="cssMiImageButton" id="divMiImageButton">
<asp:ImageButton ID="MiImageButton" runat="server" ImageAlign="Right" CssClass="cssMiImageButton" Height="50px" ImageUrl="~/Imagenes/miImagen_isologo.gif" Width="50px" OnClick="MiImageButton_Click" BorderStyle="None"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>
I leave the aspx and aspx.cs code.
What I want is that when the user is logged in, see the button, for this I tried to set the css property of the button to visible from the Page_Load but it did not work either:
protected void Page_Load(object sender, EventArgs e)
{
MiImageButton.Style["Visibility"] = "hidden";
if (!Page.IsPostBack)
{
try
{
if (this.usuarioLogin != null)
{
this.ArmarMenu();
MiImageButton.Style["Visibility"] = "visible";
}
}
catch (Exception ex)
{
log.Error("Site.Master:Page_Load", ex);
this.lblMensaje.Text = msgErrorGenerico;
}
}
}
Update
I corrected the code with the help of @Thiago Loureiro. Now the button can not be seen when the page is started but the button is not visible to the user.
I leave the corrected code, add "UpdateMode" to the UpdatePanel and the updMiImageButton.Update () ;.
I leave the corrected codes
Aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
MiImageButton.Style["Visibility"] = "hidden";
updMiImageButton.Update();
if (!Page.IsPostBack)
{
try
{
if (this.usuarioLogin != null)
{
this.ArmarMenu();
MiImageButton.Style["Visibility"] = "visible";
updMiImageButton.Update();
}
}
catch (Exception ex)
{
log.Error("Site.Master:Page_Load", ex);
this.lblMensaje.Text = msgErrorGenerico;
}
}
}
Aspx:
<asp:UpdatePanel ID="updMiImageButton" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<div class="cssMiImageButton" id="divMiImageButton">
<asp:ImageButton ID="MiImageButton" runat="server" ImageAlign="Right" CssClass="cssMiImageButton" Height="50px" ImageUrl="~/Imagenes/miImagen_isologo.gif" Width="50px" OnClick="MiImageButton_Click" BorderStyle="None"/>
</div>
</ContentTemplate>
</asp:UpdatePanel>