Adding ScriptManager makes Request never complete - asp.net

I have a very strange problem. Initially, my page is working fine, if I click a "Back" button, it will navigate to the previous page. But when I add this line
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
Everything seems to stop working. Clicking the button causes the request to never complete (i.e. I cannot go back to previous page when I click "Back" button).
My page structure looks like this
<%# Page Title="" Language="C#" MasterPageFile="~/Master/Main.Master" AutoEventWireup="true" CodeBehind="dsp_FileName.aspx.cs" Inherits="[Namespace].dsp_FileName" %>
<%# MasterType VirtualPath="~/Master/Main.Master" %>
<asp:Content ID="C1" ContentPlaceHolderID="PageContent" runat="server">
<script type="text/javascript">
...
</script>
<asp:ScriptManager ID="ScriptManager" runat="server"></asp:ScriptManager>
<div>
...
</div>
</asp:Content>
Am I missing something?

This problem occurs because in my master page, I have the following snippet:
<form id="frmMain" runat="server" onsubmit="progressStart('Please wait...');">
Basically I wanted to block any other input when user clicks a button. So I need to modify the above snippet to be :
<form id="frmMain" runat="server" onsubmit="progressStart('Please wait...'); return true;">
And in the page where I need to use the Script Manager, I need to add the following code.
function pageLoad() {
if (args.get_isPartialLoad()) {
jQuery.ajax({
type: "GET",
url: "../../JS/Javascript.js",
dataType: "script",
cache: true
});
$('#dErr').dialog('destroy'); // this is the dialog that will show inside the progressStart function.
}
}

Related

Two instances of the same usercontrol in an asp.net page

In my webpage I use two user controls:
ucControl1 and ucControl2. The ucControl1 control also contains an instance of the ucControl2 control inside it.
When you run the application and go to the page in question, it appears that only the instance that is inside the ucControl1 is working correctly. When trying to execute the functionality of the ucControl2 that is directly on the page, it correctly executes the backend code, opens the modal correctly but does not show the results on the screen.
What could be happening?
The page is like this
<%# Page Language="C#" AutoEventWireup="true" CodeFile="PageSample.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="PageSample" %>
<%# MasterType VirtualPath="~/MasterPage.master" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<%# Register Src="~/Controls/ucControl1.ascx" TagPrefix="uc1" TagName="ucControl1" %>
<asp:Content runat="server" ContentPlaceHolder ID="cpSampleID">
<div>
<uc1:ucControl2 runat="server" ID="uc2" />
</div>
<uc1:ucControl1 runat="server" ID="uc1" />
</asp:Content>
And the usercontrol1
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl1.ascx.cs" Inherits="ucControl1" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc1" TagName="ucControl2" %>
<%-- Something Something Something --%>
<uc1:ucControl2 runat="server" ID="ucControl2" />
I've found a solution. The modal is opened by javascript.
ucControl2
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ucControl2.ascx.cs" Inherits="ucControl2" %>
<%# Register Src="~/Controls/ucControl2.ascx" TagPrefix="uc2" TagName="ucControl2" %>
<div id="modal">
<!-- Some Textboxes -->
</div>
Method to open the modal
public void OpenModal()
{
string id = "modal";
string js = $#"
$(document).ready(function() {{
if ($('.modal.in').length > 0) {{
$('.modal').on('hidden', function() {{
$('.modal').off('hidden');
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}});
$('.modal').modal('hide');
}} else {{
$('#{id}').modal({{show: true, keyboard: false, backdrop: 'static'}});
}}
}});";
ScriptManager.RegisterStartupScript(this, this.GetType(), id, js, true);
}
So when the control is called, the javascript does not know which of the controls should open, and in this case it is opening the first control that is on the page.
To solve it I've changed the div through an asp panel, in this way asp generates a different client ID for each control and the controls are displayed correctly.

ASP.NET Server does not process pages asynchronously

