Showing posts with label working. Show all posts
Showing posts with label working. Show all posts

Monday, March 26, 2012

Catching an event from an Extender

I have written an extender and have everything working but catching an event in my .aspx page.

What is the recommended way for me to send a notification back to the application that something has happened in the extender and the page hosting the extender can take some action if it wants to?

I get the following alerts based on the code below

Client hooking into change -- at startup

add_changed -- at startup

raiseEvent: change -- when a change occurs

I have tried to use something like the following.

Control hookup in .aspx page

<psAjax:SampleExtender ID="sampleExtender" runat="server" TargetControlID="_tbName" Timeout = "250" BehaviorID="sampleExtenderBehavior"/>

Script in .aspx page

function linkBehavior()

{

var myBehavior = $find("sampleExtenderBehavior");

if (myBehavior)

{

myBehavior.add_changed(change);

}

}

function change () //This never fires

{

alert('aspx change');

}

Script in my extender .js file

add_changed : function(handler)

{

alert('add_changed');

this.get_events().addHandler('change', handler);

},

raiseEvent : function(eventName, eventArgs)

{

alert('raiseEvent: ' + eventName);

var handler = this.get_events().getHandler(eventName);

if (handler)

{

alert('Found raiseEvent: ' + eventName);

if (!eventArgs)

{

eventArgs = Sys.EventArgs.Empty;

}

handler(this, eventArgs);

}

},

I found my problem... I was not calling the linkBehavior method from pageLoad so a new behavior was created and destroyed when I called it.

I have since modified that approach and I am now registerting the event when a property is changed and this seems to work.

Is something like the following a valid way of doing things?

aspx code

<psAjax:TextChangedExtender ID="TextChangedExtender" runat="server" TargetControlID="_tbName" Timeout="250" TextChangedFunction = "onTextChanged" />

function onTextChanged()
{
alert('Client Side onTextChanged');
}


Extender .js

set_TextChangedFunction : function(value)
{
if (value != this.textChangedFunction)
{
this.remove_TextChangedHandler();

this.textChangedFunction = value;

var fn = new Function('return ' + this.textChangedFunction + '(); ');

this.add_textChanged(fn);

this.raisePropertyChanged('OnTextChanged');
}
},

Saturday, March 24, 2012

CascadingDropDownList fireEvent onchange not working when parent selection changed

I changed the included sample test page to remove the autopostback from theDropDownList3 dropdown (for color). I also removed the server side onselectedindxchanged eventhandler. I wanted to give the feedback to the user all from the client side. For that effect I added the following javascript code at the end of the page:

 <script type="text/javascript">$addHandler($get('<%=DropDownList3.ClientID%>'), "change", ProvideFeedback);function ProvideFeedback(eventElement){var makeDropdown = $get('<%=DropDownList1.ClientID%>');var modelDropdown = $get('<%=DropDownList2.ClientID%>');var colorDropdown = $get('<%=DropDownList3.ClientID%>');if(colorDropdown.selectedIndex == 0){alert("Please make all your selections");}else{alert('You selected ' + makeDropdown.options[makeDropdown.selectedIndex].text + ' - ' + modelDropdown.options[modelDropdown.selectedIndex].text + ' - ' + colorDropdown.options[colorDropdown.selectedIndex].text);}} </script>

It works just fine when I change the values in the color dropdown; I get the feedback. But I am also expecting to get the feedback when I change the make or model dropdown as the onchage is internally fired for color dropdown. But I never see that handled. Everytime I change values of make or model I never get the feedback.

Why is that? What am I missing?

Thanks.

Bumping up. Could someone please respond to this thread.

Ifthis.get_element().fireEvent('onchange'); is not producing the effect I am looking for what is it for?

Thanks.


Hi Nkv321,

CascadingDropDown will compare the selected value when its onchange event is fired. If no changes , there will no further actions , so it won't call the WebService.

I hope this helps.

Best regards,

Jonathan


