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>
Related
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
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.
I went through this thread but couldn't understand much. I am very new to ASP/HTML/Server-side programming.
I tried running this code on a .aspx file:
<form id="form1" action="Default.aspx">
<div>
<asp:Label ID="lblName"></asp:Label>
</div>
</form>
And I got an error when I tried to use this in the CodeFile:
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = "123";
}
"lblName does not exist".
But if I use runat="server" attribute with the label, then this code works.
Also, is there any concept of nesting the runat attribute. e.g, If I specify runat=server for the form above, will all my controls inside the form automatically be configured to run at server? How does this attribute work?
In which case would I be required to specify runat=server for the and for the tag? How does the server-side know that the label is inside the form if I don't have a form object at server side? Or am I missing something?
Any element marked with runat="server" lets the framework know that this will be a control on the server side. This article has more details:
Exploring the Runat Attribute
Nope, there is no such nesting available in ASP.NET, you have to specify "runat" to every control that you want to use in code behind and that is part of ASP.NET web library.
Because ASP.NET can only recognize difference between client side tag (the html that runs on browser) and server side tag with help of "runat"
I am having an ASP.NET page with one Asp.net button control and a normal html link (anchor tage) I want to invoke the postbackl event of asp.net button control when someone clicks on the link.
I used the below code
<a href="javascript:myFunction();" class="checkout" ></a>
<asp:Button ID="btnCheckout" runat="server" Visible="false"
onclick="btnCheckout_Click" />
and in my javascript i have
function myFunction()
{
var strname;
strname = "Test";
__doPostBack('btnCheckout','OnClick');
}
But when runnin gthis , i am getting an error like __doPostBack is undefined
Can any one tell me why it is ?
Thanks in advance
This anyway wouldn't have worked. When you make your .NET control invisible by using 'Visible="false"' it isn't rendered, that means not available at the client.
Back to your question.
1- Where is myFunction defined? Between the tag?
2- Are there more .NET controls on the page? If there aren't any other .NET controls, .NET doesn't add all the scripts that are required for postbacks and stuff.
Why not do the following (based on TheVillageIdiot answer):
<asp:LinkButton ID="lbtnCheckout" runat="server" CausesValidation="false" OnClick="lbtnCheckout_Click" CssClass="checkout" />
With the above example you don't need the fake button and make it invisble. You still can do your postback. Way more cleaner approach I would say.
First of all I tried your code and also not get anything like __doPostBack, then I added another button on the page which was visible but it was all the same. Then I added a LinkButton and got __doPostBack method. You can do post back from javascript but then EventValidation is problem, as it does not allow this kind of thing. I had to use the following to overcome it and it worked:
protected override void Render(HtmlTextWriter writer)
{
ClientScript.RegisterForEventValidation(
new PostBackOptions(btnCheckout, "OnClick"));
base.Render(writer);
}
I think I'm bit incoherent in answering so I'll mark it as wiki :)
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