I have a page with button, and i want to load 2 data grids with data asynchronously by cliking the button.
This is the code of the page, I use jquery to make calls to other 2 pages that will yield me html.
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Test" %>
<asp:Content ID="Content2" ContentPlaceHolderID="cphCenter" Runat="Server">
<style type="text/css">
#wait {
position:absolute;
top:0px;
right:10px;
width:200px;
z-index:1000;
vertical-align:middle;
text-align:center;
background: #febf00;
display:none;
}
</style>
<script src='<%= ResolveUrl("../../../../Scripts/jquery-1.4.1.js") %>' type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#wait')
.ajaxStart(function () { $(this).show(); })
.ajaxStop(function () { $(this).hide(); });
$('input:button').live('click', loadData);
});
function loadData() {
$.get("Source.aspx", {},
function (data) {
$('#a1').html(data);
},
"html");
alert('This alert is asynchronous (1st)');
$.get("Source2.aspx", {},
function (data) {
$('#a2').html(data);
},
"html");
alert('This alert is asynchronous (2nd)');
}
</script>
<div id="test13">
<input type="button" id="btnLoad" value="Load" />
</div>
<div id="a1"></div>
<div id="a2"></div>
<div id="wait">Please wait <img src="ajax-loading.gif" /></div>
</asp:Content>
Then I have 2 aspx pages, Source1.aspx and Source2.aspx. They only containe a gridDataView and little code in OnLoad event.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Solutions_CashCenter_StockManagement_Test_Source" %>
<form runat="server">
<cc1:GridDataView runat="server" ID="gridTest" >
</cc1:GridDataView>
<asp:SqlDataSource ID="dsTest" runat="server" ConnectionString="<%$ ConnectionStrings:WebPortalConnectionString %>"
ProviderName="<%$ ConnectionStrings:WebPortalConnectionString.ProviderName %>">
</asp:SqlDataSource>
</form>
Server-side:
Thread.Sleep(5000);
dsTest.SelectCommand = "SELECT 'test1', 'test2', 'test3'";
this.gridTest.DataSourceID = "dsTest";
this.gridTest.DataBind();
And the same for the second page, but with different data for the grid.
What I have in result is that both alerts happen at once, but the grids are loaded one after one, that is 1st grid appears after 5 seconds, and then second one appers after another 5 sec.
That is the server does not actually process them concurrently.
What am I doing wrong and how should I organize all to work as I need?
This is happens because the session locks the page reads.
So when the one page is loading, the session lock all the rest request until is finish and send the page.
To make it work you need ether to disabled the session on this pages, ether use handler that is not have by default session lock.
Relative questions :
Trying to make Web Method Asynchronous
Web app blocked while processing another web app on sharing same session
What perfmon counters are useful for identifying ASP.NET bottlenecks?
Replacing ASP.Net's session entirely

The state information is invalid for this page and might be corrupted (IE only)