It's not about changing the selected value and calling the web service. It's about when the parent value changes -- child drop down items get rebound -- and then an event is fired indicating that the child dropdown value has changed.

My question is what can that event be used for? How can it be used? I tried to use it in the sample that I put forth earlier but it was not executing. For example how can I add/attach a hanlder in the page to this event?

Thanks


Hi Nkv321,

I think you can attach a Javascript to the CascadingDropDown's add_selectionChanged or add_populated. For example:

function pageLoad(){$find("CascadingDropDown's BehaviorID"). add_selectionChanged(onSelectionChanged); }

function onSelectionChanged(){//your codes here.}

add_selectionChanged //Add an event handler for the selectionChanged event

add_populated //Add an event handler for the populated event

I Hope this help.

Best regards,

Jonathan

Cascadingdropdown working with web methods

Hi,

I am using the Cascadingdropdown as below

<atlasToolkit:CascadingDropDownID="CascadingDropDown1"runat="server">

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList1"Category="Principal"PromptText="Please select Principal"LoadingText="[Loading Principals...]"ServiceMethod="GetDropDownContentsPageMethod"/>

<atlasToolkit:CascadingDropDownPropertiesTargetControlID="DropDownList2"Category="MessageType"PromptText="Please select message type"LoadingText="[Loading Message Types...]"ServicePath=""ServiceMethod="GetDropDownContents1"ParentControlID="DropDownList1"/>

</atlasToolkit:CascadingDropDown>

<asp:DropDownListID="DropDownList1"runat="server">

</asp:DropDownList>

<asp:DropDownListID="DropDownList2"runat="server"/>

And the code behind is

<WebMethod()> _

PublicFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AtlasControlToolkit.CascadingDropDownNameValue()

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetRegions(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

EndFunction

<WebMethod()> _

PublicFunction GetDropDownContents1(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As AtlasControlToolkit.CascadingDropDownNameValue()

Dim lobjDALAs VOSS.Integrations.Web.DataAccess.XmlAdmin

Try

lobjDAL =New VOSS.Integrations.Web.DataAccess.XmlAdmin

Return lobjDAL.GetDropDownContents2(knownCategoryValues, category)

Catch exAs Exception

ReturnNothing

Finally

lobjDAL =Nothing

EndTry

ReturnNothing

EndFunction

Now the first function works and retrieves the values, but the second function does not. I am not using a web service. Do I need to always use a webservice for this. Can both the methods not pick values directly from db?

Pleae assist

Regards

Raj

Hi Raj,

You should check outFAQ Item #20.

Thanks,
Ted

Wednesday, March 21, 2012

CascadingDropDown returns [Method Error 12031] after upgrade to 1.0 Beta

After upgrading from the July CTP to 1.0 Beta all my CascadingDropDown's have stoped working. I only get [Method error 12031] in return an all of them. I hade the same problem when implementing them the first time but I then found the answer in thread 1393072 and referenced threads. This time however I am not able to find anything that helps me. I have tried to migrate my July CTP projekt to a new empty 1.0 Beta project but it doesn't help. Have anyone else hade the same problem?

I am grateful for any suggestions and tips!!

Have you made sure to decorate your service class with this attribute?

[Microsoft.Web.Script.Services.ScriptService()]
public class MyService : WebService
{
...
}


Thanks allot!

Now i works just fine. One can wonder why that line isn't in the walkthrough for CascadingDropDown!


Thanks a lot for that! That's been bugging me all morning. Although I didn't have [Method Error 12031], I had [Method Error 500], this solution still worked for me. It really should be in the walkthrough
I Agree! This should be added RIGHT AWAY!!!

Hey Guys,

Actually there is some documentation and I'll point you to where I found most of my upgrade info. Garbin's recent post on his blog has three links to some very vital information.

http://aspadvice.com/blogs/garbin/archive/2006/10/20/MS-AJAX-v1.0-Beta-and-Ajax-Control-Toolkit-released_2100_.aspx

The CTP-to-Beta whitepaper is where I found the not for adding the ScriptService attribute.

Hope this helps.


The method error 12030 still appears for me when I use the CTP and the specified attribute.

Regards

Vinit


Did you change the return type of your methods that populate your drop downs to return an array of AjaxControlToolkit.CascadingDropDownNameValue objects?

All web methods for child drop downs must have a signature that conforms to the following:

[WebMethod]
public AjaxControlToolkit.CascadingDropDownNameValue[] GetDataForMyChildDropDown(string knownCategoryValues, string category)

You can find this in the CTP-to-Beta whitepaper I believe.


Hiya.

Had the same problem and finally found out why. None of the other things suggested worked. Thanks to Steve Clements for that one... http://geekswithblogs.net/steveclements/archive/2006/10/23/94893.aspx

The web service class either needs

[Microsoft.Web.Script.Services.ScriptService]

or

using Microsoft.Web.Script.Services;

namespace Clm.Web.Services

{

[ScriptService]

publicclassFoo


Your most welcome :)

Steve


Same problem, but using only pagemethods...

What changes do I need to get it working?


Can you post some code?
http://forums.asp.net/thread/1486194.aspx

Hi,

I've run into the same error. However, when I change the line in the webservice.vb file from:

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

to:

<Microsoft.Web.Script.Serices.ScriptService ()
I get the error 'Type Microsoft.Web.Script.Serices.ScriptService' is not defined'

The whole "snippet":

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

Shared _DocumentAs XmlDocument
Shared _lockAs New Object

I'd appreciate any suggestions.
Thanks!

CascadingDropDown not working within EditItemTemplate in Ajax Beta

I had the cascading drop down working fine inside the EditItemTemplate in a gridview with the previous Atlas CTP release. But now it stopped working with Ajax Beta 1.0. Do I need to do something different to make it work again. I tried placing Gridview.Databind() in Page_Load, but that stopped the gridview from updating back to the database.

<EditItemTemplate>

<asp:DropDownListID="ddlBuEdit"runat="server"/>

<ajax:CascadingDropDownID="ccd1"runat="server"

TargetControlID="ddlBuEdit"

Category="BU"

LoadingText="Loading Data..."

PromptText="Select Business Unit"

ServicePath="getSelectionData.asmx"

SelectedValue='<%# Eval("BusinessUnit") %>'

ServiceMethod="getBU"/>

</EditItemTemplate>

Please see if this is relevant:http://forums.asp.net/thread/1441672.aspx.

CascadingDropDown method error 12031

Hello all,

I'm trying to use a CascadingDropDown Control in my application, but it isn't working, and I'm sure I'm following the instructions. Can anybody see what's wrong please? The page loads ok but the DropDownList Control that should be dynamically populated isn't. Instead, it displays an option that reads "method error 12031". I'm using Visual Studio .NET version 8 to develop, debug and run my application. Here's what I'm doing:

Firstly, the aspx page:

 <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:DropDownList runat="server" id="department" /> <asp:DropDownList runat="server" id="role" /> <AjaxToolkit:CascadingDropDown runat="server" id="CascadingDropDown1" TargetControlID="role" Category="role" PromptText="select a role" LoadingText="Loading roles..." ServicePath="~/WebModules/RoleAdmin/Services/RolesService.asmx" ServiceMethod="GetRolesInDepartment" />

Secondly, the Web Service referenced by the CascadingDropDown's ServicePath Property, which is in the "~WebModules/RoleAdmin/Services/RolesService/" directory:

<%@dotnet.itags.org. WebService Language="VB" CodeBehind="~/App_Code/RolesService.vb" Class="RolesService" %>

Thirdly, the CodeBehind for the WebService, which is in the "~/App_Code" directory. As you can see, for testing purposes it's as simple as it can be. It doesn't even look at a database!

Imports System.WebImports System.DataImports System.CollectionsImports System.Web.ServicesImports System.Web.Services.ProtocolsImports AjaxControlToolkitImports Harcourt.TMSUser.WebModules.RoleAdmin.Business<WebService(Namespace:="Harcourt.TMSUser.WebModules.RoleAdmin.Services")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _Public Class RolesServiceInherits WebService <WebMethod()> _Public Function GetRolesForDepartment( _ByVal knownCategoryValuesAs String, _ByVal categoryAs String) _As CascadingDropDownNameValue()Dim returnCascadingDropDownNameValues(3)As CascadingDropDownNameValue returnCascadingDropDownNameValues(0) =New CascadingDropDownNameValue("A role","1") returnCascadingDropDownNameValues(1) =New CascadingDropDownNameValue("Another role","2") returnCascadingDropDownNameValues(2) =New CascadingDropDownNameValue("The last role","3")Return returnCascadingDropDownNameValuesEnd FunctionEnd Class

I have remembered to put the AjaxControlToolkit.dll assembly in my "~/Bin" directory, and I have registered it in my web.config file.

So what could possibly be causing this error? I couldn't have made the method much simpler, and it is returning valid XML if I run the web service directly. Can anybody explain why I am recieving this 12031 method error, please?

Many thanks in anticipation of your advice.

Ben

On further research, I have come accross posts that suggest I MIGHT have to decorate the web service class with a <Microsoft.Web.Script.Services.ScriptService()> _ attribute as well as the <WebService()> _ attribute.

However, Visual Studio .NET doesn't like it when I do this. It says "type Microsoft.Web.Script.Services.ScriptService is not defined".

I tried importing the namespace containing that class but apparently it can't find that either:

Where is the Microsoft.Web namespace?

My application doesn't know. Do I need to write something in web.config to show it where to go?

Or am I completely on the wrong track anyway?

Any advice would be very much appreciated! Thank you.


Which version of AJAX are you running? Release 1.0 RTM should need

"System.Web.Script.Services.ScriptService()" vs "Microsoft.Web.Script.Services.ScriptService()"


Thanks for your reply, LSU.Net,

I'm using the version I downloaded the day before yesterday! So I guess the most recent version.

Are you saying I need a particular one of those two attributes, or both, or will either do?


There is no longer a Microsoft.Web namespace. You will need only the System namespace.

Thank you! At least now I can get it to compile and launch ok, now that I have the correct namespace and have tweaked my web.config file.

However, I'm still having trouble. This time it's on the client side. I have a javascript error "Error: 'name' is null or not an object". This error appears as soon as the page loads. The second drop down in my page is disabled, by the Ajax CascadingDropDown, and the SelectText is displayed. However, because of the Javascript error, the Control does not function in the browser at all.

Any ideas what causes this problem, please?


I reimplemented your code and still had problems... Error 500s and such. I did a PageMethod and it worked. Note: I removed your custom namespaces.

In the page: Example Default5.aspx:

 <asp:DropDownList runat="server" id="role" /> <AjaxToolkit:CascadingDropDown runat="server" id="CascadingDropDown1" TargetControlID="role" Category="role" PromptText="select a role" LoadingText="Loading roles..." ServicePath="Default5.aspx" ServiceMethod="GetRolesForDepartmentPageMethod" />
 
In Default5.aspx codebehind:
 
 
[WebMethod] [System.Web.Script.Services.ScriptMethod]public static CascadingDropDownNameValue[] GetRolesForDepartmentPageMethod(string knownCategoryValues,string category) {return new RolesService().GetRolesForDepartment(knownCategoryValues, category); }
  
RolesService.cs:
 
 
 [WebMethod] [System.Web.Script.Services.ScriptMethod]public AjaxControlToolkit.CascadingDropDownNameValue[] GetRolesForDepartment(string knownCategoryValues,string category) { CascadingDropDownNameValue[] returnCascadingDropDownNameValues =new CascadingDropDownNameValue[3];//Dim returnCascadingDropDownNameValues(3) As CascadingDropDownNameValue returnCascadingDropDownNameValues[0] =new AjaxControlToolkit.CascadingDropDownNameValue("A role","1"); returnCascadingDropDownNameValues[1] =new AjaxControlToolkit.CascadingDropDownNameValue("Another role","2"); returnCascadingDropDownNameValues[2] =new AjaxControlToolkit.CascadingDropDownNameValue("The last role","3");return returnCascadingDropDownNameValues; }

Thank you very much, I'll give it a try after lunch, but do you know why I can't use a separate web service? I thought that was supposed to be within the capabilities of the CascadingDropDown Control.
You should be able to, but I had problems. I'm unsure why.
Have a look at the ToolkitTests\CascadingDropDown.aspx automated test case that comes with the Toolkit for an example of using a Web Service (vs. a Page Method).
This cascadingdropdown control is a complete waste of time. I've tried everything, web service, page methods, static, in a user control, in a aspx page... all I get are 12031, 12030, and 500 errors.

You probably didn't make your function shared.

also Im not sure if its required but you should have your script managerEnablePartialRendering="true"

<WebMethod()> _

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

PublicSharedFunction GetDropDownContentsPageMethod(ByVal knownCategoryValuesAsString,ByVal categoryAsString)As CascadingDropDownNameValue()

Dim kvAs StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

Dim iProductIDAsInteger = 0ForEach deAs DictionaryEntryIn kv

iProductID = de.Value.ToString()

Next

Dim dsAs Data.DataSet = fill your dataset

Dim valuesAsNew List(Of CascadingDropDownNameValue)

ForEach drAs Data.DataRowIn ds.Tables(0).Rows

Dim vAsNew CascadingDropDownNameValue

v.name = dr("Version")

v.value = dr("VersionID")

values.Add(v)

Next

Return values.ToArray

EndFunction


Eventually I made it work with DotNetNuke 4.5.3.
The way to do it is pretty hardcore!

0. Obtain the sources of the whole AjaxControlToolkit package.1. Copy two script files "CascadingDropDownBehavior.js" and "BaseScripts.js" from AjaxControlToolkit to the "~/DesktopModules/" dir of your site.
2. Rebuild the whole AjaxControlToolkit with the original files "CascadingDropDownBehavior.js" and "BaseScripts.js" madeEMPTY!
3. Add some lines to your .ascx module file as it is written here: http://www.adefwebserver.com/DotNetNukeHELP/Misc/Dotnetnuke_AJAX_webservices.htm
In our case we have 2 javascript files, so the code of Page_Load() will be like this:

...
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
// Create a reference to the Script Manager
ScriptManager objScriptManager = ScriptManager.GetCurrent(this.Page);
// Add a reference to the web service
ServiceReference objServiceReference = new ServiceReference();
objServiceReference.Path = @."~/DesktopModules/YourModule/YourWebService.asmx";
objScriptManager.Services.Add(objServiceReference);

ScriptReference objScriptReference1 = new ScriptReference();
objScriptReference1.Path = @."~/DesktopModules/YourModule/BaseScripts.js";
objScriptManager.Scripts.Add(objScriptReference1);
ScriptReference objScriptReference2 = new ScriptReference();
objScriptReference2.Path = @."~/DesktopModules/YourModule/CascadingDropDownBehavior.js";
objScriptManager.Scripts.Add(objScriptReference2);
}
...

4. Build your website. Voila!

Sorry, if something is not clear enough. I've spent the whole night trying make it work.. )

I've managed to get this working on my PC. For some reason using upper case characters in XML element names causes a problem (the example in the toolkit uses: make, model and color, not Make, Model and Color). Also I think the name of the the XML file has to be the same as the service as well - eg. CarsService.cs relates to CarsService.xml. I might be completely wrong but that's the only way I could get it to work for me... I recommend copying and tweaking the code from the Tool kit sample one bit at a time.