ReportViewer 10, ASPX, Paging Issues - asp.net

I have a small web project, the sole purpose of this project is to house and produce reports for a larger application.
I have a page "ReportManager.aspx" that simply has a ReportViewer (10.0) control on it.
<div style="width:auto;">
<form id="Form1" runat="server" style="width:100%; height: 100%;">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:reportviewer id="ReportViewer1" runat="server" Width="100%" Height="100%" AsyncRendering="false" SizeToReportContent="true"></rsweb:reportviewer>
</form>
</div>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if (IsPostBack)
return;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer");
ReportViewer1.ServerReport.ReportPath = "/SSRSReport";
ReportParameter param = new ReportParameter("effective_date", "4/22/2013");
ReportViewer1.ServerReport.SetParameters(param);
ReportViewer1.PageCountMode = PageCountMode.Actual;
}
</script>
Changing pages on the reportviewer control at runtime is producing an error.
The error is in:
Reserved.ReportViewerWebControl.axd?OpType=Resource&Version=10.0.30319.1&Name=ViewerScript
at Line 3559, and looks like this:
// Remove the current STYLE element, if it already exists.
if (oldStyleElement != null)
headElement.removeChild(oldStyleElement);
headElement.removeChild(oldStyleElement); is the line where the error is showing htmlfile: Invalid argument. Break | Continue | Ignore.
Clicking "Continue" causes the report to render without any styling. Clicking "ignore" allows the report to render correctly.
I am running Windows 2012 Server, Visual Studio 2012 Premium and IE8. The same error occurs on Win 7 machines.
Any suggestions or known fixes?

My report is in an MVC app also. I actually fix this problem awhile ago. I think I fixed it by removing the following lines:
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://localhost/ReportServer");
ReportViewer1.ServerReport.ReportPath = "/SSRSReport";
ReportViewer1.PageCountMode = PageCountMode.Actual;
I changed the code to store all that data in the tag.
Another thing I did was add
ReportViewer1.ServerReport.Refresh() below ReportViewer1.ServerReport.SetParameters(param).
After I made those changes, everything started working.

Though suspicious it would help, I tried removing as much code-behind as possible like you suggested, but this did not fix it for me.
However, this was the solution in our app:
The .aspx page hosting the ReportViewer control was missing its <body> tag.
THAT'S ALL!!
Anti-climactic, I know, but apparently this causes IE8 (at least) to barf on
headElement.removeChild(oldStyleElement);
I'm curious if doing the same in your app brings the error back.
There are only a handful of resources I found via Google dealing with this problem, I can't believe this wasn't mentioned in any of them :-x

Related

The name "Label1" does not exist in the current context

I've got a weird issue in Visual Studio where I can't reference controls from the code-behind page.
To give a really simple example, my page is like this:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="New.aspx.cs" Inherits="ITDashboard.idea.New" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
And my codebehind is this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ITDashboard.idea
{
public partial class New : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "hello";
}
}
}
The application is called ITDashboard, and this page is in a folder called "idea".
Have looked around, and some posts suggest deleting the designer file and recreating it. However, there's no option in VS2012 that I could see. Also I get the same error with a new blank page, even at the site root.
I don't have enough points yet to add a comment, so please forgive this comment in the answer box!
I've seen this before. "This" = VS not adding controls to the designer file. From what I was able to find, it's just a corruption in the page. Or if it's happening on all pages, it's a corruption of the project. You didn't do anything to cause it, so there is nothing you can do in the future to avoid it. Luckily, in 13+ years of working with various versions of VS, I've only seen it two or three times.
Andrew nailed it. If the problem is isolated to this page, then create a new page and replicate your corrupt page one control at a time. If it's at the project level (and it sounds like it is), you'll have a little more work to do.
Here's a good tip on how to recover from a corrupt project:
How can I recover a corrupt .csproj file in Visual Studio 2010?
Good luck!
Thought I'd post in case somebody has the same thing.
All the web posts I saw were pointing to "Convert to web application" (now under Project in VS2013). However this wasn't working for me.
Finally got it working by changing the .net Framework type (arbitrarily to 4.5). I then re-ran the Convert to web application option and it recreated the designer.cs files.
Also, any new controls I add are automatically added to the designer.cs properly now.
if you are having redouble setting the text of Label1 ...change Label1.text to Label1.Text.
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'label1' does not exist in the current context ConsoleApplication6

ASP.NET Button click event not working in IE11

