Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB code behind not seeing aspx controls .Net 1.1 1

Status
Not open for further replies.

gtjr921

Programmer
Aug 30, 2006
115
Asp.net 1.1

I am trying to create a contact form with asp.net 1.1 page and a vb code behind. when i reference a control in my vb code it acts as if it does not know what controls i am referencing I get "Name 'txtFrom' is not declared"
I get this for any aspx control I call in my vb code.
Here is my code
Code:
'vb code behind contact.vb
Imports System.Web.Mail
Imports System.Web.Mail.MailMessage
Public Class WebForm1
    Inherits System.Web.UI.Page
    Public Sub Btnsend_click(ByVal sender As Object, ByVal e As eventargs)
        Dim objEmail As New MailMessage()
        objEmail.To = "myemail@here.com"
        objEmail.From = txtFrom.Text
        'objEmail.Cc       = txtCc.Text
        objEmail.Subject = "subject Email"
        objEmail.Body = txtName.Text & ", " & txtMSG.Text
        objEmail.Priority = MailPriority.High
        SmtpMail.SmtpServer = "123.456.789.1"
        Try
            SmtpMail.Send(objEMail)
    Response.Write(Your E-mail to has been sent _              )     Catch exc As Exception
            Response.Write("Send failure: " + exc.ToString())
        End Try
        
    End Sub
End Class

Asp.net page relevant code
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" codebehind="contact.vb" Src="contact.vb" Inherits="WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]

<asp:TextBox id="txtFrom" runat="server" TextMode="SingleLine"></asp:TextBox>
                                                                                                    
                                                                                                        <asp:Label id="lblMsg" runat="server" 
text="Type Your Message Here"></asp:Label>
                                                                                                        <br />
                                                                                                        <asp:TextBox id="txtMSG" runat="server" TextMode="MultiLine" Height="186px" Width="552px"></asp:TextBox>
                                                                                                        <br />
                                                                                                        <br />
                                                                                                        <asp:Button id="btnSend" runat="server" Text="Send Email" onclick="Btnsend_click"></asp:Button>
 
Visual Studio 2003 had a tendency to do this. Try closing both pages (the aspx and the code behind page), opening the aspx page again, deleting the original control and adding it again. If that doesn't sort out the problem, you can add the reference to the control yourself (have a look at the Protected WithEvents declarations at the top of your code behind page to see how they are added).


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
it was the protected withevents.
For reference i added
Code:
   Protected WithEvents btnSend As System.Web.UI.WebControls.Button
    Protected WithEvents txtFrom As System.Web.UI.WebControls.Textbox
    Protected WithEvents txtName As System.Web.UI.WebControls.Textbox
    Protected WithEvents txtMSG As System.Web.UI.WebControls.Textbox
    Protected WithEvents lblSuccess As System.Web.UI.WebControls.Label

thanks for the tip!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top