Showing posts with label causing. Show all posts
Showing posts with label causing. Show all posts

Monday, March 26, 2012

Challenging PageRequestManagerParserException error

Hello,

I received the following error today (using ASP.NET AJAX), and I'm unable to suss it out. Any ideas on what might be causing the below?:

Sys.WebForms.PageRequestManagerParserException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to response.write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'Master 544|updatePan'.

I believe I am using the latest version of System.Web.Extensions, Version=1.0.61025.0

Thanks in advance,
-Alex

Hi, I figured it out. There was a Response.Write() call in the aspx page (inline in the HTML). Apparently, this is not allowed when using UpdatePanels. Any more info available on this subject?

-Alex


Thanks for the info ... I didn't figure it was my update panel who cause my trouble ...

I use another way to do it. Thanks !

causing validation from client side without postback?

Now that I added callout extenders to my validators how can I get them to work 1- on the client before calling an AJAX webservice and 2- in the webservice? I am not using an update panel so can I turn off server side validation and write my own for the webservice to call?

Hi Echo,

Echo88:

Now that I added callout extenders to my validators how can I get them to work 1- on the client before calling an AJAX webservice and 2- in the webservice? I am not using an update panel so can I turn off server side validation and write my own for the webservice to call?

My understanding of your issue is that you want to validate the inputs. If all these are correct then call the WebService ,otherwise, show the error message by using ValidatorCalloutExtender. If I have misunderstood, please feel free to let me know.

Validators are call before the form is submitted , but to call the WebService we don't need to postback. So I suggest that you should write your own validate Javascript code instead of ValidatorCalloutExtender controls.

Here is the sample to call a WebService.

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="DataTableService.asmx" InlineScript="true" />
</Services>
</asp:ScriptManager
<input type="button" value="Get DataTable" onclick="getDataTable();" /
<div id="result"></div
<script language="javascript" type="text/javascript">
function getDataTable()
{
DataTableService.GetDataTable(onSucceeded, onFailed);
}

function onSucceeded(result)
{
//handle code
}

function onFailed(error)
{
//handle code
}

You can also transfer all the inputs and validate on the server side in the WebService.

I hope this help.

Best regards,

Jonathan


Thanks - sucks that I can not use those jazzy callouts. But a question I have is - doesn't it call a client script prior to postback?? My understanding is that validation takes place before posting the form data to the server, so one would think there is a call to a script that precedes the actual postback. Am I wrong?


Hi Echo88,

But a question I have is - doesn't it call a client script prior to postback??

Yes , you are right. The problem is that if all the inputs are correct , the form will postback next. But to call a webservice , we usually do not need to postback. It will cause the page refreshment. Based on this , I think write your own Javascript function is a better way in this situation. If you don't want to validate on the client side , you can also transfer all the inputs to the server side and validate on the WebService.

function setBoy()
{
var boy = new Object();
boy.Name = "Terry";
var girl = new Object();
girl.Name = "Mary";
boy.GirlFriend = girl;

BoyGirlService.SetBoyWithGirlFriend(boy, onSetBoySucceeded, onFailed); // call the WebService.
}

I hope this help.

Best regards,

Jonathan


exactly - I am calling a webservice instead of a postback. But am I right to say there should be a way to cause validation on the client - regardless of postback? I just thought there would be a method to execute independently. What aboutPage_ClientValidate() ??


Hi Echo88,

Yes , I agree with you. You can use it like this.

Button1.Attributes["OnClick"] = "Javascript:if (typeof(Page_ClientValidate) == 'function') if(Page_ClientValidate()) {return confirm('Are you sure to submit ?'); } else return false;";

Best regards,

Jonathan


I tried that - no dice. The button is set to cause validation and uses submit behavior. However, nothing is happening? I guess it is not finding Page_ClientValidate function. When include Page_ClientValidate by itself - it throws an error. So why is not included?


Hi Echo88,

Sorry for the delay. Here is my test sample and it works pretty well.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { Button1.Attributes["OnClick"] = "Javascript:if (typeof(Page_ClientValidate) == 'function') if(Page_ClientValidate()) {return confirm('Are you sure to submit ?'); } else return false;"; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"><%=DateTime.Now.ToString()%> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator" ControlToValidate="TextBox1"></asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Button" UseSubmitBehavior="true" CausesValidation="true" /> </form></body></html>
So please compare it with yours and if it doesn't work, please feel free to let me know with more information. Thanks.

Best regards,

Jonathan


Your example works - even though it does perform a postback - I turned off the submitbehavior. Still works:) so there is hope- I suspect the

