Showing posts with label following. Show all posts
Showing posts with label following. Show all posts

Wednesday, March 28, 2012

Change element on click

Hi,

I'm trying to create an AJAX-enabled control thas has the following functionality:

it's a Label that, when clicked, changes into a TextBox. The user can enter some text into the textbox en when he clicks outside the box (onblur) the textbox changes to a label again (now containing the entered text).

For this I created a server control inheriting from Label and a corresponding client control

The question is: can I change the displayed control in the _onClick event of the client control.

It should be something like:

_onClick : function(e){
this.element = $create(TextBox);
},

Does anyone know the right methods for this?

Thanks,

Thomas

Hmmm... I don't know if you can replace a control like that really. In that case, you would have to go to the parent element in the DOM tree, remove the label element and then add the text element. But that's very cumbersome.

What if you create both Label and TextBox and you toggle visibility on the two? Try changing the css attribute "display". Set it to block to show the element and none to hide it. Could help you with code in case you get stuck, just let me know. Good luck!

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 !

Wednesday, March 21, 2012

CascadingDropDown placed inside an asp:EditItemTemplate.

I tried the cascading dropdownlist when the user clicks on edit on a formview, but I realized from the following error that this will not work:

System.InvalidOperationException: The UpdatePanel 'EditUpdatePanel' was not present when the page's InitComplete event was raised. This is usually caused when an UpdatePanel is placed inside a template.

I also found a previous threadhttp://forums.asp.net/thread/1255759.aspxwhere the respondent confirmed that the updatePanel must be outside of the GridView

Does that mean that theAtlasControlToolkit:cascadingdropdown control cannot be used within any databound templated controls (such as GridView, FormView, Details, etc.)?

I don't believe so. UpdatePanel has "special needs" on the page which is why it probably has this issue. I haven't tried this but I think CascadingDropdownshould work OK - I can't think of why it wouldn't. Can you give it a try and report back?


I think the problem is that theatlasToolkit:CascadingDropDown requires anatlas:UpdatePanel around the dropdownlists otherwise changing the selection in one dropdownlist would not affect the next. But sinceatlas:UpdatePanel cannot be placed within the EditItemTemplate therefore it seems that there is no way to put theatlasToolkit:CascadingDropDown within the EditItemTemplate.

Here I tried 3 scenarios in addition to the one I described in my previous post:

1- The cascadingdropdown lists work if placed within atlas:UpdatePanel outside of an EditItemTemplate:http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown.aspx

2- The cascadingdropdown lists not working if placed within the EditItemTemplate and the atlas:UpdatePanel outside the FormView. http://www.webswapp.com/codesamples/aspnet20/atlas/cascadingdropdown2.aspx

(On my local PC, a JavaScript popup dialog box comes with the following error: "System.ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or in a page." But when run remotely you do not get that error. The lists just do not display anything)

3- The cascadingdropdown lists not working if placed within the EditItemTemplate and no atlas:UpdatePanel on the page

The source code for all scenario are listed on the demo pages.


CascadingDropDown does not need an UpdatePanel to work - the client-side changes are done in script and the web service requests are async thanks to Atlas. So #3 above is the scerario you probably want. I suspect it's not working for you because your ParentControlID properties are pointing at "CascadingDropDownX", but your DropDown controls are named "ddlYYY". Please try fixing that and let us know how it goes!

Hi David,

Thanks for your help. Your suspicion was right. I had the wrong values for the ParentControlID. Now that I corrected them and got it working within the FormView's EditItemTemplate and the data is being updated upon postback successfuly as shown here: http://www.webswapp.com/codesamples/aspnet20/atlas/toolkit_cascadingdropdown.aspx

I am wondering about the possibility of doing 2 more features to make the function of this control equivalent to the server-side controls:

1- How to set the default values upon loading the EditItemTemplate? (Since I could not use the Bind or Eval statements)

2- In order to prevent flashing of the screen when I submit the FormView, I tried using the Atlas:UpdatePanel around the FormView but I got this error message:

Assertion Failed: Unrecognized tag AtlasControlExtender:ValidationScript


That is so cool!

From above...

1) This is a feature we've added to the refresh, which should be available within the next day or so. When it is, you can just add a "SelectedValue='blah'" to the properties and it'll select that value

2) I'm not sure why you're getting that. In any case, in your extender set "SuppressValidationScript='false'" and it'll preven that guy from even loading.


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

I tried # 2 above but I still get the error. The code is exactly as listed in the link I provided before plus the updatePanel surrounding the FormView

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

<ContentTemplate>

<asp:FormViewID="FormView1"runat="server" .... >

</asp:FormView>

</ContentTemplate>

</atlas:UpdatePanel>


SuppressValidationScript="true"

Ok. The first error (above) does not show up but the next errors (which used to appear after I clicked on cancel) is still repeated for each dropdown list: "Assertion Failed: Unrecognized tag atlasControlToolkit:cascadingDropDownBehavior"


That's often related to the relative position of the controls, the extender, and the UpdatePanel. Some wiggling around of the different items can sometimes solve the problem. If it doesn't - and if the new Toolkit release doesn't help - please let us know.

CascadingDropDown method error 500

Hi,

I've created a new project following the video found here :http://www.asp.net/learn/ajax-videos/video-77.aspx

My code is the same as in the demo, but when I run the website, I have the "method error 500" in each dropdownlist instead of the makes, models and colors...

Does anyone know what this error code means ?

Thanks for your help.

Hi Dpin,

10.5 Server Error 5xx
Response status codes beginning with the digit "5" indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents should display any included entity to the user. These response codes are applicable to any request method.

10.5.1 500 Internal Server Error
The server encountered an unexpected condition which prevented it from fulfilling the request.

To resovle the kind of problem, we suggest that you should first check whether your WebService works fine or not. Then check the Control settings. If all these are ok, but your application doesn't work properly. Please add break points to your WebService and debug it step-by-step. Here is theuseful information. Please pay special attention to my last reply.

I hope this help.

Best regards,

Jonathan

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.