Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Running C# code in aspx file

Reply
Thread Tools

Running C# code in aspx file

 
 
Mario
Guest
Posts: n/a
 
      05-25-2010
The row below:

<asp:Label runat="server" ID="Label4" Text="<%#
System.Math.Ceiling((double)(Container.TotalRowCou nt)/(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.


 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      05-25-2010
On May 25, 2:34*pm, "Mario" <(E-Mail Removed)> wrote:
> The row below:
>
> <asp:Label runat="server" ID="Label4" Text="<%#
> System.Math.Ceiling((double)(Container.TotalRowCou nt)/(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/QuickStar...odebehind.aspx
 
Reply With Quote
 
 
 
 
Mario
Guest
Posts: n/a
 
      05-26-2010

"Alexey Smirnov" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On May 25, 2:34 pm, "Mario" <(E-Mail Removed)> wrote:
> The row below:
>
> <asp:Label runat="server" ID="Label4" Text="<%#
> System.Math.Ceiling((double)(Container.TotalRowCou nt)/(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/QuickStar...odebehind.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.


 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      05-26-2010
On May 26, 8:02*am, "Mario" <(E-Mail Removed)> wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where to put server side c# code (in .aspx or in the aspx.cs ?) Mr Flibble ASP .Net 8 05-23-2006 04:37 PM
adding main.aspx.vb & main.aspx.resx under aspx John M ASP .Net 1 05-29-2005 09:27 PM
How to bring aspx code (in HTML view) to the aspx.vb code-behind? Paolo Pignatelli ASP .Net 6 02-21-2005 01:55 AM
Running code when viewing aspx code =?Utf-8?B?TWF0dGhpYXMgSC4=?= ASP .Net 2 02-11-2005 02:31 PM
including one aspx file in another aspx file vish ASP .Net 2 07-16-2003 10:29 PM



Advertisments