FileUpload in form HTML - c#

I have a Website and in one webpage there is a form, where one of the fields is to upload an image. I have created in my database a column picture of type LONGBINARY. I have read some webpages where they explain how to use <asp:FileUpload ID="FileUpload1" runat="server"/>. But the doubt is that I have an input tag <input id="Submit1" type="submit" value="Put In Store" /> for my form. All the webpages where they explain about FileUpload are using a ASP button, but for my form I need an submit input.
So:
What do I do if it says I need a ASP Button but I need a submit input?
Where need to be the code of the FileUpload when you click?
My last question about FileUpload(There are the links they gave me).

You can upload a file using your way. Just in the form tag, do mention the type attribute type as multipart data. So when you click on Submit the request goes to the place that is mentioned in the action attribute of the form tag.
Example form tag:
<form action="demo_post_enctype.asp" method="post" enctype="multipart/form-data">

Related

How To Used The Same Web Form

I have three web forms in asp.net
Student
Parents
Search
Student
Parents
Search
On Form Student and Parents have the same button Search, when we click on it it's redirect to form Search
Question
When i clicked Search it redirect to the web page that we has been search, I mean that on form Student and and form Parent used the same form Search.
So how can we solve the problem?
Use Jquery to Submit your form:
Example :
<form action="http://test.com">
<input type="submit" value="FirstForm"/>
</form>
<form action="http://test.com/2">
<input type="submit" value="SecondForm"/>
</form>
<form action="http://test.com/3">
<input type="submit" value="SecondForm"/>
</form>
Now Place Jquery to submit your forms uniquely:
$('form').on('submit',function(){
$(this).submit();
});
Now this will only submit the form which you have submitted.
Hope this works for you!
I think your problem already answered in this link. Another options you can use is by passing the source page in a "query string" or in a session

input "id" and "name" changes when set runat=server from

In my form I need to insert different inputs of type "hidden".
The inputs must be html controls with "name" and "id's". Because I send this form to a external url.
For the validation I do runat=server in a hidden input and then I can use requiredfieldvalidator.
But the problem is when I look in the source after visiting the page the name is changed. for example
<input type="hidden" name="hotelIdform" value="" runat="server" id="hotelIdform">
changed to
<input name="ctl00$ctl00$Master_Body$child_center_content$hotelIdform" type="hidden" id="hotelIdform" value="b4ba78fc-0b62-4809-9dca-000972573139" />
and i used ClientIDMode="Static" , just ID is okay
please help me
It seems you are using Master pages and not using static client ID. Thus, ASP.NET is changing the ID while it compiling the page.
You need to set ClientIDMode to Static.
Please refer this SO post

Umbraco 4.11.3 : Client side form upload (multipart/form-data) gives 404

I'm using umbraco with extensionless urls.
I've inserted a simple piece of HTML in one of my masterpages (en/test) :
<form method="post" enctype="multipart/form-data">
<input type="submit" />
</form>
When I press the submit button, I get a 404. The path is exactly the same and should exist.
When I remove the enctype part, the submit occurs fine.
I can't figure out how to fix this, but I bet it has something to do with the rewriting.
I also tried the following without success:
<form method="post" enctype="multipart/form-data" action="/en/test">
<input type="submit" />
</form>
<form method="post" enctype="multipart/form-data" action="/en/test.aspx">
<input type="submit" />
</form>
The only page where I CAN use the enctype attribute, is on the actual homepage. I guess this has to do with the fact that the physic default.aspx exists.
=============== UPDATE =================
There is only one form element in the page, the one that I've inserted. So a "whole page" form element is certainly not the case. Secondly, yes the form is in theory posting back to itself. I also tried an empty action tag, plus an action tag with the full url as suggested, with the same results.
When I either use the following scenario's:
No action attribute
action=""
action="{relative path}"
action="{absolute path}"
I end up on exact same URL as where I fired the submit from. But it's a 404. When I press the enter key in my address bar, no 404, I'm back at my original page with the same URL.
First question I should ask is do you get a 404 when you browse to "/en/test" or "/en/test.aspx". For the form to post back to itself try an empty action e.g. action="" or writing the current url into the action attribute. And one further question, do you have another form wrapped around your page with the runat="server" attribute because if you have you will end up with nested forms which will also cause you issues.
On a side node I would strongly suggest upgrading your installation to at least v4.11.4 due to a bug that was introduced in 4.10. Please see the following for details...
Trying to publish a root node (parent) after unpublishing a child result in a YSOD:
http://issues.umbraco.org/issue/U4-1491
Path Fixup
http://our.umbraco.org/projects/developer-tools/path-fixup

