Disable a HTML Button

Posted by Ragha under ASP.NET on 4/1/2008 | Views : 3405 | Status : [Member] | Replies : 4
Hi


i have 2 html buttons in aspx page


one is open and other is close


my requirement is


the open button must be visible and close button must be invisible in page load of aspx


when i click on open the close button must be visible and open must be invisible


when close button gets visible the open button must be invisible


remeber the two buttons are html buttons

if any code is given it would be appreciated


thanks
sudha




Responses

Posted by: Srinu0411 on: 4/1/2008 [Member] Starter

Up
0
Down
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Button2.Visible = false;
}

}

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Visible = false;
Button2.Visible = true;
}

protected void Button2_Click(object sender, EventArgs e)
{
Button2.Visible = false;
Button1.Visible = true;
}

kaja srinivas

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ragha on: 4/1/2008 [Member] Starter

Up
0
Down
thanks srinu

but they are not server controls and i cannot get the reference in aspx.cs page


they are html buttons


if any solution please provide

thanks
sudha

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 4/1/2008 [Member] Starter

Up
0
Down
Lets say you have following buttons

<input type="button" id="btnOpen" value="Open" onclick="ShowHide(''open'')" />

<input type="button" id="btnClose" value="Close" onclick="ShowHide(''close'')" style="display:none;"/>


Now use following JavaScript code

<script language="JavaScript">

function ShowHide(todo)
{
if (todo == 'open')
{
document.getElementById('btnOpen').style.display = 'none';
document.getElementById('btnClose').style.display = '';
}
else
{
document.getElementById('btnOpen').style.display = '';
document.getElementById('btnClose').style.display = 'none';
}
}
</script>


Hope this will work.
Thanks

Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeks on: 4/18/2009 [Member] Bronze

Up
0
Down
If you want to get the reference of the HTML control in server side, you can write runat="server" in that control.

Else you can use Display 'none' property as Raja has specified

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response