Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Monday, March 26, 2012

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

Saturday, March 24, 2012

CascadingDropdownList [Method Error 500]

Still trying to get these dropdowns to work. I have created a page with a single ddl that should be populated from the web service and has no parents but I still get the [method error 500] as the values, what am I mising here?

ddl.aspx

<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager id="ScriptManager1" runat="server" EnablePartialRendering="true" >
</asp:ScriptManager>

<asp:DropDownList ID="Region" runat="server" >
</asp:DropDownList>

<cc1:CascadingDropDown
Category="Region"
Enabled="true"
PromptText="Please work..."
ID="CascadingDropDown2"
TargetControlID="Region"
ServiceMethod="GetCountries"
ServicePath="CountriesByRegion.asmx"
runat="server">
</cc1:CascadingDropDown>

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

CountriesByRegion.asmx

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports PFCEnergy.Refining.Country.Business
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
Public Shared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class

Hi,

I too get the same error . Have you sorted the problem ?

Pls help if its working for u .

Thanks.


Yeah got it working, I added the bold and removed the struck through. Good luck.

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Collections.Generic
Imports System.Data
Imports AjaxControlToolkit

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class CountriesByRegion
Inherits System.Web.Services.WebService

<WebMethod()> _
PublicShared Function GetCountries(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
Dim values As New _
System.Collections.Generic.List( _
Of AjaxControlToolkit.CascadingDropDownNameValue)

values.Add(New CascadingDropDownNameValue("foo", "bar"))
values.Add(New CascadingDropDownNameValue("bar", "foo"))
Return values.ToArray
End Function

End Class


Hi,

Iam not using list as u did in web method, So i thinkImports System.Collections.Generic is not needed.

Then i am not using Static (C#) in function.

So what would be wrong in my case?

Thanks.



Hi everyone, I had the same problem and after a little tweaking it works!

Here is the tip:

Please make that the database datatype matches the .NET datatype.If you have a different datatype in your database, you should TYPE CAST it to the corresponding .NET type.
string make = (string)dr["Make"];
int makeId = (int)dr["MakeID"];

.NET Framework Type

ADO.NET Database Type

SQL Data Type

String

Varchar

Varchar()

String

Nvarchar

Nvarchar()

String

NChar

Nchar()

String

NText

NText

String

Text

Text

Double

BigInt

Float

DateTime

DateTime

Datetime

DateTime

SmallDateTime

Smalldatetime

Int

Int

Int

Int64

BigInt

Bigint

Int16

SmallInt

smallint

Byte[]

Binary

Binary()

Byte[]

Image

Image

Byte[]

VarBinary

Varbinary()

Byte

TinyInt

Tinyint

Bool

Bit

Bit

Decimal

Decimal

Decimal

Decimal

Money

Money

Decimal

SmallMoney

SmallMoney

Float

Float

Float

Guid

UniqueIdentifier

Uniqueidentifier

Real

Real

Real

Wednesday, March 21, 2012

CascadingDropDown Problem

Hi All

I'm using the latest release of the toolkit. I'm building a CascadingDropDown and am getting a 12030 method error when I use a remote service (rather than have the service in the same project).

<cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="ddlMake" Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]" ServicePath="~/../CarServiceLocal/CarService.asmx" ServiceMethod="GetDropDownContents"/>

If I set the Service path to a local asmx file it works fine ServicePath="CarService.asmx"

But if I change it to be a remote service

ServicePath="~/../CarServiceLocal/CarService.asmx"

or

ServicePath="http://localhost/CarServiceLocal/CarService.asmx"

Then I get the 12030 method error.

Does anyone have any ideas?

Cheers


Craig

The CDD sample page uses the ~ syntax, so I'm reasonably confident it works in general. Your use of it with ".." makes me wonder if it works like you think it does. I'd say to double-check that the final path that gets used is correct.

CascadingDropDown Lists [Method Error 500]

Hi All,

I have recently started to learn AJAX, as well as all web developing. I am trying to read a database using a web service to populate drop down lists. I have searched through hundreds of posts and tried everything I found. The most common fix I found was to add System.Web.Script.Services.ScriptService before my class and System.Web.Script.Services.ScriptMethod before my WebMethod. I've tried upping my maxjsonlength. But these haven't fixed my problem. My problem being that on my development machine the app works fine, but on my webserver I get the Method Error 500. It seems like it can't find the asmx file, because, to see if it would even return anything, I took out the database read and put in bogus output.

Could my server be missing some key element to run AJAX? I have installed the Extentions on it. Is there something I have to do to deploy or publish the app? I have been just copying over all the files in my project.

I tried to put a call to the webservice in a page level method like they did on the How do I: cascading .. video, but that didn't work. I received a "BC30002: Type WebService not defined" Error. So that brings me back to thinking the app can't find the asmx file.

Anyone have any ideas?! Thanks for the help!

asmx file code:

Imports System.Web

Imports System.Web.Services

Imports System.Web.Services.Protocols

Imports AjaxControlToolkit

Imports System.Collections.Generic

Imports System.Data<WebService(Namespace:="http://tempuri.org/")> _

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

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

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

PublicClass WebServiceInherits System.Web.Services.WebService

<WebMethod()> _

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

PublicFunction GetCategory(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()

Dim myListAsNew List(Of CascadingDropDownNameValue)

Dim adapterAsNew DataSet1TableAdapters.sp_GetCategory1TableAdapter

myList.Add(New CascadingDropDownNameValue("test","test"))

Return myList.ToArray

'For Each dr As DataRow In adapter.GetCategory1

' myList.Add(New CascadingDropDownNameValue(dr("Category1").ToString, dr("Category1").ToString))

'Next

'Return myList.ToArray

EndFunction

EndClass

aspx file code:

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="true"CodeFile="Default.aspx.vb"Inherits="_Default"EnableEventValidation="false" %>

<%@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %> 'DO I REALLY NEED THIS LINE?

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="ScriptManager1"runat="server"/>

<br/>

<br/>

<div>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<asp:DropDownListID="DropDownList1"runat="server"Width="232px">

</asp:DropDownList><br/>

<br/>

<br/>

<cc1:CascadingDropDownID="CascadingDropDown1"runat="server"Category="cat1"LoadingText="Loading..."

PromptText="Select Category"ServiceMethod="GetCategory"ServicePath="WebService.asmx"

TargetControlID="DropDownList1">

</cc1:CascadingDropDown>

<br/>

<br/>

</ContentTemplate>

</asp:UpdatePanel>

</div>

</form>

</body>

</html>

Thanks Again!

Princess

Well, I figured it out. Turns out I had my folders in the wrong place. The way I was referencing the webservice, the App_Code file, App_Data, & Bin folders plus the web.config file have to be at the top level of your application folder.

Mystery Solved!


Thats nice..So mark the answer, so it will help for otheres.