Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > newbie to creating web controls

Reply
Thread Tools

newbie to creating web controls

 
 
GJH
Guest
Posts: n/a
 
      12-29-2005
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


 
Reply With Quote
 
 
 
 
addup
Guest
Posts: n/a
 
      12-30-2005
> cant get any properties working from codebehind.

What's not working?
I ask because I can't really see anyhing wrong here.

If nothing seems to be happening on click, it may be because your
Public Sub Emailer (why is it public?) does not have correct error
handling

Try this, and see if you get an error message

Catch ex As Exception
HttpContext.Current.Response.Write("<BR>ERROR: " & ex.Message)
End Try


Hope this helps
-- addup --

 
Reply With Quote
 
 
 
 
GJH
Guest
Posts: n/a
 
      12-30-2005
Hi addup,
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,
G


"addup" <> wrote in message
news: ups.com...
>> cant get any properties working from codebehind.

>
> What's not working?
> I ask because I can't really see anyhing wrong here.
>
> If nothing seems to be happening on click, it may be because your
> Public Sub Emailer (why is it public?) does not have correct error
> handling
>
> Try this, and see if you get an error message
>
> Catch ex As Exception
> HttpContext.Current.Response.Write("<BR>ERROR: " & ex.Message)
> End Try
>
>
> Hope this helps
> -- addup --
>



 
Reply With Quote
 
Steve Walker
Guest
Posts: n/a
 
      01-04-2006
In message <#>, GJH
<> writes

>What am I doing wrong?


You are overriding the OnClick method in your control. That means that
the OnClick method of the base class (button) is never called. One of
the things that the OnClick method of the base class evidently does is
to call the Click() delegate. Since you are overriding OnClick, this
never happens. Since this never happens, your code-behind event handler
for Click never gets called.

You can force the base class's OnClick implementation to execute before
your custom version by adding whatever the VB equivalent is of the C#

base.OnClick(e);

as the first line of code in

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

Emailer()

End Sub

MyBase.OnClick(e)? Something like that.

Note that this doesn't explain why you can't set the values in the page
load event. That may be a separate issue.


--
Steve Walker
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net 5 01-10-2007 10:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Web Controls 4 12-21-2006 02:50 AM
Using Web.config's <system.web><pages><controls><add /></controls></pages></system.web> To Register UserControls Nathan Sokalski ASP .Net Building Controls 4 12-21-2006 02:50 AM
newbie: HTML controls vs Web controls R.A.M. ASP .Net 2 11-16-2006 08:21 AM
newbie to creating web controls GJH ASP .Net Building Controls 6 12-30-2005 03:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57