newbie to creating web controls

Discussion in 'ASP .Net Building Controls' started by GJH, Dec 29, 2005.

  1. GJH

    GJH Guest

    I am trying to develop some .NET web controls in VB or C# and need some
    help.
    Does anyone know any websites with a good tutorial on how to start. The MSDN
    site is not helping me at all.

    An example I have is code that will email, I simply want to create a button
    that has all the email code inside it, so I just have to place the button on
    my page and add some properties and be done. It works fine when adding the
    properties for the Property tab but cant get any properties working from
    codebehind.

    What am I doing wrong?

    thanks in advance, heres my code.

    <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    runat=server></{0}:EmailButton>")> Public Class EmailButton

    Inherits System.Web.UI.WebControls.Button

    Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod, emlRedirect As
    String

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    SMTPServer() As String

    Get

    Return smtpText

    End Get

    Set(ByVal Value As String)

    smtpText = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailTo() As String

    Get

    Return emlto

    End Get

    Set(ByVal Value As String)

    emlto = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailFrom() As String

    Get

    Return emlfrom

    End Get

    Set(ByVal Value As String)

    emlfrom = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailCC() As String

    Get

    Return emlcc

    End Get

    Set(ByVal Value As String)

    emlcc = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailBcc() As String

    Get

    Return emlbcc

    End Get

    Set(ByVal Value As String)

    emlbcc = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailSubject() As String

    Get

    Return emlSubj

    End Get

    Set(ByVal Value As String)

    emlSubj = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailBody() As String

    Get

    Return emlBod

    End Get

    Set(ByVal Value As String)

    emlBod = Value

    End Set

    End Property

    <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    EmailGoToPage() As String

    Get

    Return emlRedirect

    End Get

    Set(ByVal Value As String)

    emlRedirect = Value

    End Set

    End Property

    Public Sub Emailer()

    Try

    Dim gjhMail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage

    System.Web.Mail.SmtpMail.SmtpServer = smtpText

    gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html

    gjhMail.From = emlfrom

    gjhMail.Subject = emlSubj

    gjhMail.To = EmailTo()

    gjhMail.Cc = emlcc

    gjhMail.Bcc = emlbcc

    gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf

    System.Web.Mail.SmtpMail.Send(gjhMail)

    Catch ex As Exception

    End Try

    End Sub



    Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)

    MyBase.Render(output)

    End Sub

    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)

    Emailer()

    End Sub
    GJH, Dec 29, 2005
    #1
    1. Advertising

  2. GJH,
    the class looks fine, what issues are you having using it from a
    codebehind? ie, how are you using it?

    Mike


    GJH wrote:
    > I am trying to develop some .NET web controls in VB or C# and need some
    > help.
    > Does anyone know any websites with a good tutorial on how to start. The MSDN
    > site is not helping me at all.
    >
    > An example I have is code that will email, I simply want to create a button
    > that has all the email code inside it, so I just have to place the button on
    > my page and add some properties and be done. It works fine when adding the
    > properties for the Property tab but cant get any properties working from
    > codebehind.
    >
    > What am I doing wrong?
    >
    > thanks in advance, heres my code.
    >
    > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > runat=server></{0}:EmailButton>")> Public Class EmailButton
    >
    > Inherits System.Web.UI.WebControls.Button
    >
    > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod, emlRedirect As
    > String
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > SMTPServer() As String
    >
    > Get
    >
    > Return smtpText
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > smtpText = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailTo() As String
    >
    > Get
    >
    > Return emlto
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlto = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailFrom() As String
    >
    > Get
    >
    > Return emlfrom
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlfrom = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailCC() As String
    >
    > Get
    >
    > Return emlcc
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlcc = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailBcc() As String
    >
    > Get
    >
    > Return emlbcc
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlbcc = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailSubject() As String
    >
    > Get
    >
    > Return emlSubj
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlSubj = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailBody() As String
    >
    > Get
    >
    > Return emlBod
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlBod = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailGoToPage() As String
    >
    > Get
    >
    > Return emlRedirect
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlRedirect = Value
    >
    > End Set
    >
    > End Property
    >
    > Public Sub Emailer()
    >
    > Try
    >
    > Dim gjhMail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    >
    > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    >
    > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    >
    > gjhMail.From = emlfrom
    >
    > gjhMail.Subject = emlSubj
    >
    > gjhMail.To = EmailTo()
    >
    > gjhMail.Cc = emlcc
    >
    > gjhMail.Bcc = emlbcc
    >
    > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    >
    > System.Web.Mail.SmtpMail.Send(gjhMail)
    >
    > Catch ex As Exception
    >
    > End Try
    >
    > End Sub
    >
    >
    >
    > Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    >
    > MyBase.Render(output)
    >
    > End Sub
    >
    > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    >
    > Emailer()
    >
    > End Sub
    Mike MacMillan, Dec 29, 2005
    #2
    1. Advertising

  3. GJH

    GJH Guest

    I'd like to be able to do this:
    Private Sub EmailButton1_Click(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles EmailButton1.Click
    EmailButton1.EmailBody = TextBox1.text

    Response.Redirect(http://www.msn.com)

    End Sub

    but the button never retrieves the TextBox1.Text value. It is always
    Nothing.
    The Response.Redirect does work though, if i comment out the 1st line.


    thanks in advance,
    G

    "Mike MacMillan" <> wrote in message
    news:...
    > GJH,
    > the class looks fine, what issues are you having using it from a
    > codebehind? ie, how are you using it?
    >
    > Mike
    >
    >
    > GJH wrote:
    > > I am trying to develop some .NET web controls in VB or C# and need some
    > > help.
    > > Does anyone know any websites with a good tutorial on how to start. The

    MSDN
    > > site is not helping me at all.
    > >
    > > An example I have is code that will email, I simply want to create a

    button
    > > that has all the email code inside it, so I just have to place the

    button on
    > > my page and add some properties and be done. It works fine when adding

    the
    > > properties for the Property tab but cant get any properties working from
    > > codebehind.
    > >
    > > What am I doing wrong?
    > >
    > > thanks in advance, heres my code.
    > >
    > > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > > runat=server></{0}:EmailButton>")> Public Class EmailButton
    > >
    > > Inherits System.Web.UI.WebControls.Button
    > >
    > > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod,

    emlRedirect As
    > > String
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > SMTPServer() As String
    > >
    > > Get
    > >
    > > Return smtpText
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > smtpText = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailTo() As String
    > >
    > > Get
    > >
    > > Return emlto
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlto = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailFrom() As String
    > >
    > > Get
    > >
    > > Return emlfrom
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlfrom = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailCC() As String
    > >
    > > Get
    > >
    > > Return emlcc
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlcc = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailBcc() As String
    > >
    > > Get
    > >
    > > Return emlbcc
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlbcc = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailSubject() As String
    > >
    > > Get
    > >
    > > Return emlSubj
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlSubj = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailBody() As String
    > >
    > > Get
    > >
    > > Return emlBod
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlBod = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailGoToPage() As String
    > >
    > > Get
    > >
    > > Return emlRedirect
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlRedirect = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > Public Sub Emailer()
    > >
    > > Try
    > >
    > > Dim gjhMail As System.Web.Mail.MailMessage = New

    System.Web.Mail.MailMessage
    > >
    > > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    > >
    > > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    > >
    > > gjhMail.From = emlfrom
    > >
    > > gjhMail.Subject = emlSubj
    > >
    > > gjhMail.To = EmailTo()
    > >
    > > gjhMail.Cc = emlcc
    > >
    > > gjhMail.Bcc = emlbcc
    > >
    > > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    > >
    > > System.Web.Mail.SmtpMail.Send(gjhMail)
    > >
    > > Catch ex As Exception
    > >
    > > End Try
    > >
    > > End Sub
    > >
    > >
    > >
    > > Protected Overrides Sub Render(ByVal output As

    System.Web.UI.HtmlTextWriter)
    > >
    > > MyBase.Render(output)
    > >
    > > End Sub
    > >
    > > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    > >
    > > Emailer()
    > >
    > > End Sub

    >
    GJH, Dec 29, 2005
    #3
  4. GJH,
    2 things here:

    > but the button never retrieves the TextBox1.Text value

    are you certain the TextBox1 control has a valid .Text property
    upon postback? ie, is viewstate restoring the value of the textbox?

    > The Response.Redirect does work though, if i comment out the 1st

    line.
    does this mean if you leave the line where it set the EmailBody
    property uncommented, it throw an error? i can't imagine why else it
    wouldn't run the Response.Redirect unless an error was thrown. if so,
    what is the error?

    Mike MacMillan



    GJH wrote:
    > I'd like to be able to do this:
    > Private Sub EmailButton1_Click(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles EmailButton1.Click
    > EmailButton1.EmailBody = TextBox1.text
    >
    > Response.Redirect(http://www.msn.com)
    >
    > End Sub
    >
    > but the button never retrieves the TextBox1.Text value. It is always
    > Nothing.
    > The Response.Redirect does work though, if i comment out the 1st line.
    >
    >
    > thanks in advance,
    > G
    >
    > "Mike MacMillan" <> wrote in message
    > news:...
    > > GJH,
    > > the class looks fine, what issues are you having using it from a
    > > codebehind? ie, how are you using it?
    > >
    > > Mike
    > >
    > >
    > > GJH wrote:
    > > > I am trying to develop some .NET web controls in VB or C# and need some
    > > > help.
    > > > Does anyone know any websites with a good tutorial on how to start. The

    > MSDN
    > > > site is not helping me at all.
    > > >
    > > > An example I have is code that will email, I simply want to create a

    > button
    > > > that has all the email code inside it, so I just have to place the

    > button on
    > > > my page and add some properties and be done. It works fine when adding

    > the
    > > > properties for the Property tab but cant get any properties working from
    > > > codebehind.
    > > >
    > > > What am I doing wrong?
    > > >
    > > > thanks in advance, heres my code.
    > > >
    > > > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > > > runat=server></{0}:EmailButton>")> Public Class EmailButton
    > > >
    > > > Inherits System.Web.UI.WebControls.Button
    > > >
    > > > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod,

    > emlRedirect As
    > > > String
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > SMTPServer() As String
    > > >
    > > > Get
    > > >
    > > > Return smtpText
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > smtpText = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailTo() As String
    > > >
    > > > Get
    > > >
    > > > Return emlto
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlto = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailFrom() As String
    > > >
    > > > Get
    > > >
    > > > Return emlfrom
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlfrom = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailCC() As String
    > > >
    > > > Get
    > > >
    > > > Return emlcc
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlcc = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailBcc() As String
    > > >
    > > > Get
    > > >
    > > > Return emlbcc
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlbcc = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailSubject() As String
    > > >
    > > > Get
    > > >
    > > > Return emlSubj
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlSubj = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailBody() As String
    > > >
    > > > Get
    > > >
    > > > Return emlBod
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlBod = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > EmailGoToPage() As String
    > > >
    > > > Get
    > > >
    > > > Return emlRedirect
    > > >
    > > > End Get
    > > >
    > > > Set(ByVal Value As String)
    > > >
    > > > emlRedirect = Value
    > > >
    > > > End Set
    > > >
    > > > End Property
    > > >
    > > > Public Sub Emailer()
    > > >
    > > > Try
    > > >
    > > > Dim gjhMail As System.Web.Mail.MailMessage = New

    > System.Web.Mail.MailMessage
    > > >
    > > > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    > > >
    > > > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    > > >
    > > > gjhMail.From = emlfrom
    > > >
    > > > gjhMail.Subject = emlSubj
    > > >
    > > > gjhMail.To = EmailTo()
    > > >
    > > > gjhMail.Cc = emlcc
    > > >
    > > > gjhMail.Bcc = emlbcc
    > > >
    > > > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    > > >
    > > > System.Web.Mail.SmtpMail.Send(gjhMail)
    > > >
    > > > Catch ex As Exception
    > > >
    > > > End Try
    > > >
    > > > End Sub
    > > >
    > > >
    > > >
    > > > Protected Overrides Sub Render(ByVal output As

    > System.Web.UI.HtmlTextWriter)
    > > >
    > > > MyBase.Render(output)
    > > >
    > > > End Sub
    > > >
    > > > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    > > >
    > > > Emailer()
    > > >
    > > > End Sub

    > >
    Mike MacMillan, Dec 29, 2005
    #4
  5. GJH

    GJH Guest

    Mike, thanks so much for your responses,

    If I leave the EmailBody = TextBox1.text and have the Redirect, it does not
    redirect but sends me a blank email. BUT I get different results depending
    upon where I put my Emailer() function in the control.
    Things only seem to work when I have the settings in the Property's Tab set,
    nothing really on the code behind. Am I missing some kind of call in my
    control to have it read the codebehind page???

    I have tried it in:

    this sends 1 blank email before page is loaded
    Protected Overrides Sub Render(ByVal output As
    System.Web.UI.HtmlTextWriter)
    Emailer()
    MyBase.Render(output)
    End Sub

    this sends 1 blank email and does not redirect
    Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    Emailer()
    End Sub

    this sends 1 blank email and redirects
    Private Sub EmailButton_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles MyBase.Click
    Emailer()
    End Sub





    "Mike MacMillan" <> wrote in message
    news:...
    > GJH,
    > 2 things here:
    >
    > > but the button never retrieves the TextBox1.Text value

    > are you certain the TextBox1 control has a valid .Text property
    > upon postback? ie, is viewstate restoring the value of the textbox?
    >
    > > The Response.Redirect does work though, if i comment out the 1st

    > line.
    > does this mean if you leave the line where it set the EmailBody
    > property uncommented, it throw an error? i can't imagine why else it
    > wouldn't run the Response.Redirect unless an error was thrown. if so,
    > what is the error?
    >
    > Mike MacMillan
    >
    >
    >
    > GJH wrote:
    > > I'd like to be able to do this:
    > > Private Sub EmailButton1_Click(ByVal sender As System.Object, ByVal e As
    > > System.EventArgs) Handles EmailButton1.Click
    > > EmailButton1.EmailBody = TextBox1.text
    > >
    > > Response.Redirect(http://www.msn.com)
    > >
    > > End Sub
    > >
    > > but the button never retrieves the TextBox1.Text value. It is always
    > > Nothing.
    > > The Response.Redirect does work though, if i comment out the 1st line.
    > >
    > >
    > > thanks in advance,
    > > G
    > >
    > > "Mike MacMillan" <> wrote in message
    > > news:...
    > > > GJH,
    > > > the class looks fine, what issues are you having using it from a
    > > > codebehind? ie, how are you using it?
    > > >
    > > > Mike
    > > >
    > > >
    > > > GJH wrote:
    > > > > I am trying to develop some .NET web controls in VB or C# and need

    some
    > > > > help.
    > > > > Does anyone know any websites with a good tutorial on how to start.

    The
    > > MSDN
    > > > > site is not helping me at all.
    > > > >
    > > > > An example I have is code that will email, I simply want to create

    a
    > > button
    > > > > that has all the email code inside it, so I just have to place the

    > > button on
    > > > > my page and add some properties and be done. It works fine when

    adding
    > > the
    > > > > properties for the Property tab but cant get any properties working

    from
    > > > > codebehind.
    > > > >
    > > > > What am I doing wrong?
    > > > >
    > > > > thanks in advance, heres my code.
    > > > >
    > > > > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > > > > runat=server></{0}:EmailButton>")> Public Class EmailButton
    > > > >
    > > > > Inherits System.Web.UI.WebControls.Button
    > > > >
    > > > > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod,

    > > emlRedirect As
    > > > > String
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > SMTPServer() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return smtpText
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > smtpText = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailTo() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlto
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlto = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailFrom() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlfrom
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlfrom = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailCC() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlcc
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlcc = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailBcc() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlbcc
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlbcc = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailSubject() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlSubj
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlSubj = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailBody() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlBod
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlBod = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > > > EmailGoToPage() As String
    > > > >
    > > > > Get
    > > > >
    > > > > Return emlRedirect
    > > > >
    > > > > End Get
    > > > >
    > > > > Set(ByVal Value As String)
    > > > >
    > > > > emlRedirect = Value
    > > > >
    > > > > End Set
    > > > >
    > > > > End Property
    > > > >
    > > > > Public Sub Emailer()
    > > > >
    > > > > Try
    > > > >
    > > > > Dim gjhMail As System.Web.Mail.MailMessage = New

    > > System.Web.Mail.MailMessage
    > > > >
    > > > > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    > > > >
    > > > > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    > > > >
    > > > > gjhMail.From = emlfrom
    > > > >
    > > > > gjhMail.Subject = emlSubj
    > > > >
    > > > > gjhMail.To = EmailTo()
    > > > >
    > > > > gjhMail.Cc = emlcc
    > > > >
    > > > > gjhMail.Bcc = emlbcc
    > > > >
    > > > > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    > > > >
    > > > > System.Web.Mail.SmtpMail.Send(gjhMail)
    > > > >
    > > > > Catch ex As Exception
    > > > >
    > > > > End Try
    > > > >
    > > > > End Sub
    > > > >
    > > > >
    > > > >
    > > > > Protected Overrides Sub Render(ByVal output As

    > > System.Web.UI.HtmlTextWriter)
    > > > >
    > > > > MyBase.Render(output)
    > > > >
    > > > > End Sub
    > > > >
    > > > > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    > > > >
    > > > > Emailer()
    > > > >
    > > > > End Sub
    > > >

    >
    GJH, Dec 29, 2005
    #5
  6. GJH,
    im not sure i have enough info to give you a complete solution. my
    recommendation though would be to remote the try-catch around the logic
    in the Emailer() method and see if/what exception is thrown. were you
    able to validate whether or not TextBox1 holds a valid value when
    you're trying to set the .EmailBody property?

    Mike MacMillan


    GJH wrote:
    > I am trying to develop some .NET web controls in VB or C# and need some
    > help.
    > Does anyone know any websites with a good tutorial on how to start. The MSDN
    > site is not helping me at all.
    >
    > An example I have is code that will email, I simply want to create a button
    > that has all the email code inside it, so I just have to place the button on
    > my page and add some properties and be done. It works fine when adding the
    > properties for the Property tab but cant get any properties working from
    > codebehind.
    >
    > What am I doing wrong?
    >
    > thanks in advance, heres my code.
    >
    > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > runat=server></{0}:EmailButton>")> Public Class EmailButton
    >
    > Inherits System.Web.UI.WebControls.Button
    >
    > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod, emlRedirect As
    > String
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > SMTPServer() As String
    >
    > Get
    >
    > Return smtpText
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > smtpText = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailTo() As String
    >
    > Get
    >
    > Return emlto
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlto = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailFrom() As String
    >
    > Get
    >
    > Return emlfrom
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlfrom = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailCC() As String
    >
    > Get
    >
    > Return emlcc
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlcc = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailBcc() As String
    >
    > Get
    >
    > Return emlbcc
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlbcc = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailSubject() As String
    >
    > Get
    >
    > Return emlSubj
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlSubj = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailBody() As String
    >
    > Get
    >
    > Return emlBod
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlBod = Value
    >
    > End Set
    >
    > End Property
    >
    > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > EmailGoToPage() As String
    >
    > Get
    >
    > Return emlRedirect
    >
    > End Get
    >
    > Set(ByVal Value As String)
    >
    > emlRedirect = Value
    >
    > End Set
    >
    > End Property
    >
    > Public Sub Emailer()
    >
    > Try
    >
    > Dim gjhMail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage
    >
    > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    >
    > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    >
    > gjhMail.From = emlfrom
    >
    > gjhMail.Subject = emlSubj
    >
    > gjhMail.To = EmailTo()
    >
    > gjhMail.Cc = emlcc
    >
    > gjhMail.Bcc = emlbcc
    >
    > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    >
    > System.Web.Mail.SmtpMail.Send(gjhMail)
    >
    > Catch ex As Exception
    >
    > End Try
    >
    > End Sub
    >
    >
    >
    > Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
    >
    > MyBase.Render(output)
    >
    > End Sub
    >
    > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    >
    > Emailer()
    >
    > End Sub
    Mike MacMillan, Dec 29, 2005
    #6
  7. GJH

    GJH Guest

    Hi Mike,
    I have it in a try/catch and the only time the .EmailBody has a value is
    when I set it in the Properties Tab in the Designer. It never has a value
    when I try to set it in the click event in codebehind. None of my properties
    return a value from the button click event codebehind. Even if I try to set
    a value in the page_load event, it still returns a value of Nothing.

    I created a new Property named EmailGoToPage() which is just a string to
    redirect to after the button is clicked. I am calling it like this in my
    Emailer() method:
    Page.Response.Redirect(EmailGoToPage())

    and setting on the click event on my webpage like this:
    EmailButton1.EmailGoToPage = "http://www.cnn.com"

    and here is the error message I get:
    Value cannot be null. Parameter name: url

    I am doing: Inherits System.Web.UI.WebControls.Button for my control
    So it should be just a button with all its regular features right?

    Thanks again for your help,
    Greg


    "Mike MacMillan" <> wrote in message
    news:...
    > GJH,
    > im not sure i have enough info to give you a complete solution. my
    > recommendation though would be to remote the try-catch around the logic
    > in the Emailer() method and see if/what exception is thrown. were you
    > able to validate whether or not TextBox1 holds a valid value when
    > you're trying to set the .EmailBody property?
    >
    > Mike MacMillan
    >
    >
    > GJH wrote:
    > > I am trying to develop some .NET web controls in VB or C# and need some
    > > help.
    > > Does anyone know any websites with a good tutorial on how to start. The

    MSDN
    > > site is not helping me at all.
    > >
    > > An example I have is code that will email, I simply want to create a

    button
    > > that has all the email code inside it, so I just have to place the

    button on
    > > my page and add some properties and be done. It works fine when adding

    the
    > > properties for the Property tab but cant get any properties working from
    > > codebehind.
    > >
    > > What am I doing wrong?
    > >
    > > thanks in advance, heres my code.
    > >
    > > <DefaultProperty("Text"), ToolboxData("<{0}:EmailButton
    > > runat=server></{0}:EmailButton>")> Public Class EmailButton
    > >
    > > Inherits System.Web.UI.WebControls.Button
    > >
    > > Dim emlto, emlfrom, emlcc, emlbcc, smtpText, emlSubj, emlBod,

    emlRedirect As
    > > String
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > SMTPServer() As String
    > >
    > > Get
    > >
    > > Return smtpText
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > smtpText = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailTo() As String
    > >
    > > Get
    > >
    > > Return emlto
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlto = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailFrom() As String
    > >
    > > Get
    > >
    > > Return emlfrom
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlfrom = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailCC() As String
    > >
    > > Get
    > >
    > > Return emlcc
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlcc = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailBcc() As String
    > >
    > > Get
    > >
    > > Return emlbcc
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlbcc = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailSubject() As String
    > >
    > > Get
    > >
    > > Return emlSubj
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlSubj = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailBody() As String
    > >
    > > Get
    > >
    > > Return emlBod
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlBod = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > <Bindable(True), Category("Appearance"), DefaultValue("")> Property
    > > EmailGoToPage() As String
    > >
    > > Get
    > >
    > > Return emlRedirect
    > >
    > > End Get
    > >
    > > Set(ByVal Value As String)
    > >
    > > emlRedirect = Value
    > >
    > > End Set
    > >
    > > End Property
    > >
    > > Public Sub Emailer()
    > >
    > > Try
    > >
    > > Dim gjhMail As System.Web.Mail.MailMessage = New

    System.Web.Mail.MailMessage
    > >
    > > System.Web.Mail.SmtpMail.SmtpServer = smtpText
    > >
    > > gjhMail.BodyFormat = System.Web.Mail.MailFormat.Html
    > >
    > > gjhMail.From = emlfrom
    > >
    > > gjhMail.Subject = emlSubj
    > >
    > > gjhMail.To = EmailTo()
    > >
    > > gjhMail.Cc = emlcc
    > >
    > > gjhMail.Bcc = emlbcc
    > >
    > > gjhMail.Body = emlBod & "<br />" & vbCrLf & "<br />" & vbCrLf
    > >
    > > System.Web.Mail.SmtpMail.Send(gjhMail)
    > >
    > > Catch ex As Exception
    > >
    > > End Try
    > >
    > > End Sub
    > >
    > >
    > >
    > > Protected Overrides Sub Render(ByVal output As

    System.Web.UI.HtmlTextWriter)
    > >
    > > MyBase.Render(output)
    > >
    > > End Sub
    > >
    > > Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    > >
    > > Emailer()
    > >
    > > End Sub

    >
    GJH, Dec 30, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. R.A.M.
    Replies:
    2
    Views:
    347
    Laurent Bugnion
    Nov 16, 2006
  2. Nathan Sokalski
    Replies:
    5
    Views:
    1,006
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  3. Nathan Sokalski
    Replies:
    4
    Views:
    284
    Nathan Sokalski
    Dec 21, 2006
  4. GJH

    newbie to creating web controls

    GJH, Dec 29, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    122
    Steve Walker
    Jan 4, 2006
  5. Nathan Sokalski
    Replies:
    4
    Views:
    320
    Nathan Sokalski
    Dec 21, 2006
Loading...

Share This Page