Sending form data in email

G

Guest

Hello,
I want to send an email when the Insert button is clicked that includes data
entered on the form. I am using asp.net 2.0 and an insert template. I
receive the email OK, but there is no subject or body. Please help.

Here's my code:
Protected Sub InsertButton_Init(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim message As New System.Net.Mail.MailMessage()
Dim client = New System.Net.Mail.SmtpClient()
Dim prb As New String(Request.Form("insertprb"))

message.From = New System.Net.Mail.MailAddress("(e-mail address removed)")
message.To.Add(New System.Net.Mail.MailAddress("(e-mail address removed)"))
message.Subject = prb
message.Body = prb
message.IsBodyHtml = True
client.Send(message)
End Sub


Thank you for your time.
 
G

Guest

Ann said:
Hello,
I want to send an email when the Insert button is clicked that includes
data
entered on the form. I am using asp.net 2.0 and an insert template. I
receive the email OK, but there is no subject or body. Please help.

Here's my code:
Protected Sub InsertButton_Init(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim message As New System.Net.Mail.MailMessage()
Dim client = New System.Net.Mail.SmtpClient()
Dim prb As New String(Request.Form("insertprb"))

Try

Dim prb As String = insertprb.Text
 
G

Guest

I try that and I get this error:

Compiler Error Message: BC30451: Name 'insertprb' is not declared.

Source Error:



Line 18: Dim client = New System.Net.Mail.SmtpClient()
Line 19:
Line 20: Dim prb As String = insertprb.Text
Line 21:
Line 22: message.From = New
System.Net.Mail.MailAddress("(e-mail address removed)")


Do you have any other suggestions? Thanks!
 
G

Guest

I try that and I get this error:

Compiler Error Message: BC30451: Name 'insertprb' is not declared.

Source Error:

Line 18: Dim client = New System.Net.Mail.SmtpClient()
Line 19:
Line 20: Dim prb As String = insertprb.Text
Line 21:
Line 22: message.From = New
System.Net.Mail.MailAddress("(e-mail address removed)")

Do you have any other suggestions? Thanks!





- Show quoted text -

What's the ID of your TextBox Control?

<asp:TextBox ID="insertprb" ... ?
 
G

Guest

<asp:TextBox ID="Insertprb" runat="server" Text='<%# Bind("powerRequestBy") %>'
Width="193px"></asp:TextBox>
 
G

Guest

<asp:TextBox ID="Insertprb" runat="server" Text='<%# Bind("powerRequestBy") %>'
Width="193px"></asp:TextBox>

Then Dim prb As String = Insertprb.Text should give you a current text
value
 
G

Guest

So do you have any idea why I get that error? Thanks

Wait... I think I got it

Do you have that TextBox inside a data-bound control? Can I see the
code of the control?

Another question, why do you use the Init event (InsertButton_Init)?
It is fired when the button is initialized.
 
G

Guest

It is in the insert item template in a formview control. Here is the code
for this textbox:

<asp:TextBox ID="Insertprb" runat="server" Text='<%# Bind("powerRequestBy")
%>' Width="193px"></asp:TextBox>

Did you want to see the code of the entire formview control?

What event should it be in? I wasn't sure.

Thanks so much for your time.

Ann
 
N

Nesster13

It is in the insert item template in a formview control. Here is the code
for this textbox:

<asp:TextBox ID="Insertprb" runat="server" Text='<%# Bind("powerRequestBy")
%>' Width="193px"></asp:TextBox>

Did you want to see the code of the entire formview control?

What event should it be in? I wasn't sure.

Thanks so much for your time.

Ann

Ann,

If your textbox is inside a formview control, when the page display,
the id of the textbox will be altered.
For example, I have a textbox id="txt_category". When I load this page
and view the source code, I see the id of the textbox as
"ctl00_ContentPlaceHolder1_GridView1_ctl02_txt_category". This is
because my form is inside a master page and the textbox is inside a
gridview (GridView1). One way to access the textbox value is with the
FindControl method.

Here is part of the code that I used to get the value from my textbox
within a gridview control:

protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
//holding the new valud before existing update mode.
TextBox txt_category =
(TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("txt_category");
hf_new_category.Value = txt_category.Text;
}

This method use the gridview rowupdating event to look for the textbox
"txt_category" and saved the new value into a hidden field.

You should be able to apply the same logic to the formview control
textbox.
 
G

Guest

Hi Nesster13, do you happen to have VB example of this code?

Thank you so much!


Nesster13 said:
It is in the insert item template in a formview control. Here is the code
for this textbox:

<asp:TextBox ID="Insertprb" runat="server" Text='<%# Bind("powerRequestBy")
%>' Width="193px"></asp:TextBox>

Did you want to see the code of the entire formview control?

What event should it be in? I wasn't sure.

Thanks so much for your time.

Ann

Ann,

If your textbox is inside a formview control, when the page display,
the id of the textbox will be altered.
For example, I have a textbox id="txt_category". When I load this page
and view the source code, I see the id of the textbox as
"ctl00_ContentPlaceHolder1_GridView1_ctl02_txt_category". This is
because my form is inside a master page and the textbox is inside a
gridview (GridView1). One way to access the textbox value is with the
FindControl method.

Here is part of the code that I used to get the value from my textbox
within a gridview control:

protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
//holding the new valud before existing update mode.
TextBox txt_category =
(TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("txt_category");
hf_new_category.Value = txt_category.Text;
}

This method use the gridview rowupdating event to look for the textbox
"txt_category" and saved the new value into a hidden field.

You should be able to apply the same logic to the formview control
textbox.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top