success message afer submit an html form - asp.net

I have a simple html form like:
<form id="form1" method="post" target="_self">
<input type="text" name="lastname">
<input type="submit" value="Register" />
<form>
I want to replace the whole of this same page with just a success message
from the server, which will also show 'lastname' that was send.
Is there a simple way to do it with from the server side?
(asp.net forms application)
Thanks a lot
Liron

For message and lastname you can pass a query string and display message and another way to submit form using ajax call.

Related

Form Variable Becomes Part of Link to Web Page

We are hosting a PURL site and the variable is at the end: http://mywebpage.com/first.last
Now the client wants a static web page where you go and enter a first and last, then on submit it goes to out PURL site.
Tried this with straight html but it's not going to work. On to ASP.
New to ASP and I'm trying to have a form that has 2 fields, first, last in a link. Here is the form concept:
<form id="form1" name="form1" method="post">
<p>
<label for="1">First Name:</label>
<input type="text" name="first" id="first" />
<label for="2">Last Name:</label>
<input type="text" name="last" id="last" />
</p>
<p><input type="submit" name="3" id="3" onclick="window.open('http://mywebpage.com/first=val1&.&last=val2')"/>
</p>
</form>
Any help to put me on the right tracks would be extremely welcome at this point.
Thank you,
Ed
Try this:
<form id="form1" name="form1" method="GET" action="http://mywebpage.com/" >
Then do a normal submit without onclick and window.open.
action will submit form to that URL, and method="GET" will pass form parameters in a query string.

Can ASP.Net form have method=get or post attribute?

I am new to asp.net.
My question is, can a ASP.net form with runat="server", have a method attribute in it?
For example:
<form id="form1" runat="server" method="get">
.......
</form>
Is this possible?
Thanks for your answers.
I would like to share some points which I found.
By default the form with runat="server", will have method="post".
But when we request a page for the first time, (i.e) request is not a postback, the method="get".
And it becomes method="post",while postback.
I checked this by placing a piece of code in code behind:
In Page_Load():
if(Request.RequestType=="GET")
{
Response.Write("Request is a GET type");
}
else if(Request.RequestType=="POST")
{
Response.Write("Request is a POST type");
}
By default, the output
For the first request of that page: Request is a GET type
In postback: Request is a POST type
If i give the following code in the WebForm1.aspx
<form id="form1" runat="server" method="get">
For this, the output will be:
For the first request of that page: Request is a GET type
In postback: Request is a GET type
This is what I found.
Thank you very much for your responses.
yes you can try like below.
design part
you can design a form like :
<form id="form1" runat="server" method="post">
<input type="radio" name="Gender" value="male" id="test" checked="checked" />
male
<input type="radio" name="Gender" value="female" />female
<input type="submit" value="test" />
<asp:Button ID="btn" runat="server" Text="value" />
</form>
and how to get value from the form :
if (Request.Form["Gender"] != null)
{
string selectedGender = Request.Form["Gender"].ToString();
}
with this way you can get the value from form in asp.net.
i hope it will help you.
Yes,You can use use Method attribute..
The default will be Method="Post"
The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.
If you select view source in an .aspx page containing a form containg these properties...
Please refer : http://www.w3schools.com/aspnet/aspnet_forms.asp

Having trouble with form requests

I've setup two pages. 1.aspx, and 2.aspx.
on 1.aspx I have a form like so:
<form action="2.aspx" method="post" id="myform">
<input type="hidden" value="this works" id="mydata" />
<input type="submit" />
</form>
on 2.aspx I have this code:
Response.Write(Request.Form("mydata"))
This returns nothing.
I also tried
Response.Write(Request.Form(0))
but I get "Index was out of range." Message from the server.
I know I'm probably missing something very simple, but, I can't seem to find it!
What am I doing wrong?
Thanks!
ID is used for client-side access. Give your hidden field name="mydata" for server-side form access
Instead of having
<input type="hidden" value="this works" id="mydata" />
have
<input type="hidden" value="this works" name="mydata" />
IF you want to keep id instead of name you have to write it out differently.
you want to use document.getElementById instead of Request.form

