Another Newbie question

  • Thread starter Thread starter Sjaak
  • Start date Start date
S

Sjaak

Hi there,

I'm starting to learn ASP.NET from this book and there is something I
don't really understand.

See the following code :
-------
<script runat="server">
Public Sub btnLogin_Click(ByVal sender As Object, ByVal e AS
System.EventArgs)
Dim objSMTP As System.Web.Mail.SmtpMail
Dim ret as object
objSMTP.Send("(e-mail address removed)", "(e-mail address removed)", "test
mail", "test")
End Sub
Public Sub Button2_Click(ByVal sender As Object, ByVal e AS
System.EventArgs)
Dim objSMTP As System.Web.Mail.SmtpMail
objSMTP.Send("(e-mail address removed)", "(e-mail address removed)", "test
mail", txtMessage.value)
End Sub
</script>

<!-- futher down in the form -->

<input type="text" id="txtMessage" name="txtMessage" size="50"
runat="server">

<asp:button id="btnLogin" Text="Login" Runat="server"></asp:button>

<input type="button" id="button2" runat="server" value="server side
html button" onserverclick="Button2_Click" name="Button2">

------------------------


The line :
<input type="text" id="txtMessage" name="txtMessage" size="50"
runat="server">
is ofcourse an input field. Now I would like to change this input
field into
a 'controltype' (not sure if that's what it's called) field like :

<asp:TextBox ID="txtmessage" Runat="server"></asp:TextBox>

When I use this code I get the error : The ID 'txtmessage' is already
used by another control. Why?

What ID should I give it?

and what should I change in the code :
---
Public Sub Button2_Click(ByVal sender As Object, ByVal e AS
System.EventArgs)
Dim objSMTP As System.Web.Mail.SmtpMail
objSMTP.Send("(e-mail address removed)", "(e-mail address removed)", "test
mail", txtMessage.value)
---

To get it to work with the new ID?

Hope this makes sense and the question isn't to stupid %-) This
asp.net is really puzzeling me.

Thanks for any help!!

Steven.
 
Sjaak,

In my opinion is your sample full of HTML controls and ASP controls mixed
between each other what makes it difficult to see what happens while there
should be with those HTML than in my opinion as well some Javascript, I
guest this.

This page is full of facts and as well samples, I would look in your
situation first too that.

http://www.systemwebmail.net/

To see more samples I think this is a very good newsgroup for the way as you
are using ASPNET. (Scripting style).

http://samples.gotdotnet.com/quickstart/

I hope this helps?

Cor
 
The newsgroup is
microsoft.public.dotnet.framework.aspnet while the link is to very good
samples.

Cor
 
One thing to keep in mind is that, if you tend to "comment out" code that you
are changing, like wrapping your original '<input type="text"
id="txtMessage"...' in HTML Comment tags (<!-- -->) before putting in the
new '<asp:Textbox id="txtMessage"...' code, the VS IDE sees both the
commented out and the new id tags, and won;t allow them to coexist. For this
you can try renaming the original input tag id value to
'...id="txtMessageOld"...'. The IDE doesn't allow the same id for ANY
'...runat="server"...' tags, even for different types.

Another thing to consider is that the "value" property of the <input> tag is
not replicated to the <asp:Textbox> tag; the <asp:Textbox> property that
would correspond is the Text property. Therefore, your
'objSMTP.Send("(e-mail address removed)", "(e-mail address removed)", "test
mail", txtMessage.value)' line would have to change to reflect this, i.e.,
'objSMTP.Send("(e-mail address removed)", "(e-mail address removed)", "test
mail", txtMessage.Text)'.
 
Back
Top