I am doing following in one of my webpart .ascx file.
<FORM action="https://illustration.sagicorlifeusa.com/fse5/main/FormPost.aspx" id="frmLogin" method="post" target=blank>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<%= CompleteRequest %>
<input type="submit" name="__exclude__Submit" value="Run Sagicor Life Illustration Software Online" />
Notice the method="post"; However, looks like when I add this web-part, The hosting page already has a <FORM/> . How can I do the above POST?
posting to a new window from inside an ASPX web form (which SharePoint is) is tricky, because the framework wraps everything in a <form> it keeps track of. If you are required to post to the target page (i.e. get isn't good enough), you might have to:
create a separate .aspx page entirely to produce the form
open that form from within your Web Part with a JS call to window.open or an <a href="..." target="blank"
auto-post that form, with JavaScript, as soon as it loads.
(I have no firsthand experience with sharepoint; take this answer with a grain of salt.)
Related
I have a HTML page which is dynamically generating by server. The application has an IDE to generate and design pages then deploy the server. The server displaying this pages in an iframe. We can use all c# methods as well as Page_Load and Page_PreRender events in pages. But I can't modify source code of the asp.net page (I mean can't add runat="server").
What I want to do, finding a html tag by css class (#form1 > span) before pre-render then add a new css property in code behind.
<form id="form1" action="DocumentViewer.aspx" method="post" autocomplete="off">
<span>
<table>
<tr>
<td></td>
</tr>
</table>
</span>
Without runat="server" you cannot access the control in code behind. Best way to do it is to inject the jquery script from code behind to do the same work.
Please take a look at this answer.
In my asp.net web control form i am using two text box 1st is simple input html control and 2nd is asp.net input web control.
<form id="form1" runat="server">
Email: <input type="text" id="txt_email" name="txt_email" value="" /><br />
Email2: <asp:TextBox ID="txt_email2" runat="server"></asp:TextBox><br />
<asp:Button ID="btn_login" Name="btn_login" runat="server" Text="Button"
onclick="btn_login_Click" />
</form>
I need to know what is the difference using simple control and asp.net input control both of them pass the value to code behind after the form submit. can any one help me on this?
As defined in your example input type="text" won't even be visible to code-behind because it is missing runat="server" attribute.
If you do add it - there're still differences. ASP.NET TextBox is more advanced and in par with the rest of ASP.NET model (e.g. it has property .Text vs. .Value of an HtmlInput control, it has events and other properties).
But if you simple need to pass text information back to the server, either of them will do the job.
The biggest differences are that
the asp.net controls are rendered on the server, and thus they have more overhead on your server than using traditional controls - traditional controls (by default) are rendered once then basically reside on the client's browser, asp controls are persistent on the server side.
the asp controls can be accessed and worked with directly in the code behind files.
asp controls have some additional tags that can be used on their fields usually.
as was pointed out by #Yuriy-Galanter, how the value is accessed is slightly different.
The asp:Textbox renders HTML to the client/browser when the page request is made. Picture the ASP.NET control, in this case an asp:TextBox as a server side bit of code that knows to render a <input type="text"> HTML element when the request for the aspx page is made to the server.
The ASP.NET compiler, when parsing your aspx page just spits out the <input type="text"> HTML element you have for Email: and for Email2: the ASP.NET compiler knows that is a server control because of the runat="server" tag. So the ASP.NET compiler, having a reference to the ASP.NET assemblies on the server, reads the code for the <asp:TextBox> and knows to ultimately respond to the page request with an <input type="text" id="txt_email2" />
The server side controls are accessible in your code behind page. So is accessible in the code behind but the <input> element is not. Good for you to consider in your research at this point, that if you add runat="server" to your element, it is accessible in your code behind.
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
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.
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.