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
Related
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.
}
}
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>
enter code hereI am trying to upload a file using FileUpload Control. As there are so many complexities within my form, I cannot use Html.BeginForm (of course this works perfectly fine). All I want to do is with Input id call the function to send the postedfile to the controller. I searched in the web, but my need is this. I DO NOT WANT TO SUBMIT THE WHOLE FORM. All I want to do is upload file and comeback to my form to complete the rest of the fields. Any type of code snippet would be appreciated. Thanks
Here is the sample of code what I have
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
ViewReportFiles
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm([ActionName], [ControllerName], FormMethod.Post, new { target = "_blank" }))
{%>
Here I have few fields to process.
Along with this I have fileUpload control
<table>
<tr>
<td valign="bottom">
<input type="file" id="document" name="document" accept="text/xml, text/csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" size="76" />
</td>
<td valign="bottom">
<div Id="UploadFile"> <input type="image" alt="upload file" src="<%= ResolveUrl("~/media/form_upload_btn.png") %>" name="image" /> </div>
</td>
</tr>
</table>
<% }>
My javascript is as follows
<script type="text/javascript" language="javascript">
$("#UploadFile").click(function () {
if ($("#document").val() == '') {
// checking for selected file
alert('Please select a document.');
return false;
}
$.ajaxFileUpload({
**url: '<%= Url.Action("actionName", "Controller") %>',**
data: { val: 'aaa' },
secureuri: false,
fileElementId: 'document',
dataType: 'xml',
success: function (data) {
}
});
});
</script>
Here the problem is it's not getting into that URL. it goes to my HTTPPost of the page.
My controller code is like this....
public void UploadAccessDataFile(){
foreach (string uploadFile in Request.Files)
{
}
}
Please help.
I am trying to upload a file using FileUpload Control
Don't try this to do this. Read the following blog post which explains how to upload files in an ASP.NET MVC application.
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
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" />
<%= #"});" %>