.NET Framework Developer Center >
.NET Development Forums
>
JScript for the .NET Framework
>
IMG onclick error
IMG onclick error
- Hi all,
I have a little problem with an IMG on my HTML code. I assign an attribute onclick to a javascript method, it fails me with a javascript error notifying me that an object is expected, but I cannot resolve what exactly I'm doing wrong.
This is my code:
[vb Code] Me.btnCerrar.Attributes.Add("onclick", "javascript:qmCerrar();") [HTML Code] <table id="Table1" runat="server" border="0" cellpadding="0" cellspacing="0" class="cabeceraTabla" style="z-index: 106; left: 0px; width: 368px; position: absolute; top: 0px; height: 6px"> <tr> <td style="height: 19px; width: 372px;"> <asp:Label ID="labTituloLayFoto" runat="server" CssClass="etiquetaFiltro" Text="Añadir Fotografía" Style="z-index: 130; left: 5px; position: absolute; top: 3px" Width="109px"></asp:Label> </td> <td align="right" style="width: 0px; height: 19px; text-align: right;"> <img id="btnCerrar" runat="server" class="cursor" src="../Imagenes/imgBotonCerrar.gif" style="height:14px;width:15px;z-index: 102; left: 312px; position: absolute; top: 2px"/> </td> </tr> </table>
Programmer
Answers
- Hi Rohit,
I forgot to include the function in this thread but it exists in my original code as you write (only with an alert).
I've resolved the problem anyway. Just calling the same method that opens the iFrame including an if...else condition to close it.
I think we could close this thread.
Thanks a lot for your help (^^).
My Best Regards,
CarmenDev
Programmer- Marked As Answer byHarry ZhuMSFT, ModeratorMonday, May 25, 2009 2:23 AM
All Replies
- I tried your code, I do not get any error. The only difference that I added (which is not shown in your code sample):
<script language=javascript>
function qmCerrar()
{
alert('hello');
}
</script>
It seems you haven't written qmCerrar() function. - Hi Rohit,
I forgot to include the function in this thread but it exists in my original code as you write (only with an alert).
I've resolved the problem anyway. Just calling the same method that opens the iFrame including an if...else condition to close it.
I think we could close this thread.
Thanks a lot for your help (^^).
My Best Regards,
CarmenDev
Programmer- Marked As Answer byHarry ZhuMSFT, ModeratorMonday, May 25, 2009 2:23 AM
- hi,
in attributes u can ad ____ follows
Me.btnCerrar.Attributes.Add("onclick", "qmCerrar()")
dont use "javascript:". - Hi saravmani,
I also tried this too, but without results.
Thanks for your help (^^).
Best Regards,
CarmenDev
Programmer hi sorry for delay reply....i think u may got ans....if not try this.....
in aspx itself u can use the event.....
<img id="btnCerrar" runat="server" onclic="FunctionName()" class="cursor" src="../Imagenes/imgBotonCerrar.gif"...... />


