Dynamic file upload controls not working in asp.net webforms page - asp.net

I have a web page where I dynamically generate lots of elements from code behind and inject them into the page, as such:
input type="file" style="width:480px;" id="fileUploadLogo345">
I also have buttons for submitting, like this:
input id="Submit1" type="submit" value="Substituir Logo" onclick="return jsSubmitLogo(345);">
(The javascript function always returns true...)
No matter what I try, I am unable to get any of the uploaded files from code behind.
I tried adding enctype="multipart/form-data" to the form, I tried adding runat="server" to the file upload controls, I have no idea what else I could try. No matter what I do, in code behind Request.Files.Count equals zero.
Any idea what I could be doing wrong?
If it makes any difference, I am using a master page...
Thanks

You are using "id" attributes in your html... you should instead use "name" attributes, and everything will show up fine in code behind.

Related

liferay-ui:search-container-column-button wont react to click

i am using liferay-ui:search-container-column-button inside liferay container the button should point to another jsp with take parameter from the current selected row.
<liferay-ui:search-container emptyResultsMessage="There are no organizations available">
<liferay-ui:search-container-results
results="<%=OrganizationLocalServiceUtil.getOrganizationAll() %>"
total="<%=OrganizationLocalServiceUtil.getOrganizationsCount() %>">
</liferay-ui:search-container-results>
<liferay-ui:search-container-row
className ="fff.sem.service.model.Organization"
keyProperty="organizationId"
modelVar="organization"
escapedModel="<%=true %>"
>
<liferay-ui:search-container-column-text
name="Organization short name"
value="<%= organization.getOrganizationShortName() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-text
name="Organization full name"
value="<%= organization.getOrganizationFullName() %>">
</liferay-ui:search-container-column-text>
<liferay-ui:search-container-column-button href="<%=addOrganization1URL %>"></liferay-ui:search-container-column-button>
<liferay-ui:search-container-column-jsp
align="right"
path="/html/sem/organization_actions.jsp"
/>
</liferay-ui:search-container-row>
As you noticed in the code I used search-container-column-jsp to add edit and delete feature for the row. I use a column with search-container-column-button so that each button of that column point to another form, but the search-container-column-button wont react on clicking. What is going on?
Recent Liferay forum posts indicate a potential issue with the taglib:
search-container-column-button does not work
Issue in calling an action from liferay search-container-column-button tag
grep of the Liferay source code nor a github search return a single instance where the taglib is used.
My attempts to use the <liferay-ui:search-container-column-button to properly call any type (action, render, resource) URL were not successful. In examining the source closer, I believe the generic dump of the href attribute value into the onclick attribute is the problem.
In comparing the html generated by a <aui:button> to that of the search-container-column-button the onclick attribute is missing location.href=
I would recommend using a liferay-ui:search-container-column-jsp as you have done for the other actions, but instead of an icon-menu use a <aui:button> if you want the field to be a button.
Including the missing info:
<%
final String hrefFix = "location.href='" + addOrganization1URL .toString()+"'";
%>
<liferay-ui:search-container-column-button href="<%=hrefFix%>"/>
does provide a working solution, however, if this is indeed a bug and is fixed in a future patch, this workaround would then become a bug.

Double-clicking on a form control in Visual Studio 2010 design view inserts a script instead of inserting an event handler

The title pretty much precisely asks the question, but I shall repeat;
When I double click on a form control while in the design view in a Web Application project within Visual Studio 2010, say a 'button' or a 'submit' for example, it inserts a javascript function into my .aspx file. When I do this at work it automatically creates an event handler for the control in the code-behind.
How do I change this to that setting? I have used '/resetsettings' already, and other answers to similar questions do not solve my problem. I have reinstalled, gone through every menu I can find (though I may have missed something) and I'm pulling my hair out.
I don't want to type those event handler subroutines every time! Halp meee!
Thanks in advance for any helpful replies.
What it looks like is going on with this is that you are double clicking on a regular HTML element. For example, if you have
<input type="button" value="Test" id="Test" name="Test" />
and double click on it in design view it will create a JavaScript function on the page for it and an onclick event in the element. If you want to create an event handler in the code behind, you need to have an Asp.Net control like
<asp:Button runat="server" ID="Test" Text="Test" />
and then double click that to create a code event in the code behind.
Also, make sure that your page directive at the top has the correct filename for its CodeFile attribute to correctly map to an existing code behind file.

ASP.NET Master Page and User Content Forms

Is there a good way to enable forms that come out of user content (CMS) that is displayed inside the form runat="server" tag? All sorts of services provide forms for users to paste into their website, which break if the content ends up inside a .net form. It seems to me that there must be a good way around this, but I can't seem to find any solutions.
The one solution I've found is to put them in an IFRAME. So instead of embedding your form inside the page:
<FORM action="http://www.example.com/target.html">
.. form content
</FORM>
create a new ASPX file like this:
<FORM action="http://www.example.com/target.html" target="_top">
.. form content
</FORM>
Then in your original page, you'll refer to it via an IFRAME:
<IFRAME src='myform.aspx'></IFRAME>
Some things you'll need to do:
Make sure that you do not include any <FORM runat="server"> inside the new ASPX file.
Adjust the size of the IFRAME and the ASPX file to be exactly the same
For the FORM in the new ASPX files, you probably want to set target='_top' to ensure when a user fills in the form, the result is in the main window rather than inside the IFRAME.

