getElementById question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have one button in the aspx page called btnSubmit which i need to disable
using javascript
the document.getElementById("btn_Submit").Enabled=false returns an error
and the
document.getElementById('_ctl0_ContentPlaceHolder1_btnSubmit').Enabled=false
works fine but how can i get that _ctl0_ContentPlaceHolder1_btnSubmit' ? now
i looked in the "view source" of the actual page

thanks,
akis
 
You can get the ID of the control on the clientside via the ClientID property
of the control. So when you render the script in your code do it in this way:
document.getElementById('" + myControl.ClientID + "');

At least this works for me.
 
Hi,
The reason script is not working because there is no property called
Enabled in JavaScript,
every one make this mistake. To disable a control use Disabled property


See the following link for HTML reference
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/dhtml_node_entry.asp

Can you see a property called Enabled...????

Hope the following code might help you...
<script language="JavaScript">

function test()

{

document.getElementById("Button1").disabled=true

}

</script>

<body onload="test()">

<form id="form1" runat="server" >

<div>


<br />

<asp:Button ID="Button1" runat="server" Text="Button" /></div>

</form>

</body>

vinu
 
don't you mean something more along the lines of:

document.getElementById("<%=myControl.ClientId%>");

Karl
 
thanks all three of you,
a compination of the answers gives me results

TextBox1.Attributes.Add("OnChange", "getElementById('"+Button1.ClientID+
"').disabled=true");
 
If it's done in the aspx file then do it your way, in the code behind file
when you render it somehow like output.write(...) then in my way. ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top