I have a text box in a page. Whose visibility is set false from the server side. Now I want to make it visible from client side by using java-script. (Any post back or parti
set the style["visibility"] = "hidden"
on the server side.
I.E. in c# btnSave.style["visibility"] = "hidden";
It will get the button rendered and therefore on the client side this element is accessible.
On the client side change the visibility style to visible.
$('#btnSave).css("visibility", "visible");
Once control is marked as invisible at server side, no mark-up (html) is emitted for it. So it cannot be made visible at JS, because it (corresponding html) does not exists at client side.
Instead of making invisible at server side, you need to emit a start-up script to hide it on client side.
If you set the control visible=false
it will not render at client side, But there is a tricky solution, that will accomplish the same thing.
In your page load, where you are set Visible=false
, you can set the style
to display:none
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Attributes.Add("style", "display:none");
}
It will render the control in client side, but user can't see and then you can visible the control in Javascript function to set style Diplay:block
, LIKE...
document.getElementById('<%=TextBox2.ClientID %>').style.display = 'block';