I have a code which i have put in and that does not seem to work in IE11. Can anyone please help me out ?
I am working in VS2005 and click event is not firing in localhost.I have tried the following fixes; hotfix from microsoft(microsoft update standalone package) and installed .Net framework 4.5 Even then button event is not firing.
Below is the code which I have put in - The aspx and the aspx.cs lines are mentioned below :
aspx
<asp:Button ID="btnExcelExport" runat="server" Text="Excel" OnClick="btnExcelExport_Click" />
aspx.cs:
protected void btnExcelExport_Click(object sender, System.EventArgs e)
{
Label1.Text = "You clicked a button.";
}
Depending on the version of your .NET framework, this is actually a bug. There's a patch available from Microsoft.
http://blogs.telerik.com/aspnet-ajax/posts/13-12-19/how-to-get-your-asp.net-application-working-in-ie11
Is your tag wrapped in a:
<form id="form1" runat="server" enableviewstate="false">
<!-- postbacks and other .NET client-based functionality require a
wrapping form tag -->
</form>

ASPX EventValidation error with DropDownList

This must have an obvious solution, but I'm stumped. We are developing an application which is mostly XHR-based, so while we are using .aspx, very little is done with typical controls. However, in a few spots, we are just doing basic "throw this data into a spreadsheet for the user" things with a couple dropdowns for timespan for reports, etc.
The problem is when we use asp:DropDownList controls, it immediately causes any page we put them in to throw Event Validation errors on submit. I have created test pages that do not share the rest of the application's master pages (aka, no JS at all modifying things client side) just to be sure that we don't have some stray JS causing issues.
If I remove the DropDownList in the following example, the button click happens just fine. If I click the button with the page sitting as shown, it throws the Event Validation error.
However, other applications running on the same machine, in 4.0 Integrated app pools, do not exhibit this behavior, so I'm assuming it has something to do with the configuration. The web.config is pretty standard...tried turning httpCompression section off in a desperate attempt, but to no avail.
Does anyone have a suggestion on where to start here? Please remember... There is NO CLIENT SIDE MODIFICATION going on. This is straight from the server to the browser, then 'click' on the ASP-generated button.
Turning off Event Validation in the page directive does eliminate the error, but I'd rather not turn off validation if I can help it.
Environment:
Windows 7 Pro
IIS 7.5
.NET 4.0 Integrated app-pool
Error happens in IE9/Chrome/Firefox/Safari
Page:
<html>
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlDays" runat="server">
<asp:ListItem Text="30 Days" Value="30"></asp:ListItem>
<asp:ListItem Text="60 Days" Value="60"></asp:ListItem>
<asp:ListItem Text="90 Days" Value="90"></asp:ListItem>
</asp:DropDownList>
<asp:Button ID="butExport" Text="Export" runat="server" />
</div>
</form>
</body>
</html>
Codebehind:
protected void Page_Load(object sender, EventArgs e) {
butExport.Click += new EventHandler(butExport_Click);
}
void butExport_Click(object sender, EventArgs e) {
Syslog("clicked");
}
Form Data (according to Chrome Inspector):
__VIEWSTATE:/wEPDwULLTIwOTUzNjUzOTVkZIiv1cdholWibyWL8h5HASwxedB47NUpctCv8OQc1CWM
__EVENTVALIDATION:/wEWAgL0voCyDQKDgcL6CAX34hdaRiHyNiY1xLIh5Pr6aj5q8h8gGG875vMq1SXF
ddlDays:30
butExport:Export
OK, I started going through my project looking for any possible configuration item that could be causing issues. Turns out a co-worker used a WebControlAdapter and applied it to all DropDownLists and during the Render, did not use RegisterForEventValidation.
I don't particularly like the adapter, but in the interest of moving on with life, I left it there and while rendering bound items, I'm calling Page.ClientScript.RegisterForEventValidation for each value. This has fixed every problematic DropDownList we have in the application.
Thanks for the suggestions, all.

ResolveClientUrl works differently in ASP.Net 4 and 3.5