Is nested <form> possible?

in a content page of an asp.net web page, i would like to include the "paypal" button "Pay Now".
So, i've a master page, and a content page.
In my content page i copy-paste paypal code.
In particular i use a "modalpopupextender" to permit my user to buy the object.
The problem is... it not work.
So my hypotheses are:
I'm not sure, but i think i can't use a nested <form action>
If not the first, maybe i can't use a <form action> into a modal popup ?
someone can suggest me an "elegant" solutions to solve this ?
Thank you ...
EDIT: in particular, what i'm trying to do is to permit to sell from a website.
I've a master page, and a content page.
Obviously in master page i've the classical "form action" .
Then i'm gone to paypal and got this code: "
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<table>
<tr><td>
<input type="hidden" name="on0" value="Annuncio Premium">Annuncio Premium
</td></tr>
<tr><td>
<select name="os0">
<option value="Premium 1">Premium 1 €1,00</option>
</select>
</td></tr>
</table>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="encrypted" value="-----BEGIN ">
<input type="image" src="https://www.paypal.com/it_IT/IT/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
So i've pasted it into my content page ... as it... without changing.
In particular i've pasted it, into a panel, that will show whith a "modalpopupextender".
It works. But what it not work is when i click the paypal "Buy Now" button.
My web page don't redirect to paypal, modalpopup disappears and nothing happens.
I had this exact issue too and couldn't believe that PayPal had not provided some sort of solution for .NET developers!!
Here is how I solved it:
<asp:ImageButton ID="btnPayNow" runat="server" ImageUrl="myPayPalButton.jpg"
PostBackUrl="https://www.paypal.com/cgi-bin/webscr" OnClick="btnPayNow_Click"/>
Use an ImageButton or normal button and simply remove the form tags for the PayPal code, leave in the hidden input fields and the data will be posted to the PayPal url!
Nice and easy :)
Ps. The method 'btnPayNow_Click()' does nothing, signature exists but there is no logic in the code I have.
You are quite correct, in that you cannot nest <form>s.
Nor can you use the form action to create a popup - the action attribute is the url to which the form posts to.
You can, however, have many <form>s on the page, so long as they are not nested. Perhaps that will solve you issue.
Can you please describe exactly what you are trying to achieve? It is not clear from your question what the problem is.
If I understand the question correctly, you are trying to create a dynamic HTML popup window which contains a PayPal form. You are having problems because the popup contains a form, but the HTML for the popup is already contained within a form.
If the problem you are experiencing is what I described above, the solution is fairly simple. You need to move all of the HTML for the popup outside of the exiting form element. If you are using CSS to properly lay out your site, it should be possible to display your dynamic popup wherever you need to on the page using relative or absolute positioning. The HTML for the popup need not be contained within another form. It may also be possible (perhaps even necessary) to put the contents of the popup into an iframe, which can be submitted entirely independently from the rest of the page. The semantics of how your popup works would depend on how you need your page to function.
So, to be clear...it is not possible to nest form elements. However, it is also not necessary to accomplish your needs.
EDIT:
To improve the answer above in light of the updated question. You can have multiple content panels on a master page. It should be entirely possible to create another content panel that is outside of your form element in your master page...and place your modal popup inside of this alternative content panel. My above answer would then still apply, as you no longer have nested forms.
You are right in your first hypothese, you can't have nested form tags in a page.
You just have to put the code for the popup outside the form, you can have any number of forms in the page as long as they are not nested.
Dal's answer is correct! (not taking credit with my answer)
I had a similar issue in ASP.NET (4.0) when trying to submit data to SagePay (same as PayPal form posting). I was writing the form fields in dynamically using panels in the code-behind using
Dim Panel As New Panel
Panel.Controls.Add(New LiteralControl("My <input> controls HTML")) '1 control.add per <input> control.
MyDiv.Controls.Add(Panel)
I was writing the whole < form> dynamically also, so when it came to debugging I received no warnings regarding the issue that my entire Site.Master is within a - this is not visible from a .aspx page using the master as a template! It was quite frustrating... Until I read that you cannot have a nested < form>... There are only two alternatives to this:
1) move the form details outside the first that is within my Site.Master from the .aspx page itself. (I didn't like the idea of this, messy messy!)
2) create another control that is NOT a to post my data.
I chose the latter!
<asp:Button id="btn_payment" value="Proceed to Payment" Text="Proceed to Payment" runat="server" PostBackUrl="https://test.sagepay.com/gateway/service/vspform-register.vsp" />
The button posted to SagePay, took my dynamically generated fields (Called from the .aspx page) and as they were already within the from my Site.Master - all worked well! - I hope this helps anyone using dynamically generated HTML with forms.

Handling elements generated by Javascript in Asp.Net

I have several elements in my web page generated by JavaScript.
Here's an example of such content:
<input id="uploadfile01" type="file" onchange="change(1);" />
<input id="uploadfile02" type="file" onchange="change(2);" />
My question is:
How can I interact with these elements in the server side, (Asp.net) after a post?
(Since the elements were dynamically generated they do not exist in the original asp.net page)
I dont think that would be possible.....if i am not mistaken you want to give the option to attach multiple files. i think it would be better to place a set number of fileupload controls and set there display to none and you can use javascript to show them.
i know that this is not what you are looking for but after a postback the controls will be lost and even if they are added again they will lose there contents.(had you been generating them through code behind)

Resources