Page_ClientValidate function is not getting generated somehow. Could the fact that I am using them all as part of a user control be the problem?
Thanks - its really appreciated. 

Ok - I found out something interesting... The Page_Validators array is not populating on this one page. Any ideas why they are not populating Page_Validators ?


OK - I found the root of the cause. In my control I have readonly mode that would make all validators invisible if it was in readonly mode. Apparently, I did set the function incorrectly and all validators were not being rendered.

Causing postback

I have written some javascript that async calls a webservice every second. If the service returns true, I want to cause a postback, with client script that can be handled on the server and tell a particular update panel to update in the server side handler.

I also wish to construct event arguments on the client to be passed as part of the post back.

How do I do this?

I need to do something similar, and I'm wondering if you could do it by having your page implement the IPostBackEventHandler. This interface requires that you implement a RaisePostBackEvent method. This method takes a string argument, and you could update your updatepanels in this method. Does anyone know if this approach would work?

Thanks,

Nick


hello.

ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

1. use the postbackaction

2. add a hidden dummy button to the updatepanel and force the submit by calling its click method


Nope, dont need to do that. ipostbackeventhandler is the way to go.

I add some javascript to the page via:

Microsoft.Web.UI.ScriptManager.RegisterClientScriptBlock(
this,
this.GetType(),
"UIService_Agent",
string.Format(
"function CheckAgentTimer()" +
"{{" +
"UIService.ShouldInteruptAgent(OnAgentTimerSucceeded,OnAgentTimerFailure);" +
"}}" +
"function OnAgentTimerSucceeded(result)" +
"{{" +
"if(eval(result))" +
"{{" +
"{0};" +
"}}" +
"setTimeout(\"CheckAgentTimer()\",{1});" +
"}}" +
"function OnAgentTimerFailure()" +
"{{" +
"setTimeout(\"CheckAgentTimer()\",60000);" +
"}}" +
"setTimeout(\"CheckAgentTimer()\",10000);",
this.Page.ClientScript.GetPostBackEventReference(this,AgentTasksTimer.AGENT_PROCESS),
this.timerInterval
),
true);

and then I implement the interface ipostbackeventhandler


public void RaisePostBackEvent(string eventArgument)
{
if (eventArgument == AGENT_PROCESS)
{
//Is There Work for the Agent?
if (WorkItemActionRequired != null && IsWorkItemActionRequired())
{
WorkItemActionRequired(this, new WorkItemEventArgs(ResourceReceiverService.GetUserWork(((IUserPrincipal)Context.User).Credentials.UserId, true)));
}
}
}

Messy I know, but bare with me...

You can then request that update panels are updated on the server i.e. myUpdatePanel.Update

This works!


Luis Abreu:

hello.

ipostbackeventhandler is not the answer if you need to update updatepanels. what you could do is:

1. use the postbackaction

2. add a hidden dummy button to the updatepanel and force the submit by calling its click method

How do you call the click method on a hidden dummy button?


hello.

you must get ?a refernce for the html control and call its click method:

$get("your_button_client_side_id").click();

But will this cause a partial or full post back?

Thanks,

Nick


hello.

it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.

That might do the trick then. Right now I have implemented IPostBackHandler, but it causes a full post-back. I just want to do a partial. How do I make the button invisible, set Visible to false, or set visible to hidden in the button style?

Thanks,

Nick


hello.

it depend: if it's an asp.net button and it's placed inside an updatepanel (or if it's outside the updatepanel but it's configured as a trigger) you'll get a partial postback.
hello again.
well, i'd just add syle="display:none" in the asp.net button declaration.

This will also allow me to put code server-side?

Thanks,

Nick

Causing Async Postback after closing ModalPopup

Hey,

Im trying to make use of the ModalPopupExtender in order to allow the user to input some information and then have an UpdatePanel async postback to update with this new information. The key here would therefore be to Update the Panel right after closing the ModalPopup. This is where Im having some troubles. No matter what I cant get the UpdatePanel to postback after clicking Ok from the ModalPopup. As of right now, once you click Ok from the Modal, you have to hit refresh in order to see the results of the info... which kinda defeats the purpose of AJAX.

Thanks in advance for help!

Hi,

You can first add an invisible button on the form, and set it as the triggerfor the UpdatePanel.

Then, add a OnOkScript to the modalPopupExtender. In the script, call click on the invisible button. Like this: $get("id of the invisible button").click

So, whenever the modalPopup is closed via clicking on ok button, the UpdatePanel is able to update.

