Re: Problem with Javascript in a UserControl

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Make a look at the HTML generated by your code and find your checkbox ID.

Did it looks some diferent from the original??? Sure it is.

The framework add the name of the control to input ids in generated HTML.

That's why your javascript don't works.




tshad wrote:
I get an error when running my Javascript inside my UserControl. It works fine if I put the UserControl Data directly in my Web Page.

The stripped down code is:

<script language=javascript>
function CheckQuestion()
{
var checkBox = document.getElementById('SecurityStandard');
alert("checkBox.checked = " + checkBox.checked);
}
</script>

Mozilla doesn't seem to have a problem, but IE gives me this error:

Error: Object required.

The object in the UserControl is:

<asp:RadioButton ID="SecurityStandard" Checked="true" GroupName="SecurityQuestion" runat="server" Text=" Secret Question:"/>

From View Source:

<input id="_ctl0_SecurityStandard" type="radio" name="_ctl0:SecurityQuestion" value="SecurityStandard" checked="checked" onclick="return CheckQuestion();" />

On the page that does work:

<input id="SecurityStandard" type="radio" name="SecurityQuestion" value="SecurityStandard" checked="checked" onclick="return CheckQuestion();" />

For some reason the radio buttons Name is appended with "_ctl0:" in the UserControl and nothing is appended in the regular page.

I am used to seeing this from DataGrids, but not as a regular control on the page.

How would I hande the Javascript in this case?

Thanks,

Tom


.



Relevant Pages

  • .Net Remoting UserControl as Object in HTML page
    ... I've had some problems with a .Net UserControl that I wrote. ... control communicates with a .Net server using .Net Remoting. ... Make sure my HTML page is in the root directory of my machine's ...
    (microsoft.public.dotnet.framework.remoting)
  • Re: multiple row updates in MYSQL using HTML
    ... > if the checkbox is checked incase you are updating most of the records ... >>all to another perl script to perform the update. ... >>I basically need maintenance of one table with unlimited rows containing ... HTML? ...
    (comp.lang.perl)
  • VB.Net UserControl in HTML Object Tag
    ... I am hosting .Net UserControls in HTML pages with Object Tags. ... The HTML page uses an Object tag whose classid is ... Put the UserControl DLL in the same directory as the HTML page. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: .Net Remoting UserControl as Object in HTML page
    ... > I've had some problems with a .Net UserControl that I wrote. ... Make sure my HTML page is in the root directory of my machine's ... The container does not catch the event. ...
    (microsoft.public.dotnet.framework.remoting)
  • Calling a local .NET UserControl from a local HTML page
    ... I am hosting .Net UserControls in HTML pages with Object Tags. ... The remote objects execute callbacks via sponsor objects. ... Put the UserControl DLL in the same directory as the HTML page. ...
    (microsoft.public.dotnet.general)