Last post Dec 20, 2010 10:10 PM by decker dong - msft
Dec 17, 2010 03:46 PM|Codewriter90x|LINK
I have a problem... I don't understand what's wrong....
<asp:Button ID="Button1" runat="server" Text="Button" onclick='
<%= Dim Manage As New LinkManage()
Dim res As String = ""
Dim currency As String = ""
res = Manage.LinkManage(5,5,5,5).ToString()
the compilation give me the error: BC36807: Impossibile selezionare elementi XML dal tipo 'ASP.gestione_funzioni_link_default_aspx'.
hem... translate... impossible to select XML element from the kind 'ASP.gestione_funzioni_link_default_aspx'
Is there any guide about how to write code on the asp net page ... so about how and when start with # or = on the <% %>
Thank's so much !!!
Dec 17, 2010 04:01 PM|habuivan27|LINK
You can find the guide in here
Dec 18, 2010 12:07 PM|Codewriter90x|LINK
so... at the end what's the problem??
Dec 20, 2010 09:55 PM|Decker Dong - MSFT|LINK
No you cannot do that, Here're two solutions:
1) Double-click the button, and say codes behind at something like this:
protected void Button1_Click（……）
2) If you put your Button into GridView or something else that you wanna process with some BoundField, do this:
<asp:Button ID="Button1" runat="server" Text="Button" CommandArgument='<%#Eval("BoundField")%>'……/>
Then double-click the button in the IDE, do this:
Button btn = (Button)sender;
// Get Arguments by btn.CommandArgument;
Dec 20, 2010 10:10 PM|Decker Dong - MSFT|LINK
<%%> can be only used as a code snippet which is used in aspx markups in something like <head>……<body>……
YOU CANNOT USE IT DIRECTLY IN ANY SERVER-SIDE CONTROL's Event Handler!
As for <%=>, this means <%Response.WriteLine(……)%>。You can use it in some properties to set.
About <%#Eval%>, this means you can only use it in any data presentation control.
For more please see this:
<% … %> Embedded Code Blocks
The Embedded Code Block is used to preserve backward compatibility with classical ASP. The code in the block can execute programming statements and call functions in the current page class during the page's render phase.
The following sample demonstrates an ASP.NET page with a snippet VB.NET code in an Embedded Code Block that displays the results of a loop.
<%@ Page %>
<% For i As Integer = 16 To 24 Step 2%>
<div style="font-size: <% Response.Write(i)%>">
Hello World<br />
For the reason that the Embedded Code Block is always mixed with the HTML source, it is hard for developers to read and maintain them. As a conclusion, it is not recommended to use the Embedded Code Block in ASP.NET anymore.
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/ms178135.aspx.
Back to the top
<%= … %> Displaying Expression
The Displaying Expression <%= ... %> is an equivalent of the Embedded Code Block which only contains the Response.Write(…) statement. It is the simplest way to display the information, like a single string, an int variable or a constant, onto the page.
For example, the following code displays the current time on the page.
It is important to remember that the Displaying Expression cannot be used in the attributes of server controls. This is because .Net framework will directly compile the whole expression, instead of the displaying content, as the value to the attribute.
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/6dwsdcf5.aspx.
<%@ … %> Directive Expression
The Directive Expression is the syntax that Specifies settings used by the page and user control compilers when they process ASP.NET Web Form (.aspx) pages and User Control (.ascx) files.
The ASP.NET Framework supports the following directives.
Defines page-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .aspx files.
*This directive name can be only used in ASP.NET Web Form pages.
Defines control-specific attributes used by the ASP.NET page parser and compiler. Can be included only in .ascx files (user controls).
*This directive name can be only used in User Control files.
Explicitly imports a namespace into a page or user control.
Declaratively indicates that a page or user control implements a specified .NET Framework interface.
Associates aliases with namespaces and class names, thereby allowing user controls and custom server controls to be rendered when included in a requested page or user control.
Links an assembly to the current page during compilation, making all the assembly's classes and interfaces available for use on the page.
Identifies an ASP.NET master page.
Identifies an ASP.NET IHttpHandler page.
Provides the means to get strong typing against the previous page as accessed through the PreviousPage property.
Assigns a class name to the Master property of an ASP.NET page, so that the page can get strongly typed references to members of the master page.
Declaratively controls the output caching policies of a page or user control.
Declaratively links a page or user control to the current page or user control.
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/xz702w3e.aspx.
<%# … %> Data-Binding Expression
The Data-Binding Expression creates binding between a server control property and a data source when the control’s DataBind method of this server control is called on the page.
The following example illustrates how to use the Data-Binding Expression to bind the string from a function to the Text property of a Label.
Protected Function SayHello() As String
Return "Hello World"
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs)
<asp:Label runat="server" Text="<%# SayHello%>"></asp:Label>
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/bda9bbfx.aspx.
<%$ … %> Expressing Builder
The Expressing Builder is used to set values of control properties based on the information contained within an application's configuration or resource files. The basic syntax of the Expressing Builder is the following:
<%$ Expression Prefix: Expression Value %>
The dollar sign ($) indicates to ASP.NET that the following expression is an Expressing Builder. The Expression Prefix defines the type of expression, such as AppSettings, ConnectionStrings or Resources. The Expression Value following the colon (:) is what ASP.NET will actually use as the value of a certain property.
The following demo illustrates how to use the Expressing Builder to obtain the copyright of a website from the AppSettings node in web.config file and set it as the value of the Literal’s Text property.
The AppSettings node in web.config file.
<add key="copyright" value="(c) Copyright 2009 WebSiteName.com"/>
The Expressing Builder in the ASP.NET Web Form page.
<asp:Literal runat="server" Text="<%$ AppSettings: copyright %>"></asp:Literal>
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/d5bd1tad.aspx.
<%-- … -- %> Server-Side Comments Block
The Server-Side Comments Block allow developers to embed code comments in any place of the HTML source of ASP.NET Web Form pages (except for within <script> code blocks). Any content between opening and closing tags of the Server-Side Comments Block will not be processed on the server or rendered to the resulting page.
A simple instance can be found below to demonstrate how to use the Server-Side Comments Block in an ASP.NET page.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim strName As String
strName = Session("userName")
lblUserName.Text = strName
<%-- Label for UserName --%>
<asp:Label runat="server" Text=""></asp:Label>
Related link in MSDN Library: http://msdn.microsoft.com/en-us/library/4acf8afk.aspx.