views:

565

answers:

4

I have some code like this

<asp:Button ID="cancelDummyButt" runat="server" CausesValidation="False" 
    Text="cancel" onclick="cancelDummyButt_Click" Enabled="True" />

(Javascript:)

buttid = '<%=cancelDummyButt.ClientID.ToString%>';
eltoclick = document.getElementById(buttid);
eltoclick.click();

The server-side code is not called. What is wrong? It goes OK until the "click". What is the best way to debug?

(This is to get the right postback from an iframe within an updatepanel)

A: 

First of all, you have a mistake in this line :

buttid = '<%= cancelDummyButt.ClientID.ToString() %>';

my recommendation is that, place your javascript code to code behind and then register to page like that :

string script = string.Format("var buttid = '{0}';", cancelDummyButt.ClientID);
if (!ClientScript.IsClientScriptBlockRegistered("myScript"))
{
    ClientScript.RegisterClientScriptBlock(typeof(_Default), "myScript", script, true);
}
Canavar
I think ToString without "()" is ok in VB.NET - anyway buttid and eltoclick got assigned correctly, as far as i could see
Olav
A: 

Solved - it was cause by a modal jQuerywindow!

(Would like some way around that, of course)

Olav

Olav
+1  A: 
iZ
+1  A: 

Programmatically invoking the click() event of a control does not fire the event handler function. You'll need to invoke it manually....

if(eltoclick.onclick())
  eltoclick.click();
Josh Stodola