I am developing a website using asp.net c# and I want to put a form inside the page. Now as aspx pages have the form tag I do not want to nest another form inside this as it will invalidate my html. But I need this form to use GET rather than POST. I know I can change the postback url in the asp:button. Can this be done without using logic in the codbehind?
Change the method to GET just for this form not every thing on the page
change the target to _blank if possible.
Example in html of what I want.
<form action="http://maps.google.co.uk/maps" method="get">
<p><label for="saddr">Your postcode</label>
<input type="text" name="saddr" id="saddr" value="" />
<input type="submit" value="Go" />
<input type="hidden" name="daddr" value="[destination]" />
<input type="hidden" name="hl" value="en" /></p>
</form>
you can use jquery to accomplish this
$(document).ready(function() {
$("#buttonId").click(function() {
$("#formId").attr("method", "get");
});
});
the above snippet, fires when the button with id 'buttonId' is clicked. it changes the method attribute of the form with id 'formId'
You can have multiple forms in an html. ASP.NET page also supports multiple form tags, however only one of then can be server side form (runat="server").
So I will suggest that you add another form tag within your page - some thing like
...
<body>
<form runat="server">
... server controls etc
</form>
<!-- your form -->
<form action="http://maps.google.co.uk/maps" method="get">
<p><label for="saddr">Your postcode</label>
<input type="text" name="saddr" id="saddr" value="" />
<input type="submit" value="Go" />
<input type="hidden" name="daddr" value="[destination]" />
<input type="hidden" name="hl" value="en" /></p>
</form>
</body>
</html>
Note that you cannot put any server side control in your html tag. So you have to use html controls and manage them within page code using Request object.
Related
I have a simple form for payment:
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input name="data" value="{{data}}" />
<input name="signature" value="{{signature}}" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
The problem is that I can't press the button for payment, it's just don't work
I can assure you that the form is working I've checked this on C# with some changes:
<div class="container">
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input type="hidden" name="data" value="#ViewData["PaymentData"]" />
<input type="hidden" name="signature" value="#ViewData["Signature"]" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
</div>
And all the parametress a passed correctly. It seems like Angular dont let me go to the link or sth like that. Help pls.
UPDATE
Ok I changed the form like this:
<form [formGroup]="payForm" (ngSubmit)="LiqPay()" #formDir="ngForm" novalidate>
<input formControlName="data" name="data" value="{{data}}" />
<input formControlName="signature" name="signature" value="{{signature}}" />
<button type="submit" class="btn btn-default" ng-href="https://www.liqpay.ua/api/3/checkout">go</button>
</form>
with LiqPay method:
LiqPay(){
let headers = new Headers();
headers.append('Content-Type', 'application/json');
this.payForm.value.data = this.data;
this.payForm.value.signature = this.signature;
this._http.post('https://www.liqpay.ua/api/3/checkout',
this.payForm,{headers}).map((response: Response) => response.json());
}
Now I guess the request is sent but it doesn't redirect on the desired link (https://www.liqpay.ua/api/3/checkout). So how can I change the form to redirect to this link with post data?
In the LiqPay method you are trying to send a post request to https://www.liqpay.ua/api/3/checkout. And in the button you have a ng-href attribute (trying to browser go to that url). I think that is not correct. You are sendind an asynchronous requets, and simultaneously sendind your user to that url.
I can understand, you are sending a form to a payment checkout? ok, you can use action in the form, exactly like the C# example.
I have tested your initial code
<form method="POST" action="https://www.liqpay.ua/api/3/checkout" accept-charset="utf-8">
<input name="data" value="{{data}}" />
<input name="signature" value="{{signature}}" />
<input type="image" src="//static.liqpay.ua/buttons/p1ru.radius.png" />
</form>
And it works...
You can view it here:
https://jsfiddle.net/L1ruajzn/
This a html code in site that i want to use it in my web browser control C# :
<form name="frmWorkBookPrintTerm" action="WorkBookPrintTerm.asp" target="_blank" method="post">
<hr width="90%">
<input type="Hidden" name="strTermCode" value="912">
<input type="Hidden" name="strStudentCode" value="896325605">
<input type="Button" onclick="javascript:document.frmWorkBookPrintTerm.submit();" value="...">
<hr width="90%">
</form>
But It is not working. When i want to go ".../WorkBookPrintTerm.asp" directly website says you did illegal job and otherwise web browser control is not working.
Thank You.
I have to add simple form to a asp:PlaceHolder
<form action="https://www...." method="post" target="_top">
<input type="hidden"...
<input type="hidden"...
<input type="image" ...name="submit">
</form>
In PageLoad() I added:
data = "<form action=...."
this.myPlaceHolder.Controls.Add(new LiteralControl(data));
When page rendered page source is:
<input type="hidden"...
<input type="hidden"...
<input type="image"...name="submit"...
<img alt=""...
As you can see no form tag?
But I am sure that data variable contains "<form ...".
Is there any other way to add form to placeholder maybe I use wrong approach?
I have to add this answer maybe will help someone.
When I add "<form..." form tag is not added but
If I add "<form></form><form..." to palceholder then it works.
I don't understand why but it works fine.
instead of adding a form dynamically you should add those to the asp file. like this:
<form action="https://www" method="post" target="_top">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
then you can add any object on the placeholder.
I have a simple form in my MVC3 site that allows users to create a contest entry. This has been implemented and works fine currently, but a request has been made to now allow users to make their entries private.
In my Entry model I added a boolean isPrivate. Then I figured I would change the HTML forms for create and edit to include a checkbox to specify whether the entry should be private.
I'm new to MVC3, but I figured I could simply change the action that the form posts to by including a new boolean parameter.
This unfortunately doesn't seem to work. Can anyone tell me how checkbox values are passed from an HTML form to a post action? This is probably fairly common, but I can't seem to find an example for this on the web. Almost all the examples out there simple show text inputs, I can't find anything with checkboxes.
Form:
<form method="post" action="../Entry/Create" enctype="multipart/form-data" onsubmit="return isValidInput()">
<input type="text" id="EntryTitle" name="EntryTitle" />
<div id="invalidTitle" class="invalidData"></div>
<p id="char-remaining">(100 characters remaining)</p>
<input type="text" id="EntryVideo" name="EntryVideo" />
<div id="invalidVideo" class="invalidData"></div>
<p id="vid-desc">(URL of the Video to Embed)</p>
<input type="file" id="ImageFile" name="ImageFile" />
<div id="invalidImage" class="invalidData"></div>
<p id="file-desc">(200x200px, jpeg, png, or gif)</p>
<textarea id="EntryDesc" name="EntryDesc"></textarea>
<div id="invalidDesc" class="invalidData"></div>
<br />
<input type="checkbox" id="isPrivate" name="isPrivate" />
Make my entry private.
<br />
(private entries will only be viewable by you and site administrators)
<br />
<button id="new-entry-save">save</button>
</form>
Action:
public ActionResult Create(string EntryTitle, string EntryVideo, HttpPostedFileBase ImageFile, string EntryDesc, Boolean isPrivate)
{
...
}
add value="true" to checkbox, also add hidden input after it with same name and value=false, i.e.:
<input type="checkbox" id="isPrivate" name="isPrivate" value="true" />
<input type="hidden" name="isPrivate" value="false" />
If you don't want to use hidden, use bool? instead of bool (e.g. nullable)
The other option is to have hidden text field with the same name to force data in unchecked field to be part of the post. See Post the checkboxes that are unchecked.
<form>
<input type='hidden' value='0' name='selfdestruct'>
<input type='checkbox' value='1' name='selfdestruct'>
</form>
I have a form
<form action="/" method="post">
<input type="file" name="myFile" />
<input type="submit" name="submit" value="submit" />
</form>
I also have some C# code
if (Request["submit"] == "submit") {
Response.Write(Request.Files.Count);
}
If a user chooses a file on their system and submits, What reasons could there be for me seeing a "0" instead of a "1" in the Request.Files.Count property?
Try adding the enctype attribute to your <form>
<form enctype="multipart/form-data" action="/" method="post">
If you are using any kind of ajax (i.e. update panel) then you have to make sure you're doing a full page post back when submitting not a partial page postback.