Running C# code in aspx file

M

Mario

The row below:

<asp:Label runat="server" ID="Label4" Text="<%#
System.Math.Ceiling((double)(Container.TotalRowCount)/(double)Container.PageSize)
%>" />

And it works fine, but I wonder, how to write similar code when I don't have
code completion between <% %> tag ? Code above I've finished in .cs file,
after I saw similar example, then I copied in a aspx file.
 
G

Guest

The row below:

<asp:Label runat="server" ID="Label4" Text="<%#
System.Math.Ceiling((double)(Container.TotalRowCount)/(double)Container.Pag eSize)
%>" />

And it works fine, but I wonder, how to write similar code when I don't have
code completion between  <% %> tag ? Code above I've finished in .cs file,
after I saw similar example, then I copied in a aspx file.

You can add your code between <script></script> tags in the asx page

<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Label4.Text = "Test"
End Sub
</script>

For more information about Code Behind and Code Inline look here
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/pages/codebehind.aspx
 
M

Mario

The row below:

<asp:Label runat="server" ID="Label4" Text="<%#
System.Math.Ceiling((double)(Container.TotalRowCount)/(double)Container.Pag
eSize)
%>" />

And it works fine, but I wonder, how to write similar code when I don't
have
code completion between <% %> tag ? Code above I've finished in .cs file,
after I saw similar example, then I copied in a aspx file.

You can add your code between <script></script> tags in the asx page

<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
Label4.Text = "Test"
End Sub
</script>

For more information about Code Behind and Code Inline look here
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/pages/codebehind.aspx

I tried wrote script above the <head> tag:
<script runat="server">

System.Math.

</script>

And I had code completion for System. Math but further Math methods are
still unrichable for code completion, so I must look at help to find what
method I need, while in Default.aspx.cs I have completion for every method
or variable of some class. 99% of code I write in .cs file, but sometimes I
only need some small part of a code and then I need to search the whole
System.Math help. I just check if my VS2008 is setup correctly.
 
G

Guest

I tried wrote script above the <head> tag:
<script runat="server">

System.Math.

</script>

And I had code completion for System. Math but further Math methods are
still unrichable for code completion, so I must look at help to find what
method I need, while in Default.aspx.cs I have completion for every method
or variable of some class. 99% of code I write in .cs file, but sometimes I
only need some small part of a code and then I need to search the whole
System.Math help. I just check if my VS2008 is setup correctly.

Intellisense will not work if code block is incorrect. In your example
above, you missed the body of a function where you would like to
execute your code with a reference to System.Math. For VB example
please refer to my last post. C# version should look like

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = System.Math.Sin(1).ToString();
}
</script>

Hope this helps
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top