Thursday, 11 November 2010

How to hide Client side Control on Server Side in C#

Recently i was doing a asp.net programming and faced a interesting issue, I had a client side (html input button) button control and wanted to hide in C# on the basis of certain conditions. After a long research i found a solution.

To hide HTML button from C#, just add the button inside the ASP.NET Panel control and hide the ASP.NET Panel.

ASP.NET Code:
<asp:panel id="pnlSave" Runat="server"><input id="btnSave" onclick="javascript:btn_Save()" type="button" value="Save"/></asp:panel>

C# Code:
 pnlSave.Visible = false;

This is the simplest solution while you can go for:
1. Add a hidden field in ASP Page and after calculation assign true or false to this hidden field.
2. on the basis of this hidden field value hide or show the HTML button.

No comments:

Post a Comment