473,473 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Webform post handling

Hi all,

This is probably a simple question, but I'm just getting started in ASP.NET,
and I can't find the answer.

I have a simple form with a "Submit" button. When the user clicks on the
button, I want to post the data in the field to a URL, which is, of course,
very simple. But I also want it to send me an email message.

I know how to do either ONE of those things, but not both. I'm working in
C#. Is there some "post" command I can use in the button handling code that
will do this?

Thanks,
Dan
Nov 16 '05 #1
6 3510
Hi Eagle:

Is the Submit button an ASP.NET server control? I.e, if you look at
the code view for the ASPX page, you should see:

<asp:Button runat="server" ... />

and not an HTML <input> tag.

If you use a server side button (just drop one on the web form from
design view), ASP.NET will automatically post back to the same form
when the user clicks the button. You can add an event handler for the
button by double clicking on the button in design view. From inside
the event handler you could add the little bit of code to send off an
email.

HTH,

--
Scott
http://www.OdeToCode.com/

On Sun, 03 Oct 2004 20:59:24 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi all,

This is probably a simple question, but I'm just getting started in ASP.NET,
and I can't find the answer.

I have a simple form with a "Submit" button. When the user clicks on the
button, I want to post the data in the field to a URL, which is, of course,
very simple. But I also want it to send me an email message.

I know how to do either ONE of those things, but not both. I'm working in
C#. Is there some "post" command I can use in the button handling code that
will do this?

Thanks,
Dan


Nov 16 '05 #2
Hi Scott,

Thanks, but I'm still not clear what to do.

For example -- if I have the following HTML form, the data is sent to the indicated web site and interpreted, but no mail message is sent.

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

If I make it an ASP.NET server control with a handler, I think it would look something like this:

private void btnSubmit_Click(object sender, System.EventArgs e)
{
MailMessage mailMsg = new MailMessage();

mailMsg.From = so****@some.com;
mailMsg.To = de**@other.com;
mailMsg.Subject = "Order Form";
mailMsg.Body = "First Value. Second Value. Third Value";

SmtpMail.Send( mailMsg );

// But I don't know what to put here to post the form data to
// https://www.someURL.com/processor.cfm
...
}

Thanks,
Dan

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:i0********************************@4ax.com...
Hi Eagle:

Is the Submit button an ASP.NET server control? I.e, if you look at
the code view for the ASPX page, you should see:

<asp:Button runat="server" ... />

and not an HTML <input> tag.

If you use a server side button (just drop one on the web form from
design view), ASP.NET will automatically post back to the same form
when the user clicks the button. You can add an event handler for the
button by double clicking on the button in design view. From inside
the event handler you could add the little bit of code to send off an
email.

HTH,

--
Scott
http://www.OdeToCode.com/

On Sun, 03 Oct 2004 20:59:24 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi all,

This is probably a simple question, but I'm just getting started in ASP.NET,
and I can't find the answer.

I have a simple form with a "Submit" button. When the user clicks on the
button, I want to post the data in the field to a URL, which is, of course,
very simple. But I also want it to send me an email message.

I know how to do either ONE of those things, but not both. I'm working in
C#. Is there some "post" command I can use in the button handling code that
will do this?

Thanks,
Dan

Nov 16 '05 #3
Hi Dan:

First, I might be confused about where you are posting. Are you
posting a form back to the same application? Your application?

If so, you could create a web form similar to the following (notice
runat="server" on the input) :

<form id="Form1" method="post" runat="server">
<INPUT id="Hidden1" type="hidden" name="Hidden1" runat="server">
<asp:Button id="Button1" runat="server"
Text="Button">
</asp:Button>
</form>

And the code behind something like:

public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string s = Hidden1.Value;
// send email, etc.
}
}

If you are posting to another application, you might want to check all
the form variables to make sure the names are correct. Perhaps the
other server is doing additional validation with cookies or by looking
at the referer header to make sure the POST is coming from someone who
has been to their application.

Hope this is making more sense for you,

--
Scott
http://www.OdeToCode.com/

On Tue, 05 Oct 2004 05:28:27 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi Scott,

Thanks, but I'm still not clear what to do.

For example -- if I have the following HTML form, the data is sent to the indicated web site and interpreted, but no mail message is sent.

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

If I make it an ASP.NET server control with a handler, I think it would look something like this:


Nov 16 '05 #4
Hi Scott,

Thanks for your help.

The page I want to implement is a confirmation of a customer's order just
BEFORE the order is placed. When they click the "Submit" button on this
confirmation page, two things have to happen --
(1) The page has to send me an email with the information about the order,
and
(2) It has to post some information to a DIFFERENT web site, which will
process their credit card information.

The following static HTML code works just fine to do part number (2), i.e.,
post the action to process the credit card information. But it does nothing
to send me an email about the details of the order. So clearly I have to
use ASP.NET rather than static HTML

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

Supposing I was using your ASP.NET code below, and can get the email part
working -- what can I put in method "Button1_Click" that would do the same
thing as the 6 lines above -- i.e., submit the form data to some other URL,
for example https://www.someURL.com/processor.cfm.

Thanks,
Dan

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:uv********************************@4ax.com...
Hi Dan:

First, I might be confused about where you are posting. Are you
posting a form back to the same application? Your application?

If so, you could create a web form similar to the following (notice
runat="server" on the input) :

<form id="Form1" method="post" runat="server">
<INPUT id="Hidden1" type="hidden" name="Hidden1" runat="server">
<asp:Button id="Button1" runat="server"
Text="Button">
</asp:Button>
</form>

And the code behind something like:

public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new
System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string s = Hidden1.Value;
// send email, etc.
}
}

