All the examples I can find are in Visual Basic, but I am using C#.
I want to get the data that is in a textbox in a form.
My code so far:
<form action="login.aspx" method="get">
<p>Username: <input type="text" name="username" /></p>
<p>Password: <input type="text" name="password" /></p>
<input type="submit" value="Submit" />
</form>
So what could I do? Because I keep getting told to do this:
Dim UserName
UserName = Request.Form("UserName")
But it doesn't work in C#.
Don't need to do that on asp.net; simply change your markup like so:
<form action="login.aspx" method="post" runat="server">
<p>Username: <input type="text" name="username" runat="server" id="txtUsername" /></p>
<p>Password: <input type="text" name="password" runat="server" id="txtPassword"/></p>
<input type="submit" value="Submit" />
</form>
And on code behind:
string UserName= txtUsername.Value;
And yes, Shawn also caught a good one, you should use POST.
Your method should be POST.
<form action="login.aspx" method="post">
The sample code you posted is vb.net. C# has it's own syntax and keywords.
to get the value you can use the following (not an optimal solution for webforms)
string userName = Request.Form["UserName"];
I would suggest going through some c# tutorials to get a handle on the language. Here's the first one i found http://www.csharp-station.com/Tutorial.aspx
Related
I need to take the username, email and password a user enters in an html form (in index.aspx) and use it in an asp.net code in another page (register.aspx in a folder called 'u').
This is the form:
<form action="u/register.aspx" method="post" id="regForm">
<input type="text" name="fname" id="fname" placeholder="Full Name (Optional)" maxlength="16" />
<input type="text" name="uname" id="uname" placeholder="Username" maxlength="16" />
<input type="email" name="email" id="email" placeholder="Email Address" maxlength="32" />
<input type="password" name="pwd" id="pwd" placeholder="Password" maxlength="16" />
<input type="password" name="repwd" id="repwd" placeholder="Repeat Password" maxlength="16" />
<input type="submit" value="Sign Up" id="signup" />
</form>
But, when I'm using Request.QueryString["fname"] for example, it doesn't take 'fname' from the form, it just takes a null.
What can I do to solve this? Is there a different method I can use to achieve the wanted result?
Thanks a lot!
You are doing it wrong.
Request.QueryString contains information related to data added after ? in the URL (ex. http://www.contoso.com?mydata=1¶m2=yy).
You have to use Request.Form to access "POST" data.
QueryString will only give the parameters on the query string of the url check here.
If you want all the parameters you will need to use the Params property.
As others have already said Request.QueryString contains data after the ? in url.
You can use Request.Form or if you want the data as part of the url, you can change your form element method attribute to "get"
I have done an interswitch payment gateway in my regular asp.net webform and asp.net mvc.
But I have a requirement to do the same in dotnetnuke which i know i can through module.
In my pay now pay of my application i have a form to send data across to interswitch webservice the form is below
<form name="form1" action="https://stageserv.interswitchng.com/test_paydirect/pay"
method="post">
<input name="product_id" type="hidden" value="XX" />
<input name="pay_item_id" type="hidden" value="XX" />
<input name="amount" type="hidden" value="XXXXXXX" />
<input name="currency" type="hidden" value="566" />
<input name="site_redirect_url" type="hidden" value="http://abc.com /getresponse”/>
<input name="txn_ref" type="hidden" value=" XXXAFTXXX”" />
<input name="hash" type="hidden" value="BB292DF9268F05CB9CBBC5E0C13CC1B13ACA34DC" />
</form>
I need someone to help me out on how i can implement this in my dotnetnukes module.
I faced a similar problem and asked this question. The accepted answer here is how I ended up doing it.
I just added the input fields to the page and then changed the "Pay" buttons PostBackUrl
This way you don't need to add an additional form to the page, and when the user clicks the button, it will submit those fields, so obviously it will pick up the ones it's looking for.
So in your case it would be:
<%-- other page content before --%>
<input name="product_id" type="hidden" value="XX" />
<input name="pay_item_id" type="hidden" value="XX" />
<input name="amount" type="hidden" value="XXXXXXX" />
<input name="currency" type="hidden" value="566" />
<input name="site_redirect_url" type="hidden" value="http://ipsum.com/getresponse”/>
<input name="txn_ref" type="hidden" value=" XXXAFTXXX”" />
<input name="hash" type="hidden" value="BB292DF9268F05CB9CBBC5E0C13CC1B13ACA34DC" />
<%-- pay button would look like this --%>
<asp:Button ID="btnPayNow" runat="server" PostBackUrl="https://stageserv.interswitchng.com/test_paydirect/pay" Text="Pay Now!" />
<%-- other page content after --%>
Of course if you have multiple payment gateway options you can set the PostBackUrl programatically before you display the form: btnPayNow.PostBackUrl = "http://<url>.com"
If you are posting to another site, not even anything on your site then you don't need a module at all.
With DNN you cannot include another form on your site like that. But you could make that a .html page and include that on your site as an iframe or something like that.
That should post to that other service fine.
I am trying to incorporate a reservation widget within my wordpress install and I have everything working fine except sending the data or it not populating on the other sites form. The site I am trying to send data to is an online reservation software: http://www.directinn.com/demo/
Here is how I am doing my form:
<form name="bookingform" action="http://www.directinn.com/demo" method="get" target="_blank">
<input type="text" name="date1" id="Text1" class="ftxt MyDate three columns" maxlength="10" value="" placeholder="Arrival Date"/>
<input type="text" name="date2" id="Text2" class="ftxt MyDate three columns" maxlength="10" value="" placeholder="Departure Date" />
<input type="submit" name="bookingformsubmit" class="book-now" value="Book Now">
<input type="hidden" name="arrivalDay" value="" />
<input type="hidden" name="arrivalMonth" value="" />
<input type="hidden" name="arrivalYear" value="" />
<input type="hidden" name="departureDay" value="" />
<input type="hidden" name="departureMonth" value="" />
<input type="hidden" name="departureYear" value="" />
<input type="hidden" name="numAdults" value="1" />
Any help would be greatly appreciated ;)
So they are saying if you can iFrame in their Form on your page and if you add the USERNAME for example to the URL, your USERNAME will appear on the invoice. Like this I believe:
http://www.directinn.com/iframefull.html/BOB
I do not think you can make your own form and POST to their page. I see no indication that that is possible from the link you posted of the example.
The code you have will submit a load of Query String data to the receiving site.
The target site may implement some type of cross-site posting prevention which is causing the blockage - or they may ignore your query string parameters entirely.
Basically I want to place a url in the form action method.
The ltlUrl.text value is added on the server side in pageLoad.
How do i use the ltlUrl as the action method?
<form action="<%# ltlurl.text%>" enctype="multipart/form-data">
<input type="text" name="title" value="test" />
<input type="file" name="file" />
<input type="submit" />
</form>
Since you are populating the text control on code behind, you can simply do this:
this.Page.Form.Action = "http://someour";
I believe the VB.NET syntax would be:
Me.Page.Form.Action = "http://someurl"
How to call a Session and use it as a value of Text Box Form. I am using asp.net
<form id="frmLog" name="frmLog" method="post" action="/Page/">
<input type="text" name="UserId" value="<%=Sessiopn["UserID"] %>">" />
</form>
Thanks!
Correct it to this. You have a typing mistake.
<input type="text" name="UserId" value="<%=Session["UserID"] %>" />
you have error on variable name (without p)
Sessiopn -> Session