Adding from within from runat server asp.net

I am having a signup page at the upper of the page there is a form tag that is runat server. I want to add a code that is given by paypal take payment. That code contains a simple html controls not asp.net controls but when i paste to the code to the page then it don't submit it to the action it postback the form and don't do with paypal code at all. when i checked the source of the code it doesn't shows the from tag given by the paypal. it doesn't rander the form given by the paypal. I also have to take the form at top because my page has asp.net controls that's why that is necessary.
Please tell the solution
You must not use asp.net form tag in asp.net while payment processing.
Use this
<body onload="document.paypal.submit();">
<form name="paypal" action='<%= ConfigurationManager.AppSettings["PayPalSubmitUrl"] %>'
method="post">
// rest html goes here
</form>
</body>
I always do it like this for paypal processing
I assume you are using PayPal Standard.
If so, collect submitted values from (regular ASP.Net) form. Then forward them to PayPal like this -
protected void SubmitRadButton_Click(object sender, EventArgs e)
{
string paypalUrl = IsTestMode ?
"https://www.sandbox.paypal.com/us/cgi-bin/webscr" :
"https://www.paypal.com/us/cgi-bin/webscr";
var builder = new StringBuilder();
builder.Append(paypalUrl);
builder.AppendFormat("?cmd=_xclick&business={0}", EmailTextBox.Text);
builder.Append("&lc=US&no_note=0&currency_code=USD");
builder.AppendFormat("&item_name={0}", ItemNameHiddenField.Value);
builder.AppendFormat("&amount={0}", AmountTextBox.Text);
builder.AppendFormat("&return={0}", ReturnUrl);
builder.AppendFormat("&cancel_return={0}", CancelUrl);
builder.AppendFormat("&undefined_quantity={0}", 1);
builder.AppendFormat("&item_number={0}", ItemNumberHiddenField.Value);
builder.AppendFormat("&cpp_header_image={0}", HeaderImage);
HttpContext.Current.Response.Redirect(builder.ToString());
}
I tried the same but didn't work. Please see my paypal code that they provided and let me know how to do this. I have tried the above method previously but this time isn't working with code. May be it is for subscription code different. Read the code following and let me know about how to use this.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="LL5LZEB8L6T8S" />
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_subscribeCC_LG.gif"
name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif"
width="1" height="1" />
</form>
Thanks

html-login form not working

I have a child page LoginContent.aspx which contains a login form. If the user logs in he should be redirected to my Welcome.aspx page. But if I press the login button the page just reloads itself, nothing happens.
The codebehind on this page is empty. Both LoginContent.aspx and Welcome.aspx are child forms of the same master page.
<form method="post" action="~/Welcome.aspx">
Username: <input type="text" name="username" size="15" /><br />
Password: <input type="password" name="passwort" size="15" /><br />
<input type="submit" value="Login"/></p>
</form>
I know I could use the asp.net login control but I want more control over things.
You can't have nested form inside aspx page.
UPDATED:
Since ASP.NET webform doesn't allow us to have multiple form in one aspx page, thus in order to make it works, do the following:
Remove the form tag
add runat server to
the input perform redirect in the server side
.
Username: <input type="text" name="username" size="15" runat=server /><br/>
Password: <input type="password" name="passwort" size="15" runat=server /><br/>
<input type="submit" value="Login" runat=server onclick="submit_onclick" /></p>
And in the code behind:
protected void submit_onclick(object sender, Event e)
{
// do some auth stuff here
Response.Redirect("~/welcome.aspx");
}
Hope this will answer your question.. :)
If your <form> tag from your LoginContent.aspx nested inside your <form runat="server"> I would try moving it so it sits outside the server-side form and see if it works from there.
It might be worth tracking the HTTP requests in the Net panel of Firebug as well, just so you can see if it is actually making the HTTP POST request to /Welcome.aspx - it might help you pinpoint exactly where the problem is.

Resources