ASP FileUpload control issue in Chrome browser - asp.net

I have a legacy webpage with an asp:FileUpload control on it with an OnClick event. When uploading an .xsls spreadsheet with parentheses () in the file name, e.g., "somefile (2).xsls," using Chrome browser, the UploadButton_Click handler is not called. Instead, the web page redirects to the default page as if an error occurred.
However, a filename without parentheses works fine. (No issue with IE.)
I need help debugging this. Breakpoints in the click handler are not hitting in this scenario. Response.Write, etc., are not good either because the event does not get hit.
The code is pretty much this:
<asp:FileUpload id="FileUpload1" runat="server">
</asp:FileUpload>
<asp:Button id="UploadButton"
Text="Upload file"
OnClick="UploadButton_Click"
runat="server">
</asp:Button>

Related

404 error on link button click to valid website address

When a user clicks on this particular link button in question, I receive a 404 error in the browser. When I click the refresh button on the browser, the target website loads as normal. Any thoughts on what this might be? It's just a plain old .net link button:
<asp:LinkButton ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none" CausesValidation="false"
PostBackUrl="http://www.targetsite.com/">WHAT ARE?</asp:LinkButton>
PostBackUrl causes page to perform POST request, not all target pages like it. If you simple mean to provide a navigation link you can use something like this instead:
<asp:HyperLink ID="lnkWhatAre" runat="server" ForeColor="#FF9999"
Style="text-decoration: none"
NavigateUrl="http://www.targetsite.com/">WHAT ARE?</asp:HyperLink>
"asp:HyperLink" is a server-side control, so you can still set all its properties in server-side code if needed. And it renders as a normal hyperlink - so it won't cause any problems redirecting.

ASP.NET Button Click causes a Postback *and* a "GET" - why?

I have code that seems to defy explanation. There are a couple of pages that do some data maintenance in our web application (VB.net codebehind). One works as expected, the other has a problem.
They both have an Ajax Tab Container to group the appropriate parts of the data. When I hit the 'Save' button, I want the page to remember what the active tab was. In the first page, there's no problem. I get the postback, go through the Page_Load and everything works as expected.
For some reason, on the second page, when I click the Save button, which is defined exactly the same as on the first page, I get the "POST" that I expect (Request.RequestType = "POST") but then Page_Load gets fired AGAIN with Page.IsPostback being "False" (Request.RequestType = "GET") - like I just clicked into the page.
The button markup is simple the only difference is that one is in a table and the second is in it's own <div>
:
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="btnSave" runat="server" Text="Save" Width="2in" />
</asp:TableCell>
<center>
<asp:Button ID="btnSave" runat="server" Text="Save" Width="4in" Height="0.33in" />
</center>
The markup at the top of the pages is identical - just the required properties with AutoEventWireup and EnableEventValidation as "False" and MaintainScrollPositionOnPostback as "True".
I can't understand why these two pages are giving me such difference results. With the .aspx markup being so similar, it's easy to spot any differences. How can I figure out where this phantom "GET" is coming from?

Using Response.Redirect with jQuery Thickbox

I'm using jQuery Thickbox to display an iframe (upload.aspx) that allows a user to upload a file. In the code behind for the upload.aspx I finish by sending:
Response.Redirect("blah.aspx");
The page I redirect to is dynamic based on the results of the upload process. When this redirect happens, it happens inside the Thickbox and not the parent window as I'd like it to. Here's the calling ASP.NET page (home.aspx):
Add New
And here's the submit button inside of the upload.aspx page:
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick="btnUpload_Click" OnClientClick="self.parent.tb_remove();" />
This is designed to close the modal window and send control to the code behind to perform the file upload, processing, etc.
Has anyone experienced this before? How would I go about sending a redirect on the parent window?
You cannot send a redirect to a parent frame.
Instead, you need to use Javascript.
You can write top.location = "whatever"; in Javascript in the <iframe>.
Here's what I ended up doing.
Added server tags to the body element of upload.aspx:
<body id="mBody" runat="server">
Removed the Response.Redirect, and attached some JavaScript to run on the next load.
HtmlGenericControl body = (HtmlGenericControl)Page.FindControl("mBody");
body.Attributes.Add("onload", "window.top.location.href='blah.aspx';");
And removed the client click from the button:
<asp:Button ID="btnUpload" runat="server" Text="Upload"
OnClick="btnUpload_Click" />

Firefox and Updatepanel

I have a problem with FireFox and ASP.NET UpdatePanel.
I have in a form a checkbox and an UpdatePanel. When I check the checkbox, an asp:panel which is into the UpdatePanel should become visible.
<asp:CheckBox ID="cbMoreOptions" runat="server" Text="plus d'options" AutoPostBack="True" OnCheckedChanged="cbOptions_CheckedChanged" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server" Visible="false">
sssssssss
</asp:Panel>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cbMoreOptions" EventName="CheckedChanged" />
</Triggers>
</asp:UpdatePanel>
Everything is working fine but not after I refresh the page while the checkbox is checked. If this is happening, the checkbox rest checked the page doesn’t make postback more to the server. The firebug shows that the page gets a response and when I verify the its content I have en error 500 which tell that the information of the page is corrupt. All this is happening only in Firefox. In IE8 and Google Chrome everything is ok.
Does anybody have an idea how can I avoid this? It’s a bug of Firefox?
All the weird comportment continues until I make enter into the URL textbox. Even if I make F5 nothing happens. What is the difference between F5 and enter into the URL? They shouldn’t have the same result?
Thanks a lot.
Have you tried placing the checkbox "cbMoreOptions" inside the UpdatePanel?
Place in inside the UpdatePanel ContentTemplate section and set an AsyncPostBackTrigger for the CheckBox.
We had this problem a long time ago and it was the way firefox uses in-memory cache to store the state of a page which messes up the way ASP.NET handles VIEWSTATE hidden field. Check if caching turned on for your aspx pages and disable it.
Edit: Here's a link that explains it in detail.
What is the difference between F5 and enter into the URL? They
shouldn’t have the same result?
If you hit enter in the address bar, it does a GET request, i.e. you enter your page's lifecycle with !IsPostBack.
When you hit F5, I observed that firefox will repeat the last request, so if that last request was a POST, it will repeat it. That's why your page stay in a buggy state. If the first post back caused an error (the checkbox' checkedChanged), hitting F5 will just repeat that error.
So, no, the don't have the same result.
I don't have any documentation to backup this statement, but this is what I observed. If anyone can point a source I'll be glad to see it.

how to navigate pages in asp.net

I have to navigate to another page in asp.net suppose I have two pages i.e. Default.aspx and Default2.aspx how do I navigate between them ?
You could use anchors in your aspx page:
Click to navigate to Default2.aspx
or make a redirect in your code behind:
Response.Redirect("~/Default2.aspx");
there are many ways, here are a few to get you started
go there
<asp:HyperLink runat="server" ID="lnk" Text="go there" NavigateURL="default2.aspx" />
<asp:LinkButton runat="server" ID="btn" Text="go there" OnClick="server_method_that_redirects" />
On your server side codebehind you may also consider using Server.Transfer(..) instead of Response.Redirect(..).
Response.Redirect sends an instruction to the browser to change the page while Server.Transfer does it directly on the server side. Browse the web for further information about the differences.

Resources