write a C# code inside a javascript code, before body tag

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Andrade

    write a C# code inside a javascript code, before body tag

    Hello,

    How can I write a C# code inside a javascript code, before body tag, as
    we wrote in classic asp?
    (I have a code file separated with a lot of C# code)

    I would like anything like this:

    <head runat="server">

    <style type="text/css">

    <%

    int x = 0;

    // Load Data Table
    DataTable rs = fnTabelaGradeCa rtas();

    // Load the grid with recordset
    foreach (DataRow cLinha in rs.Rows)
    {

    Response.Write (".active-column-" + x.ToString() +
    " {width: 80px; text-align: right;}");

    };

    %>

    .active-grid-column {border-right: 1px solid threedshadow;}
    .active-grid-row {border-bottom: 1px solid
    threedlightshad ow;}
    </style>

    <title></title>
    </head>
    <body>
    ..
    ..
    ..


    But the cod inside <% %tags is ignorated :(
    How could I write any c# code there?
    Can I write this using the behind code or I must use like classic asp?

    Please!

  • Göran Andersson

    #2
    Re: write a C# code inside a javascript code, before body tag

    Put an asp:Literal tag in the page, and populate it from the code in
    code-behind.

    You might need to declare the reference to the control yourself, though,
    as it's outside the form.

    Daniel Andrade wrote:
    Hello,
    >
    How can I write a C# code inside a javascript code, before body tag, as
    we wrote in classic asp?
    (I have a code file separated with a lot of C# code)
    >
    I would like anything like this:
    >
    <head runat="server">
    >
    <style type="text/css">
    >
    <%
    >
    int x = 0;
    >
    // Load Data Table
    DataTable rs = fnTabelaGradeCa rtas();
    >
    // Load the grid with recordset
    foreach (DataRow cLinha in rs.Rows)
    {
    >
    Response.Write (".active-column-" + x.ToString() +
    " {width: 80px; text-align: right;}");
    >
    };
    >
    %>
    >
    .active-grid-column {border-right: 1px solid threedshadow;}
    .active-grid-row {border-bottom: 1px solid
    threedlightshad ow;}
    </style>
    >
    <title></title>
    </head>
    <body>
    .
    .
    .
    >
    >
    But the cod inside <% %tags is ignorated :(
    How could I write any c# code there?
    Can I write this using the behind code or I must use like classic asp?
    >
    Please!
    >

    Comment

    Working...