POST HTML <form> to external aspx page

I have already read through this. However, in my case the page I am posting to is an external .aspx page.
Basically I generate XML data on the source page code with XElement, and need to POST that to an external .aspx page. The requirement say it needs to be wrapped in HTML </form> tag before posting. So my string in the code-behind file looks like
<FORM id="frmLogin" action="https://illustration.sagicorlifeusa.com/fse5/main/FormPost.aspx" method="post" target=blank>
<XML>myxml<XML\>
<input type="submit" name="__exclude__Submit" value="Run Sagicor Life Illustration Software Online ">
</form>
Now on the code-behind file, what is it that I need to do, to post this to the external .aspx page?
You can add a hidden input, set its value in codebehind and post the form to the destination page so that on that page the value can be extracted back. Did i understand your question?
That doesn't make sense. You normally don't post HTML code.
You should check the requirement for what they really want. My guess is that you would put it in an HTML tag if you post it from the browser, but that would not apply if you post it from the server.

Form GET in ASP.NET

I'm trying to convert a classic ASP page to ASP.NET 3.5.
On the page, there is a small form to submit your e-mail address to an external newsletter site. Here's the code:
<form name="emailForm" action="http://www.site.com/emailsignup.aspx" method="get">
<input type="text" name="email" />
<input type="submit" id="btnSubmit" name="btnSubmit" />
</form>
I was hoping I'd just be able to drop this on the page and it would work, but it doesn't, it just reloads the page.
How am I supposed to do this? Does it need to be done in the code behind of the button's click event?
In ASP.Net, by default controls - like the button - that cause postbacks will submit the page back to itself EVEN if you set the action attribute on the page to another file. What you want is called Cross-Page Posting. The following MSDN pages shows you how to do this with ASP.Net 4, but there is a link at the top to get to older versions:
http://msdn.microsoft.com/en-us/library/ms178140.aspx
http://msdn.microsoft.com/en-us/library/ms178139.aspx
Otherwise you can just use the Button's Click Event Handler in the code behind.
Hope this helps.
you must be missing runat="server" in the form tag
try to create a page through the IDE and paste the code for input tags between the form tags
<input type="text" name="email" />
<input type="submit" id="btnSubmit" name="btnSubmit" />
It surely is ending nested in the form aspx get by default.
Depending on the layout of your page, you can modify it so you don't end with a nested form. If that's not possible, I think you can't get around to use a form, so instead you'll have to look at a different solution like building the get with js.
The easiest way would be to put that <form> tag outside the main <form runat="server"> tag that usually wraps all ASP.NET controls.
If you're using a master page and the only content placeholder you can use is within that <form runat="server" tag, or you need this form tag in the page structure within the main <form runat="server"> tag then you need to:
Take out the simple <form> tag but leave the HTML <input> tags. Handle the client onclick event (the JavaScript versions, not ASP.NET postback handlers) of the submit button. That handler should grab the e-mail from the text box and issue something like window.location = 'http://www.site.com/emailsignup.aspx?email=....' in Javascript. Make sure to cancel the default HTML button action handler so it doesn't bubble up and submit the ASP.NET form too.

Categories