[Apologies if my question title does not accurately describe my problem- if you can think of a better title and have the permissions to change this then please feel free to change it!].
I think that I have stumbled upon a minor breaking change between ASP.Net 3.5 and 4.0.
[Edit: I have confirmed that there is a change in behaviour twix 3.5 and 4.0 - see my answer]
Here is the scenario: -
I have a ASP.Net 3.5 web application.
I have a trivial user control {appRoot}/Controls/Widgets/MyPictureAndTextWidget.ascx that essentially contains some text and another user control ({appRoot}/Controls/Widgets/MyPicture.ascx).
For the most part, this control is used in the normal fashion - i.e. including it in the mark up of other pages but I have one instance where I need to obtain the HTML to render on the client using Ajax.
The way I achieved this was to write an asmx web service that programmatically created a new Page and dynamically `LoadControl' the user controls and then captured the output from the rendering of the page in a string builder - particulary inelegant but it worked! See bottom for the source.
However, after upgrading the project to Asp.Net 4.0, the above code no longer works as it used to; the image, when rendered has src="../images/xxx.png (note the '../' which is not wanted).
I have created a little demo app http://cid-916198839f3e806c.office.live.com/self.aspx/Public/TestingImageWTF.zip if you want to run it for yourselves. When you compile the app using 3.5, it works (i.e. you see 2 pictures of a spider on the test page) but when you compile and run under 4.0, you only see 1 spider (the other image has the wrong URL).
The only explanation that I can come up with is that the ResolveClientUrl method (which the Image control will use in order to work out what is the relative path to the image from the currently executing page) is behaving differently. The fact that the image url is coming out as "../images/xxx.png" means that the Image control 'thinks' it is executing in a page that has a path like '{appRoot}/folder/handler' when running under 4.0 but it thinks it is running in a context '{appRoot}/handler' under 3.5.
I hope this is making sense to you - sorry if I am not describing the problem very clearly or concisely.
Can anyone either tell us how: -
to restore the 3.5 behaviour (without reverting to the 3.5 framework obviously!)
or a better way of generating the HTML in the web service in the first place?
The source
A full test application can be downloaded from here http://cid-916198839f3e806c.office.live.com/self.aspx/Public/TestingImageWTF.zip
Web Service
[WebMethod]
[ScriptMethod]
public string GetWidgetHtml(int number)
{
var pageHolder = new Page
{
//AppRelativeVirtualPath = "~/" // I tried playing with this but it made no difference!
};
for (int i = 0; i < number; i++)
{
var viewControl = (MyPictureAndTextWidget) pageHolder.LoadControl(#"~/Controls/Widgets/MyPictureAndTextWidget.ascx");
pageHolder.Controls.Add(viewControl);
}
var output = new StringWriter();
HttpContext.Current.Server.Execute(pageHolder, output, false);
StringBuilder sb = output.GetStringBuilder();
string fulloutput = sb.ToString();
return fulloutput;
}
Here are the contents of my user controls
Controls/Widgets/MyPictureAndTextWidget.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MyPictureAndTextWidget.ascx.cs" Inherits="TestingImageWTF.Controls.Widgets.MyPictureAndTextWidget" %>
<%# Register TagName="Picture" TagPrefix="widget" Src="~/Controls/Widgets/MyPictureWidget.ascx" %>
<div style="background:#EEEEEE; border:1px dashed;">
<h4>My control</h4>
Some text from the widget ....:
<br /><widget:Picture runat="server" />
</div>
Controls/Widgets/MyPictureWidget.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="MyPictureWidget.ascx.cs" Inherits="TestingImageWTF.Controls.Widgets.MyWidget" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
image.ImageUrl = "~/images/spider.png";
}
</script>
<asp:Image ID="image" runat="server" />
oSo here is at least part if the answer.
Question: Does ResolveClientUrl working differently in ASP.Net 4 and 3.5?
Answer: Yes.
And the change in behaviour (that I know of) is that it treats PathInfo differently.
To demonstrate, make the following page.
<%# Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
DateTime.Now.Ticks: <%= DateTime.Now.Ticks %>
<br />
<asp:HyperLink runat="server" NavigateUrl="~/PathInfoLinkTest.aspx">This links to ~/PathInfoLinkTest.aspx</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/PathInfoLinkTest.aspx/foo/bar">This links to ~/PathInfoLinkTest.aspx/foo/bar</asp:HyperLink>
<br />
ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") = <%= ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") %>
</form>
</body>
</html>
And run under .Net4 and .Net 3.5.
You will see that under 3.5:
ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") = 'PathInfoLinkTest.aspx/foo/bar'
whereas under 4.0 you get
ResolveClientUrl("~/PathInfoLinkTest.aspx/foo/bar") = 'bar'
The change seems to be a bug fix in response to the problems that these folk were having.
http://channel9.msdn.com/Forums/TechOff/256519-Am-I-crazy-here-but-there-appears-to-be-an-oversight-in-ASPNET
http://forums.asp.net/t/1138135.aspx/1
In essence, the bug in 3.5 is that if you are currently browsing the url http://host/app/page.aspx/foo/bar and you want to link to http://host/app/page2.aspx, then the URL as rendered on the client should be ../../page2.aspx.
Asp.Net 4 gets this correct!Asp.Net 3.5 doesn't - it outputs the link's url as 'page2.aspx' (so when clicked, the browser will request the page 'http://host/app/page.aspx/foo/bar/page2.aspx'. You can see a manifestation of this bug if you run the above page in .Net 3.5 and click on the 2nd hyperlink several times - then have a look in your browser's address bar!
Unfortunately the bug fix broke my code - because my code was relying on the (incorrect) behaviour of .Net 3.5: The web service request always has Pathinfo (the web service method name) and so when the controls render themselves, calls to ResolveClientUrl("~/xxx") (correctly) puts returns "../xxx".
I'm not sure about updates to the ResolveClientUrl method, but I do know that they made updates to how controls are rendered between .NET 4.0 and 3.5. You may want to try updating your web.config to include:
<pages controlRenderingCompatibilityVersion="3.5" />
Check out: http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770141
Also, you might try using RenderControl as follows in your web service:
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
control.RenderControl(hw);
return sb.ToString();
Rick Strahl has an article that might be useful: http://www.west-wind.com/weblog/posts/2004/Jun/08/Capturing-Output-from-ASPNet-Pages (may be somewhat dated however...)
Hope this helps!
Try to remove the leading tilde symbol from the ImageUrl value.

Asp.Net, DropDownList, AutoPostBack and Google Chrome

I've a simple asp.net page (framework 3.5) and an UpdatePanel with a series of dropdownlist I want to populate asyncronously. All works fine in all major browsers (Opera, Safari, IE6, IE7, FF3), but not in Chrome.
Chrome seems to ignore the SelectedIndexChanged event who had to make the asynch request.
Anyone knows a simple workaround to this?
Thanks!
EDIT: More Informations
As I say to Adam Lassek, the updatepanel refresh after the click to an asp:Button inside of it, but it doesn't work with the dropdown's SelectedIndexChanged event.
The updatepanel is set like:
<asp:UpdatePanel ID="updPanel" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
without Triggers specified, and the dropdows have sets AutoPostBack="true"
UPDATE: (and retagging)
After a few attempts I discover that it isn't a problem of the UpdatePanel, but it seems that the AutoPostback of dropdowns doesn't work properly, even in pages without ScriptManager and UpdatePanel...
I'm sure that it is a problem concerning only this project, because if I start a new WebSite from scratch and replicate the structure of this, works fine in Chrome...
I'm trying to remove step by step all the other things in the original project to find exactly what's the problem.
If anyone has some ideas in meantime....
There is a known incompatibility with Ajax.NET and Chrome & Safari 3.
Small, quick tests can be deceptive because it will appear to work fine with the existing Ajax.NET library as is. This is because it manages to perform the first Ajax request and fails when that ends, so only when you try to perform the second Ajax action will you notice it has failed. If you put an UpdateProgress control on your page, you'll notice that after the first request your UpdateProgress control won't disapppear.
Luckily, there is an answer!
Recently there was a great post put up detailing what to do which you can find here:
http://blog.turlov.com/2009/01/aspnet-ajax-compatibility-patch-for.html
The general gist of it is that both Chrome and Safari 3 report themselves as WebKit in their userAgent strings.
You need to add a little bit of javascript in to aid the Ajax.NET framework in recognising WebKit based browsers that looks like the following:
if (typeof(Sys.Browser.WebKit) == "undefined") {
Sys.Browser.WebKit = {};
}
if (navigator.userAgent.indexOf("WebKit/") > -1 ) {
Sys.Browser.agent = Sys.Browser.WebKit;
Sys.Browser.version =
parseFloat(navigator.userAgent.match(/WebKit\/(\d+(\.\d+)?)/)[1]);
Sys.Browser.name = "WebKit";
}
You need to add that to a javascript file and reference it in your ScriptManager:
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/assets/javascript/WebKit.js" />
</Scripts>
</asp:ScriptManager>
Note that you can keep the WebKit.js in an assembly and reference that by using a ScriptReference tag similar to this:
<asp:ScriptReference Assembly="Scripts" Name="Scripts.webkit.js" />
Once you've done all that, if at all possible stop using WebForms and Ajax.NET and use MVC and jQuery :)
This happens because MicrosoftAjax.js does browser detection, and it's incorrectly detecting Chrome as Safari. In order to fix this, you need to make the following changes:
Add a new browser type
Sys.Browser = {};
Sys.Browser.InternetExplorer = {};
Sys.Browser.Firefox = {};
Sys.Browser.Safari = {};
Sys.Browser.Opera = {};
Sys.Browser.Chrome = {};
Update the if-then logic to search for Chrome
else if (navigator.userAgent.indexOf(' Firefox/') > -1) {
Sys.Browser.agent = Sys.Browser.Firefox;
Sys.Browser.version = parseFloat(navigator.userAgent.match(/ Firefox\/(\d+\.\d+)/)[1]);
Sys.Browser.name = 'Firefox';
Sys.Browser.hasDebuggerStatement = true;
}
else if (navigator.userAgent.indexOf(' Chrome/') > -1) {
Sys.Browser.agent = Sys.Browser.Chrome;
Sys.Browser.version = parseFloat(navigator.userAgent.match(/ Chrome\/(\d+\.\d+)/)[1]);
Sys.Browser.name = 'Chrome';
Sys.Browser.hasDebuggerStatement = true;
}
else if (navigator.userAgent.indexOf(' AppleWebKit/') > -1) {
Sys.Browser.agent = Sys.Browser.Safari;
Sys.Browser.version = parseFloat(navigator.userAgent.match(/ AppleWebKit\/(\d+(\.\d+)?)/)[1]);
Sys.Browser.name = 'Safari';
Be sure to put the Chrome check before Safari. If you need help replacing the Framework script with your custom version, read this.
UPDATE:
I created a test page and put the following controls on it:
<asp:ScriptManager ID="scriptManager1" runat="server" />
<asp:UpdatePanel ID="panel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true">
<asp:ListItem Value="0" Text="Item 1" />
<asp:ListItem Value="1" Text="Item 2" />
</asp:DropDownList>
<asp:Literal ID="litTest" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
And wrote the following codebehind:
protected override void OnInit(EventArgs e)
{
ddlTest.SelectedIndexChanged += new EventHandler(ddlTest_SelectedIndexChanged);
base.OnInit(e);
}
void ddlTest_SelectedIndexChanged(object sender, EventArgs e)
{
litTest.Text = "Selected: " + ddlTest.SelectedItem.Text;
}
The Updatepanel works fine in Chrome, with no modification of the Ajax library. So, I think something else is causing this problem. You're going to need to isolate the cause of the problem through a process of elimination. Start with something simple like this example, and work up to what you have a piece at a time.
It is not an appropriate suggestion to use MVC and jQuery instead of WebForms and ASP.NET AJAX. One should understand all the pros and cons of the technologies and approaches to choose from.
First, MVC is a design pattern and has nothing to do with the particular frameworks mentioned. You can easily implement an MVC pattern with WebFroms. There are many different implementations of MVC for ASP.NET and WebForms.
Second, jQuery, being a great JavaScript library, does not allow any integration with and does not leverage server side ASP.NET functionality, as opposed to ASP.NET AJAX framework that comes standard with the ASP.NET 3.5+ and fully utilizes ASP.NET features, such as server side mark-up, ScriptManager control, server-side script combining, localization and globalization, etc.
Third, jQuery can be easily used in conjunction with ASP.NET and ASP.NET AJAX frameworks thus enhancing client-side programming. Microsoft has announced that jQuery will be shipped with the next ASP.NET 4.0 and for now you can just add it to your project manually.
I just ran into a similar problem today (although I wasn't using Ajax), and found a fix. See the third comment down on this blog post.
I have the same problem. I've got a dropdown inside a ajax postback and need to do an update when the selected index changes. It works with a basic page in a new project too.
After adding the Webkit script mentioned in the other answers I still get the same problem and when running the javascript debugger in Chrome I get this error:
uncaught exception ReferenceError: evt is not defined
UPDATE: SOLUTION
I found that in my case it was a CustomValidator that was interfering with the event handler. Setting EnableClientScript to false fixed the issue.
You can check out solution
http://dotnetguts.blogspot.com/2009/05/dropdownlist-autopostback-problem-with.html

Resources