I've see all of the other pages with this questions, but no amount of research has solved my problem. I am getting the "The state information is invalid for this page and might be corrupted" error. My page loads fine the first time. The page contains a div that has tabs that change the info on the page and the tabs are loaded dynamically and are linked to a different page. The tabing uses jquery. Without changing anything on the page, when I try to reload this page by click on the link that gets to this page or even by clicking on ANY link in the menu bar that goes to other pages, I this error. Again, this only happens in IE and I've put break points all over my code and it never goes back to the server.
<%# Page Language="C#" MasterPageFile="~/Templates/Main.Master" AutoEventWireup="true"
CodeBehind="Reporting.aspx.cs" Inherits="Pegged.Reporting" Title="Workforce Planning Report" %>
<%# Register Src="Controls/ucWebPageNavigation.ascx" TagName="ucWebPageNavigation"
TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$(function () {
$("#tabs").tabs({
ajaxOptions: {
error: function (xhr, status, index, anchor) {
$(anchor.hash).html(
"Couldn't load this tab. We'll try to fix this as soon as possible.");
}
}
});
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="IconLinks" class="TopLinks">
<uc1:ucWebPageNavigation ID="ucWebPageNavigation1" runat="server" />
</div>
<div id="divContainerReport" class="container_12">
<!--Facility Tabs-->
<div id="tabs">
<ul id="FacilityTabs" runat="server" ></ul></div>
</div>
</asp:Content>
This is the code that loads the tabs on page load:
ServicesDLL.Services ps = new ServicesDLL.Services();
string encryptString = "";
string encryptString2 = "";
encryptString = ps.EncryptQueryString("Test");
encryptString2 = ps.EncryptQueryString("Testing");
string innerhtml = "<li><a id=\"id1\" href=\"ReportFacility.aspx?facility=" + encryptString + "\">Test</a></li><li><a id=\"id2\" href=\"ReportFacility.aspx?facility=" + encryptString2 + "\">Testing</a></li>";
FacilityTabs.InnerHtml = innerhtml;
And this is the page the tabs load:
<%# Page Title="" Language="C#" MasterPageFile="~/Templates/Popup.Master" AutoEventWireup="true" CodeBehind="ReportFacility.aspx.cs" Inherits="Pegged.ReportFacility" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="divReportView" class="grid_8 BlueBorder">
<p id="testText" runat="server"></p>
</div>
</asp:Content>

jQuery Validation in ASP.NET

i have a strange situation may its a easy fix or something i may be missing but here is the question.
i have a asp.net form with master page and my validation works great without any problem but the problems starts when i try to hook my click event to the server side,
here is what i meant:
i have a form with few fields on it and if the form is empty than it should STOP submitting, otherwise allow me to execute the server side script
but its not happening, even my form is in invalid state (i do get error message saying i have to enter the required fileds) but still executing my server side script.
i would like to execute my server side script only if the form is in valid state.
here is my code:
my master page
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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">
<head runat="server">
<title>jQuery Validation in ASP.NET Master Page</title>
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script src="Scripts/jquery.validate.js" type="text/javascript"></script>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
my content page:
<%# Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript">
$(document).ready(function() {
$("#aspnetForm").validate({
rules: {
<%=txtName.UniqueID %>: {
minlength: 2,
required: true
},
<%=txtEmail.UniqueID %>: {
required: true,
email:true
}
}, messages: {
<%=txtName.UniqueID %>:{
required: "* Required Field *",
minlength: "* Please enter atleast 2 characters *"
}
}
});
});
</script>
Name: <asp:TextBox ID="txtName" MaxLength="30" runat="server" /><br />
Email: <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSubmit" runat="server" onclick="SubmitTheForm();" Text="Submit" />
</asp:Content>
function SubmitTheForm() {
SaveTheForm();
}
function SaveTheForm() {
debugger;
var request = buildNewContactRequest();
ContactServiceProxy.invoke({ serviceMethod: "PostNewContact",
data: { request: request },
callback: function(response) {
processCompletedContactStore(response);
},
error: function(xhr, errorMsg, thrown) {
postErrorAndUnBlockUI(xhr, errorMsg, thrown);
}
});
return false;
}
i have tried both ways
1)
$(document).ready(function() {
$("#btnSubmit").click(function(event) {
event.preventDefault();
SaveTheForm();
});
});
2)
<asp:Button ID="btnSubmit" runat="server" onclick="SubmitTheForm();
function SubmitTheForm() {
SaveTheForm();
}
you're posting your data without checking if the form is valid or not
I think you have to use something like this
function SubmitTheForm() {
if ($("#aspnetForm").valid()) SaveTheForm();
}
Sorry, I'm giving you bad advice. Forget my previous entry. What is the SubmitTheForm() method? You're using the jQuery validation plug in, so you should just need to attach the validation stuff to the form and all should be right with the world.
I think your button onclick needs to be
return SaveTheForm();
As in:
<asp:Button ID="btnSubmit" runat="server" onclick="return SubmitTheForm();" Text="Submit" />
Do you try to put the jQuery code script in the Head ContentPlaceHolder

jQuery document.ready + Asp.Net ContentPlaceholder cause Visual Studio intellisence problems

I want to execute JavaScript when document is ready without much syntax overhead. The idea is to use Site.Master and ContentPlaceholder:
<script type="text/javascript">
$(document).ready(function () {
<asp:ContentPlaceHolder ID="OnReadyScript" runat="server" />
});
</script>
and in inherited pages just write plain code:
<asp:Content ID="Content3" ContentPlaceHolderID="OnReadyScript" runat="server">
$("#Login").focus();
</asp:Content>
It works fine but Visual Studio complains and gives warnings.
Warning in master page is Expected expression at the line <asp:ContentPlaceHolder.
In inherited pages warning is Could not find 'OnReadyScript' in the current master page or pages.
I tried using Writer.Write in master page to render script tag and wrapping code:
<% Writer.Write(#"<script type=""text/javascript"">$(document).ready(function () {"); %>
<asp:ContentPlaceHolder ID="OnReadyScrit" runat="server" />
<% Writer.Write(#"});"); %>
but page rendering terminates after opening script tag is rendered. Html basically ends with
<script type="text/javascript">
How can I make it work?
This is a bug in Visual Studio's syntax highlighting.
Try
<%= #"<script type=""text/javascript"">$(document).ready(function () {" %>
<asp:ContentPlaceHolder ID="OnReadyScript" runat="server" />
<%= #"});" %>

Resources