Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add namespace in aspx file?

Tags:

asp.net

i have added C# code in aspx file, but it is showing error

The type or namespace name 'Mail' does not exist in the class or namespace 'System.Net' (are you missing an assembly reference?)

How i can add nampespace to aspx file i have tried <%@ import namespace="Westwind.Tools"%> but it does not work?

like image 575
Sheery Avatar asked Mar 03 '10 08:03

Sheery


People also ask

Which is a default namespace included in the code behind file of ASPX page?

aspx page inherits from the code-behind class that is named InheritSamples in the CodeBehindSamples namespace. By default, a web application that is created in Visual Studio .

How do I automatically add a namespace in Visual Studio?

To do it, you may either manually type the Using Namespace, or you just right click on the class name and select Resolve > Namespace. But using “Ctrl+.” you can automatically add the namespace in your code.

How do I edit an ASPX file?

Sometimes, the aspx files can be opened and edited with text editor. If you have free software such as Notepad++, you can open and edit the aspx files in it. Microsoft's Visual Studio is another free program that allows you to open and edit an aspx file. Adobe Dreamweaver can also open and edit an apsx file.


2 Answers

<%@ Import Namespace="System.Net.Mail" %> 
like image 174
Darin Dimitrov Avatar answered Sep 19 '22 17:09

Darin Dimitrov


I'm assuming that it's in a website and that the page doesn't have code behind?

<%@ Page Language="C#" %> <%@ Import Namespace="System.Net.Mail"%>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">           protected void Page_Load(object sender, EventArgs e)         {             System.Net.Mail.SmtpClient client = new SmtpClient();           }  </script>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>  </body> </html> 

This seems to work for me.

If it's not in a website and/or it has code behind why do you need to reference the namespace in the aspx file?

Hope this helps

like image 44
WestDiscGolf Avatar answered Sep 17 '22 17:09

WestDiscGolf