.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

Mixing javascipt and VB.NET in ASP.NET 2.0 code

Can we mix javascipt and VB.NET in ASP.NET 2.0 code ?


<script language="text/jscript">
Function Test1()

(The VB.NET code being in a code behind page such as test.aspx.vb, etc.)
Ezani Send private email
Wednesday, January 03, 2007
You cannot add content -- HTML, client script, etc -- to the code-behind page, since it is compiled as a class and not rendered to the browser (also your JS syntax is not quite right, but you probably know that).

  If you wanted to insert a script into the .aspx file, you could do that in the context of the page as with any other static content.  What is it that you really want to do here?

Peter Brunone Send private email
Thursday, January 04, 2007
As Peter says, javascript is not a problem in the aspx/ascx files, just like html or inline VB.Net.

In fact, I regularly embed C# inside the javascript.

document.aForm.<%=aConstDeclaredInBackingClass%>.value = x;

That way any server-side processing of the form post has easy access to the form variables. (Rather than hard-coding strings in the form and all the server side processors.)
Thursday, January 04, 2007
You can always add attributes to controls, or use overridden Render methods to actually spit the js code right to the browser.
Brian Send private email
Monday, January 08, 2007

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz