Problem when generating Client Side Script.

J

John Owens

I use in Render( HtmlTextWriter output) :

//--------------------------------------------------------------------------

output.WriteBeginTag( "a" );

if( ID != null )

output.WriteAttribute( "id", ClientID );


output.WriteAttribute( "href", "javascript:" +
Page.GetPostBackEventReference( this ) );

output.Write( HtmlTextWriter.TagRightChar );

if( Text.Length > 0 )

output.Write( Text );

output.WriteEndTag( "a" );



//--------------------------------------------------------------------------
-------------------------

This creates the HTML:

<a id="WebLinkButtonCtrl1"
href="javascript:__doPostBack('WebLinkButtonCtrl1','')">Type something
here</a>

The problem is when I press the button as it gives a:

Microsoft JScript runtime error: Object expected

Does anyone have any ideas as how to solve this as it appears to be
happening whenever I use

output.WriteAttribute( "href", "javascript:" +
Page.GetPostBackEventReference( this ) );

even when they are copied from samples etc.



Thanks

John.
 
J

John Owens

It was because the control wasn't inside the form tag.

Does anyone know why this is the case?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I haven't check your code, but one thing I can be sure of, the controls
should be inside a form.


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top