Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling onclick event through .aspx.cs page 1

Status
Not open for further replies.

Craftor

Programmer
Feb 1, 2001
420
NZ
Hi all

I'm trying to call a JavaScript function through my CodeBehind page of my .aspx WebForm. I have added the following code in the Page_Init event:

btnDelete.Attributes.Add ("onclick", "return CheckDeletion(this.form);");

and btnDelete is a WebForms button control.

The code for the onclick is a direct cut and paste of the code that appeared for the onclick event of a standard input button control.

When I try to run it, it first gives me the error:

Expected '('

No matter if I click Yes/No to debug, the rest of the page loads fine ...

When I click my Delete button, it gives me the following error:

Microsoft JScript runtime error: Object expected

and it's breaking on the following line of code: onclick="return CheckDeletion(this.form);"

I've tried passing the actual form name, but it still gives me the exact same error.

If I make the button a normal <input> control, and put the code behind the onclick event, it runs fine :-(

Any ideas on this please?

Thanks as always

Craftor
:cool:
 
The problem is on your javascript... we can't help you if you don't post your javascript.

Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
I didn't post it as it works fine if I call it as javascript ... i.e. putting it behind a straight HTML button ... but here it is ... If anyone would rather me post this in the Javascript forum - I'm quite happy to do so - but I really thought it was a problem in the C# code.

<script language=&quot;javascript&quot;>
<!--

function CheckDeletion(profileForm)
{

if (profileForm.chkConfirmDelete.checked)
{

profileForm.hidisDelete.value=&quot;true&quot;;
profileForm.hidClickDelete.value=&quot;true&quot;;
return true;

}
else
{

alert (&quot;Please confirm that you would like to delete this API User.&quot;);
profileForm.hidClickDelete.value=&quot;false&quot;;
return false;

}

}


-->
</script>
 
sorry aobut that, I'm blid hehehe
here is your problem:

btnDelete.Attributes.Add (&quot;onclick&quot;, &quot;javascript:return CheckDeletion(this.form);&quot;); Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Thanks so much Alcar - I'd been struggling with this for AGES!

Craftor

:cool:

It's always the little things that get you down
 
You are more than welcome. And thank you for the star =) Daren J. Lahey
Just another computer guy...
If you are unsure of forum etiquette check here FAQ796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top