If you are posting to another application, you might want to check all
the form variables to make sure the names are correct. Perhaps the
other server is doing additional validation with cookies or by looking
at the referer header to make sure the POST is coming from someone who
has been to their application.

Hope this is making more sense for you,

--
Scott
http://www.OdeToCode.com/

On Tue, 05 Oct 2004 05:28:27 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi Scott,

Thanks, but I'm still not clear what to do.

For example -- if I have the following HTML form, the data is sent to the
indicated web site and interpreted, but no mail message is sent.

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

If I make it an ASP.NET server control with a handler, I think it would
look something like this:

Nov 16 '05 #5
Hi Dan:

Ah, I see now. Yes, it's quite possible to POST to another server from
inside the click event. You'll need to use the WebRequest class from
the System.Net namespace. It can make HTTP requests (both GET and
POST) to another web server.

I have a few links handy:

Look at ClientPost and ClientGetWithSSL here:
http://msdn.microsoft.com/library/de...networking.asp

Screen Scraping, ViewState, and Authentication using ASP.Net
http://odetocode.com/Articles/162.aspx

I know from experience, however, it can be tricky to get just right
and debug. The server will expect all the POSTed values in just the
right format. It's even harder over SSL because there are no tools
that can snoop the traffic and watch what is being passed.
hth,

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 05 Oct 2004 21:27:49 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi Scott,

Thanks for your help.

The page I want to implement is a confirmation of a customer's order just
BEFORE the order is placed. When they click the "Submit" button on this
confirmation page, two things have to happen --
(1) The page has to send me an email with the information about the order,
and
(2) It has to post some information to a DIFFERENT web site, which will
process their credit card information.

The following static HTML code works just fine to do part number (2), i.e.,
post the action to process the credit card information. But it does nothing
to send me an email about the details of the order. So clearly I have to
use ASP.NET rather than static HTML

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

Supposing I was using your ASP.NET code below, and can get the email part
working -- what can I put in method "Button1_Click" that would do the same
thing as the 6 lines above -- i.e., submit the form data to some other URL,
for example https://www.someURL.com/processor.cfm.

Thanks,
Dan


Nov 16 '05 #6
Hi Scott,

Thanks for the help. I'll have to look into those web sites.

I'm also wondering if the "Response.Redirect" method might be the right
vehicle, if I can attach the Response name/value pairs.

Thanks,
Dan
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:tf********************************@4ax.com...
Hi Dan:

Ah, I see now. Yes, it's quite possible to POST to another server from
inside the click event. You'll need to use the WebRequest class from
the System.Net namespace. It can make HTTP requests (both GET and
POST) to another web server.

I have a few links handy:

Look at ClientPost and ClientGetWithSSL here:
http://msdn.microsoft.com/library/de...networking.asp

Screen Scraping, ViewState, and Authentication using ASP.Net
http://odetocode.com/Articles/162.aspx

I know from experience, however, it can be tricky to get just right
and debug. The server will expect all the POSTed values in just the
right format. It's even harder over SSL because there are no tools
that can snoop the traffic and watch what is being passed.
hth,

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Tue, 05 Oct 2004 21:27:49 GMT, "Eagle Rock" <er*@sbcglobal.net>
wrote:
Hi Scott,

Thanks for your help.

The page I want to implement is a confirmation of a customer's order just
BEFORE the order is placed. When they click the "Submit" button on this
confirmation page, two things have to happen --
(1) The page has to send me an email with the information about the order,
and
(2) It has to post some information to a DIFFERENT web site, which will
process their credit card information.

The following static HTML code works just fine to do part number (2),
i.e.,
post the action to process the credit card information. But it does
nothing
to send me an email about the details of the order. So clearly I have to
use ASP.NET rather than static HTML

<form method="post" action="https://www.someURL.com/processor.cfm">
<input type="hidden" name="var1" value="First Value">
<input type="hidden" name="var2" value="Second Value">
<input type="hidden" name="var3" value="Third Value">
<input type="submit" value="Submit">
</form>

Supposing I was using your ASP.NET code below, and can get the email part
working -- what can I put in method "Button1_Click" that would do the same
thing as the 6 lines above -- i.e., submit the form data to some other
URL,
for example https://www.someURL.com/processor.cfm.

Thanks,
Dan

Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Phillip N Rounds | last post by:
I have a webform, from which I have to submit info to another site. Their instructions are to have a html form, with the following as the submit: <form method="post"...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
5
by: Jerry | last post by:
I am using .Net 2003. I have been working with this ASP.Net webform that I created a few weeks ago. It has been working fine. However, while modifying the webform today, this webform stopped...
2
by: mg | last post by:
What code (javascript) will cause a WebForm to be submited (runatserver) whenever a new character is typed into a TextBox from the keyboard?
3
by: Harry | last post by:
Dear all, It is found that when a webform control trigger an event, Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub This...
2
by: Craig Douthitt via DotNetMonster.com | last post by:
I am trying to capture an buttonclick on a usercontrol in the webform the usercontrol resides in. After researching this issue, I've come to believe that the best way of handling this is by raising...
0
by: Solitus | last post by:
I have a difficult scenario here. Previously I have tried to post something similar here, unfortunately I got no solution. For simplicity I have created something simple to simulate my problem. I...
2
by: lakshmikandhan | last post by:
Hi All, Can anyone tell me how to handle a event while we are closing a webform in asp.net??? I have to perform some server side action while we are closing a webform.So plz give me some idea...
5
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have start web form and when the user clicks a button (server.transfer) they are directed to the second webform. I was wondering if there is a way to create an instance of the first webform...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.