Hope this helps, and please feel free to let me know if there is any problem.

Saturday, March 24, 2012

CascadingDropDown with a DB causing stack overflow

I've struggled for days through examples and self discovery to get to where I am, and now I get a stack overflow error from my cascadingdropdown object which is attempting to retrieve data from a tableadapter. When the page loads I get a msgbox pop-up error which says: "Stack overflow at line: 116". I've tried commenting out most every line in the webservice function and that seems to have no discernible effect. Perhaps it's something in the aspx page? Any help greatly appreciated.

Here's my aspx:

-------------------------------------------

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %
<%@dotnet.itags.org. Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="ajaxToolKit" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />
<br />
<div>
<asp:DropDownList ID="ddl_GetService" runat="server">
</asp:DropDownList> <br />

<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList><br />
<br />
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList><br />
<br />
<br />

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server" TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices" ParentControlID="ddl_GetService" >
</ajaxToolKit:cascadingdropdown>
<br />
</div>
<br />
<br />
<br />

</form>
</body>
</html>


-------------------------------------------

Here's my asmx file:

-------------------------------------------

<%@dotnet.itags.org. WebService Language="VB" Class="wsGetServices" %
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports AjaxControlToolkit
Imports Facilities_WizardTableAdapters
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class wsGetServices
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Function GetAllServices(ByVal sServRsn As String, ByVal sCode As String) As AjaxControlToolkit.CascadingDropDownNameValue()
Dim ServiceTableAdapter As TBL_WZ_SERVICETableAdapter = Nothing
ServiceTableAdapter = New TBL_WZ_SERVICETableAdapter()
Dim Services As Facilities_Wizard.TBL_WZ_SERVICEDataTable = ServiceTableAdapter.GetServices()
Dim values As List(Of CascadingDropDownNameValue) = New List(Of CascadingDropDownNameValue)
Dim dr As Facilities_Wizard.TBL_WZ_SERVICERow

For Each dr In Services
sServRsn = dr.SERV_RSN.ToString()
sCode = dr.CODE.ToString()
values.Add(New CascadingDropDownNameValue(sServRsn, sCode))
Next dr

Return values.ToArray()

End Function

End Class

I discovered that it's a stack overflow because it's working! And the number of rows returned is rather large. So does anyone know how I can accomodate for that? I mean a drop down with say around 300 entries?

Thanks!


It's not clear to me why returning lots of entries should cause a stack overflow. Maybe run this page under the VS debugger and have a look at what's on the stack at the time - that should help narrow the problem down.

I am having a similar issue today. I know my webservice is working and it only returns 27 records. here is my ASMX file if anyone has any advice:

<%

@.WebServiceLanguage="VB"Class="LHMCSearchDD" %>

Imports

System.Web

Imports

System.Web.Services

Imports

System.Web.Services.Protocols

Imports

System.Collections.Generic

Imports

System.Data

Imports

System.Data.SqlClient

Imports

System.Configuration

Imports

AjaxControlToolkit

<WebService(Namespace:=

"http://tempuri.org/")> _

<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

<System.Web.Script.Services.ScriptService()> _

Public

Class LHMCSearchDDInherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetProducts(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AjaxControlToolkit.CascadingDropDownNameValue()Dim cadapterAsNew dsSearchTableAdapters._PRODUCTTableAdapter' Dim cadapter As New dsSearch.DSTablesTableAdapters.countryTableAdapterDim ctableAsNew dsSearch._PRODUCTDataTable' Dim ctable As New ltcodebehind.DSTables.countryDataTable

cadapter.FillBrands(ctable)

Dim valuesAsNew List(Of AjaxControlToolkit.CascadingDropDownNameValue)For iAsInteger = 0To ctable.Count - 1

values.Add(

New CascadingDropDownNameValue(ctable(i).B_NAME, ctable(i).B_NAME))NextReturn values.ToArrayEndFunction

End

Class
I'm having the similar problem. Any new ideas on how to solve it?

There is nothing to do with the number of rows returning from the service. The problem is with your cascadingDropdown declaration.The value for TargetControlID and ParentControlID are given as same, which is causing a recursive call and there by stack overflow.

<ajaxToolKit:cascadingdropdown id="CascadingDropDown1" runat="server"TargetControlID="ddl_GetService" Category="Service" PromptText="Select a Service Code" ServicePath="wsGetServices.asmx" ServiceMethod="GetAllServices"ParentControlID="ddl_GetService" >

-Sajid T.K