1

Can you please tell me how to refer to .net classes at design time. For e.g I want to print the current datetime in a label or text box. I tried following code but my page is coming blank.

                        <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

                        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

                        <html xmlns="http://www.w3.org/1999/xhtml">
                        <head runat="server">
                            <title></title>
                        </head>
                        <body>
                            <form id="form1" runat="server">
                            <div>
                            <label runat="server"><%# DateTime.Now.ToString() %></label>

                            <asp:TextBox runat="server" ID="litDateNow" Text='<%# DateTime.Now.ToString() %>'></asp:TextBox> 

                            </div>
                            </form>
                        </body>
                        </html>

4 Answers 4

2

Consider that you want to use .net classes, in any part of ASP.net page you can use <%= your classes %> in top of any Asp.net page you can see a

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_Default" %>

so your Page declerative is using this pattern too

Sign up to request clarification or add additional context in comments.

Comments

2

That should be:

<label runat="server"><%= DateTime.Now.ToString() %></label>

Comments

0
<%= DateTime.Now.ToString() %>

You can use the above syntax

The syntax you have defined is used for databinding, not printing text

Comments

0

If you just want to display date from aspx page, write

<div>
    <%= DateTime.Now.ToLongTimeString()%>
</div>

No need to use any textbox or label control, if it is of no use in code-behind

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.