Code Behind Pages

Discussion in 'Visual Studio' started by RogerL, Jan 9, 2007.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hi I'm new to everything - DiscountASP, ASP.Net, Web Developer - however I have programmed in classic ASP.

    I'm having a problem with aspNetMail - although I suppose the real problem is with code behind pages. Here's the deal - the following page works fine in sending out an email (it's the example from the KB.) as single page code.




    <%@ Assembly name="aspNetEmail, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bc571e8da1c1f543" %>


    <%@ import Namespace="aspNetEmail" %>


    <Script runat="server" Language="VB">





    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)





    Dim msg As EmailMessage = New EmailMessage("localhost")


    'set the from address


    msg.FromAddress = "[email protected]"


    'set the to address


    msg.To = "[email protected]"


    'Set email subject and body


    msg.Subject = "ASPNetEMail test"


    msg.Body = "this is my simple email."


    'send the email


    msg.Send()


    response.Write("Mail Sent")


    End Sub





    </script>
    I've split the code into the aspx and vb files like so: 1st aspx




    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Testmail.aspx.vb" Inherits="Testmail" %>


    <%@ import Namespace="aspNetEmail" %>


    <!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>Untitled Page</title>


    </head>





    <form id="form1" runat="server">


    <div>





    </div>


    </form>


    </body>


    </html>

    Now vb:




    Partial Class Testmail


    Inherits System.Web.UI.Page


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


    ' Set SMTP Host as localhost


    Dim msg As EmailMessage = New EmailMessage("localhost")


    'set the from address


    msg.FromAddress = "[email protected]"


    'set the to address


    msg.To = "[email protected]"


    'Set email subject and body


    msg.Subject = "ASPNetEMail test"


    msg.Body = "this is my simple email."


    'send the email


    msg.Send()


    response.Write("Mail Sent")


    End Sub


    End Class


    I get this message in Web developer - Error2Type 'EmailMessage' is not defined.C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\WebSites\Test\Testmail.aspx.vb720C:\...\Test\



    I can't work out why - the namespace doesn't seem to work.
    Hope someone can help
    Thanks
     
  2. You are Missing "Handles MyBase.Load"
    i.e

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    instead of

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    Vikram

    DiscountASP.NET
    www.DiscountASP.NET
     
  3. Well done Vikram, that did it.


    Thanks very much
     
  4. It is installed locally, that's why the single code page works. The problem is with code separation in Web developer, although I have import namespace = aspnet..., the VB page isn't recognising it.





    Something I just tried is to add


    Imports aspNetEmail


    into the VB page. That stops the error, but the script still does not work, ie email (at least it now doesn't have compile errors)





    Any thoughts
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page