tags:

views:

146

answers:

3

Why this code doesn't work?

OnClientClick='<%# String.Format("return confirm('¿Está seguro que desea eliminar el registro {0}?);'", Eval("data")) %>'

The error is:

The server tag is not well formed.

How can I write this to make it work?

+1  A: 

The second ' is telling the string to end. Escape it using a backslash. Same with the ending apostrophe.

OnClientClick='<%# String.Format("return confirm(\'¿Está seguro que desea eliminar el registro {0}?);\'", Eval("data")) %>'

Try that.

Brandon
A: 

Use @ at the start of the string so that escape characters are not processed. See http://msdn.microsoft.com/en-us/library/362314fe(VS.71).aspx

OnClientClick='<%# Eval("data", @"return confirm('¿Está seguro que desea eliminar el registro {0}?);'") %>'
Damien McGivern
A: 

It also appears that the string within the confirm function is not closed prior to the closing paren. Should be:

confirm('¿Está seguro que desea eliminar el registro {0}?');
Rich