c# - Error 4 A namespace cannot directly contain members such as fields or methods -


i supposed project in class have setup website scratch using c# , asp.net.

my objective create contact form in case function send email designated address upon clicking of button i've tried create googling codes. however, i've encountered error , "a namespace cannot directly contain members such fields or methods. "

could help? in advance!

the codes i've used on page follows:

using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols;  <%@import namespace="system.web.mail" %>; <script language="c#" runat="server">;    public partial class contactus : system.web.ui.page {     protected void page_load(object sender, eventargs e)     {      }       protected void button1_click(object sender, eventargs e)     {          mailmessage msg = new mailmessage();          msg.to = "sarahhhhh@gmail.com";         msg.from = nametb.text;         msg.subject = subjecttb.text;         msg.body = messagetb.text;         lblstatus.text = "sending...";          smtpmail.send(msg);         lblstatus.text = "sent email (" + txtsubject.text + ") " + txtto.text;     } } 

remove these lines:-

<%@import namespace="system.web.mail" %>; <script language="c#" runat="server">; </script> //if it's present 

and add using system.web.mail; @ top other namespaces included. file aspx.cs file extension called code behind file, should read basics first. refer this.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -