ASP.NET AsyncFileUpload - Internet-Explorer Access is denied - asp.net

I have an asp.net AsynFileUpload control on the page and an html image tag that fires the AsyncFileUpload click event. Works fine in Firefox, Chrome and Safari but not IE.
Example
<script type="text/javascript">
function GetFile() {
document.getElementById("<%=AsyncFileUpload1.ClientID %>").click();
}
</script>
<ajaxToolkit:AsyncFileUpload runat="server" ID="AsyncFileUpload1" />
<img id="flImage1" src="images/upload.png" onclick="GetFile()" />
The uploader works fine in IE if I just use the uploader control. But I need an image on the page that will fire the uploader control click event.
When I click the image that fires the JavaScript GetFile() function, it then calls the click event for the AsynFileUpload control. I can then select my file for upload. Once I select the file I get a JavaScript alert "Access is denied".
Anyone know what the issue is and how to get around it?
Thanks in advance.

I use something like this:
document.getElementById('<%= this.AsyncUpload.ClientID %>' + '_ctl02').click();

Related

asp:linkbutton (navigating to specific page section on post back)

I have some linkbuttons to update my gridview which is in the middle of the page. Everytime I hit edit or delete etc the window scrolls to the top on the page that gets posted back. I want it to stay focused on the grideview. I have tried a javascript function but for some reason it did not work.
(edit: the following works as far as scrolling is concerned but prevents postback)
here is what I tried
<script type="text/javascript" language="javascript">
function goto() {
window.scrollTo(10, 1100);
}
</script>
<asp:LinkButton ID="lbtnGo" runat="server" OnClientClick="javascript:goto();return false;">GO</asp:LinkButton>
source
How can I do this?
Did you try with <%# Page MaintainScrollPositionOnPostback="true" %> in the page declaration?
Regards
Client-side event fires before server-side. So even if you scroll window to correct position - after postback you will be returned to the top. You can add the following code to your server-side LinkButton click event handler:
if (!this.IsStartupScriptRegistered("ScrollToGrid"))
{
String scriptString = "<script language=\"JavaScript\">";
scriptString += "window.scrollTo(10, 1100);";
scriptString += "</script>";
this.RegisterStartupScript("ScrollToGrid", scriptString);
}
this will add javascript block to your page after postback
There are, depending on the .NET framework properties available that can help one out:
ASP.NET 1.x: use SmartNavigation. ASP.NET 2.0: use MaintainScrollPositionOnPostBack. Use an UpdatePanel control to asynchronously update parts of a page
and the best way for this is UpdatePanel control to asynchronously update parts of a page

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" />

link button property to open in new tab?

