This is a migrated thread and some comments may be shown as answers.

[Solved] OnDocumentReady Expression Expected error

2 Answers 126 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
David
Top achievements
Rank 1
David asked on 01 Jul 2011, 11:41 PM

Any idea where we may have gone astray here? The top line works great but the bottom causes an Expression Expected error.

<% Html.Telerik().ScriptRegistrar().OnDocumentReady("alert('hello');")%> 
<% Html.Telerik().ScriptRegistrar().OnDocumentReady(()=>{%>function(){ alert('hello');}<% })%>

Here's the html that's rendered when I remove the bottom line,

 

<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){
jQuery('#t-ceomenu').tMenu();alert('hello');});
//]]>
</script>

Here's the error when I put it back - error BC30201: Expression expected.

Here's how the we're loading the scripts in the master page:

<%  Html.Telerik().ScriptRegistrar.DefaultGroup(Sub(group)
    group.Combined(True) _
    .Compress(True) _
    .CacheDurationInDays(365)
    End Sub) _
    .Scripts(Sub(scripts)
    scripts.AddGroup("MicrosoftCommon", Sub(group)
    group.Add("~/Scripts/MicrosoftAjax.js") _
    .Add("~/Scripts/MicrosoftMvcAjax.js") _
    .Add("~/Scripts/MicrosoftMvcValidation.js") _
    .Combined(True) _
    .Compress(True) _
    .CacheDurationInDays(365)
    End Sub)
    End Sub) _
    .Render()%>

Thanks for any help on this.

2 Answers, 1 is accepted

Sort by
0
John DeVight
Top achievements
Rank 1
answered on 12 Jul 2011, 01:10 PM
Hi David,

Looking at the javascript "function(){ alert('hello');}" it looks like you are attempting to define an anonymous function?  If I set the function equal to a variable like this"var anonymousFunction = function(){ alert('hello');}", it is fine.  I'd like to help, but I could use a bit more details of what you are trying to do...

Regards,

John DeVight
0
David
Top achievements
Rank 1
answered on 12 Jul 2011, 10:47 PM
Hey Thanks for getting back to me.

Basically we'd like to not have to define the scripts in a string after the onDocumentReady call. So for example, what would be ideal would call Html.Telerik().ScriptRegistrar().OnDocumentReady on one line then write our javascript and then close Html.Telerik().ScriptRegistrar().OnDocumentReady. I'm just having a hard time getting the syntax to work and I would rather not have to encapsulate all my javascript in a string.

I found this on another post, but we're using vb without razor (MVC 2) and I'm getting an expression expected error when I try to run the code.

<% Html.Telerik().ScriptRegistrar()
           .OnDocumentReady(() =>
           { %>
                alert('ready');
             <%
           })
           .Render();
        %>

Here's the link to the other post http://www.telerik.com/community/forums/aspnet-mvc/general/hijacking-of-ondocumentready.aspx

Thanks again.
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
John DeVight
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or