Showing posts with label complex. Show all posts
Showing posts with label complex. Show all posts

Wednesday, March 28, 2012

Extenders: Using complex types inside my Behavior.js javascript?

I added some complex types to my PanelExtender.vb that represents lists of numerical values:

Public Class ChartPanelExtenderInherits ExtenderControlBase(Of ChartPanelProperties, Panel)Private _dataseriesAs ArrayListPublic Sub AddSerie(ByVal p_serieAs DataSerie) _dataseries.Add(p_serie)End Sub Public Class DataSeriePrivate _valuesAs ArrayListPrivate _nameAs String Public Sub New(ByVal serieNameAs String) _name = serieNameEnd Sub Public Sub AddValue(ByVal p_valueAs Integer) _values.Add(p_value)End Sub Public Property Name()As String Get Return _nameEnd Get Set(ByVal valueAs String) _name = valueEnd Set End Property End Class End Class
Although I can easily create and add data series to my PanelExtender on the server-side (aspx page):

 Public Sub Page_load(ByVal sender As Object, ByVal e As EventArgs) Dim mySerie As New ChartPanelExtender.DataSerie("MyData") mySerie.AddValue(2) mySerie.AddValue(3) mySerie.AddValue(4) ' this is the name of the control in the page ChartPanelExtender1.AddSerie(mySerie) End Sub

I cannot figure how to access this data inside my javascript PanelBehavior.js code?
Do I need to somehow serialize/deserialize it manually?
How can I pass this data to the PanelBehavior.js script?

Any suggestions would be appreciated including telling me I am way off and giving an alternative hehe. All I really need is a way to pass data series to the behavior script.

Thanks in advance

PascalThe typical way of getting information to a JS behavior is via one of its properties. Your server code might transform the list somehow so that it can be safely passed to the behavior in a string (ex: [a, b, c] -> "a,b,c") and then the behavior can transform the string back into the data it represents. We're considering adding JSON support to this scenario so that more complex data types could be communicated more easily, but haven't done so yet, so the ->string-> technique may be a good choice for now. Hope this helps!
Okies, will see if JSON gets added in next CTP.
Thanks for the reply :)

Pascal

Monday, March 26, 2012

Executing inline JavaScript on load

I have a rather complex ASP.NET control -WebDialog - that I'm trying to get working within Atlas' UpdatePanel.

The way the control currently works is by outputting JavaScript in its render method which is executed by the browser on load. The problem is that when an UpdatePanel is refreshed Atlas doesn't seem to execute inline scripts and so nothing happens.

I have tried moving outputting the JavaScript from the control's render method to its PreRender and then passing the script to RegisterClientScriptBlock, which Atlas does execute. While this method works great in simple scenarios, when the dialog has form controls like TextBox and Button it errors. Since I'm manually calling RenderControl on the nested content, and outside of the form's render, VerifyRenderingInServerForm throws an exception.

I don't want everyone who uses the control to have to use a custom page with VerifyRenderingInServerForm overridden.

Is there a solution that will update when an UpdatePanel refreshes yet works with forms controls and isn't obtrusive to the user developer?

hello.

i doubt it...i think that the only option is sending the javascript to the client though the clientscriptmanager class...


If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.
From what I'm reading, I believe that your JS code is registering with the window's onload event. The first time your page loads the window.onload event occurs, but subsequent partial postbacks don't cause the window.onload event to occur again.

Your thoughts of registering the script with RegisterClientScriptBlock (or RegisterClientStartupScript) seem to be on the right path. I'm not real sure from your posts why your having to manually call RenderControl (shouldn't the controls be added to the parent control's control collection?), but executing inline JS code on load is possible on an UpdatePanel refresh by registering with the ClientScriptManager.

- Joel

hello.

James Newton-King:

If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.

hum...i'm following you...you say that you don't want to be dependant upon atlas ( i think you're talking about the server side dll?)...but you also say that you have the control placed inside an updatepanel. the only way you'll use a panel is if you add the atlas dll to your app!

one more thing: if you're using asp.net (i assume you are) then you can use the clientscriptmanager without any problems since it was introduced in asp.net 2.0 to handle client script registration.


Luis Abreu:

hello.

James Newton-King:

If I did that then I'd be dependant upon Atlas and have to include it's dll with my installer and output all it's JavaScript to the page which I don't want to do.

hum...i'm following you...you say that you don't want to be dependant upon atlas ( i think you're talking about the server side dll?)...but you also say that you have the control placed inside an updatepanel. the only way you'll use a panel is if you add the atlas dll to your app!

one more thing: if you're using asp.net (i assume you are) then you can use the clientscriptmanager without any problems since it was introduced in asp.net 2.0 to handle client script registration.


Obviously if the dialog was inside an UpdatePanel then the app would be using Atlas but this control is also for regular ASP.NET 2.0 users. They're the reason I don't want to become dependant upon Atlas.

Sorry, I confused the ScriptManager in Atlas with the ClientScriptManager in ASP.NET 2.0. I am already using the ClientScriptManager (RegisterClientScriptBlock is a method on it) to register the script so I thought you must have meant the Atlas one. The problem I'm having using RegisterClientScriptBlock is that when I register the JavaScript and render the html in PreRender, ASP.NET throws an exception. It doesn't allow form form controls to be rendered outside of the form.

Anyway, I've come up with a solution that appears to work:
I'm rendering the HTML like you usually would on a page but inside a hidden div and outputting the other JavaScript using RegisterStartUpScript so that it works with Atlas's UpdatePanel. When the dialog is displayed I copy the HTML out from the hidden div into the dialog.