In my application I have some link buttons there but when I right click on them I cannot (they are in disable mode) find the menu items Open in new tab or Open in new window.
How do I show those menu items?
Code example:
<asp:LinkButton id="lbnkVidTtile1" runat="Server" CssClass="bodytext" Text='<%#Eval("newvideotitle") %>' />
From the docs:
Use the LinkButton control to create a hyperlink-style button on the Web page. The LinkButton control has the same appearance as a HyperLink control, but has the same functionality as a Button control. If you want to link to another Web page when the control is clicked, consider using the HyperLink control.
As this isn't actually performing a link in the standard sense, there's no Target property on the control (the HyperLink control does have a Target) - it's attempting to perform a PostBack to the server from a text link.
Depending on what you are trying to do you could either:
Use a HyperLink control, and set the Target property
Provide a method to the OnClientClick property that opens a new window to the correct place.
In your code that handles the PostBack add some JavaScript to fire on PageLoad that will open a new window correct place.
Here is your Tag.
<asp:LinkButton ID="LinkButton1" runat="server">Open Test Page</asp:LinkButton>
Here is your code on the code behind.
LinkButton1.Attributes.Add("href","../Test.aspx")
LinkButton1.Attributes.Add("target","_blank")
Hope this will be helpful for someone.
Edit
To do the same with a link button inside a template field, use the following code.
Use GridView_RowDataBound event to find Link button.
Dim LB as LinkButton = e.Row.FindControl("LinkButton1")
LB.Attributes.Add("href","../Test.aspx")
LB.Attributes.Add("target","_blank")
try by Adding following onClientClick event.
OnClientClick="aspnetForm.target ='_blank';"
so on click it will call Javascript function an will open respective link in News tab.
<asp:LinkButton id="lbnkVidTtile1" OnClientClick="aspnetForm.target ='_blank';" runat="Server" CssClass="bodytext" Text='<%# Eval("newvideotitle") %>' />
This is not perfect, but it works.
<asp:LinkButton id="lbnkVidTtile1" runat="Server"
CssClass="bodytext" Text='<%# Eval("newvideotitle") %>'
OnClientClick="return PostToNewWindow();" />
<script type="text/javascript">
function PostToNewWindow()
{
originalTarget = document.forms[0].target;
document.forms[0].target='_blank';
window.setTimeout("document.forms[0].target=originalTarget;",300);
return true;
}
</script>
LinkButton executes HTTP POST operation, you cant change post target here.
Not all the browsers support posting form to a new target window.
In order to have it post, you have to change target of your "FORM".
You can use some javascript workaround to change your POST target, by changing form's target attribute, but browser will give a warning to user (IE Does), that this page is trying to post data on a new window, do you want to continue etc.
Try to find out ID of your form element in generated aspx, and you can change target like...
getElementByID('theForm').target = '_blank' or 'myNewWindow'
When the LinkButton Enabled property is false it just renders a standard hyperlink. When you right click any disabled hyperlink you don't get the option to open in anything.
try
lbnkVidTtile1.Enabled = true;
I'm sorry if I misunderstood. Could I just make sure that you understand the purpose of a LinkButton? It is to give the appearance of a HyperLink but the behaviour of a Button. This means that it will have an anchor tag, but there is JavaScript wired up that performs a PostBack to the page. If you want to link to another page then it is recommended here
that you use a standard HyperLink control.
It throws error.
Microsoft JScript runtime error: 'aspnetForm' is undefined
<asp:LinkButton ID="LinkButton1" runat="server" target="_blank">LinkButton</asp:LinkButton>
Use target="_blank" because It creates anchor markup. the following HTML is generated for above code
<a id="ctl00_ContentPlaceHolder1_LinkButton1" target="_blank" href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$LinkButton1','')">LinkButton</a>

Redirect parent window from iFrame

I have an asp.net page inside an iFrame. I want to redirect the parent page (that sits outside the iFrame) when an asp.net button on the asp.net page in the iFrame is clicked.
The asp.net button will need to do some processing before re-directing, so I guess I need to call javascript from the asp.net
just create simple ans: in javascript
<script type="text/javascript">
function NewWindow() {
document.forms[0].target = "_top";
}
</script>
call it any control like button
<asp:LinkButton ID="linkbutton1" Text="Enroll Now" OnClientClick="NewWindow();" runat="server" onclick="enrol_Click"/>

How to hide the refresh button on the report viewer control (ASP.NET)

I have a strange scenario wherein I am having to delete the data from the table once a report is generated. The data gets uploaded to the table when the user clicks on a "Generate Report" button on the web page.
My problem is that once the report is generated and shown on the report viewer control I don't want the user to click on the "Refresh" button on the ReportViewer pane. Is there a way I can hide it?
Forget it, very stupid of me. Its under "Toolbar" properties on the ReportViewer control. ShowRefreshButton.
Thanks :)
<rsweb:ReportViewer ID="viewerName" runat="server" ShowRefreshButton="false" AsyncRendering="false" SizeToReportContent="True" >
</rsweb:ReportViewer>
Do you have control over the web page? If so, add a bit of javascript that hides the button.
Using jQuery:
<html>
<head>
<script>
$(document).ready(function() {
$('#btnid').hide(); }
)
</script>
</head>
<body>
...
</body>
</html>

Resources