Showing posts with label developing. Show all posts
Showing posts with label developing. Show all posts

Wednesday, March 28, 2012

Updating a Cell (TD) in a Table

Hi all,

I am developing a webcontrol and I am also developing an AjaxExtender for these control...

Now the problem is when I register an click Event, I works fine, but I would like to replace the

value of one special cell with the result I get from Sys.Net.WebServiceProxy.invoke(),

since I am not so familiar with javaScript and all these Ajax stuff ;) I would like

to ask you guys if you have any advice for me to do that...

thanks in advance,

Omid

It depends a bit on your table structure and how you have things marked up with id's and so on. The easiest possible case is that your TD has a unique id, in which case you can easily say:

$get('idoftheelement').innerHTML = resultsOfTheInvoke;

if you don't have a unique id for it, it's somewhat more complex, but generally it's easiest if you use array notation, for example,

var table = $get('idOfthetable');

var rows = table.getElementsByTagName('TR");

var firstRow = rows[0];

var firstRowTds = firstRow.getElementsByTagName("TD");

var lastTd = firstRowTds[firstRowTds.length-1];

once you have the TD you want, you can set its innerHTML property to the texto f the result param.


hi Paul,

thank you very much for the advice...

My Table and rows and Cols have all an unique ID,

so I think $get('idoftheelement').innerHTML = resultsOfTheInvoke; fits to me...

redards Omid.

ps. I have another little question... what will happen if the ID is not Unique?? will I get an Array?


ID's have to be unique. I've honestly never tried to do them otherwise, since the spec requires them to be. I imagine you'd get different results in different browsers and depending on your doctype declaration.

one thing to watch out for when using the Id is that if your table is a server control and its inside a Master page or a User Control, then ASP.Net will munge the server-side ID to keep it unique (in case you have mulitple instances of the same control o nthe page, etc). The solution to that is to either not use the id (use some other means such as the one described) or else embed the server-generated id somewhere on the page inside a <script> block such as : var myTableId = '<%= tblMain.ClientID %>';

Monday, March 26, 2012

Updating Atlas

Hello,
I was developing a produciton project using Atlas July CTP and Control Toolkit.
Now I'd like to updating to last version, but I can see that ATLAS is formed by 2 components:
Atlas 1.0 beta AND Atlas CTP beta.
I was used only Updatepanel in July CTP

What I need now? Is necessary to install both 1.0 and CTP?

And fot update what I do?
Must uninstall the previous version and then Install the new one?

tnx

If you just used the updatepanel, you don't need the CTP Beta, only the AJAX.net 1.0 beta. If you used the Atlas Control Toolkit, you'll need to reinstall that too. You'll also have to update your pages to work with new new edition of the framework, but with just updatepanels, it won't be that hard.
Can some direct me to installation instructions page......please.

For install instructions, go to:

http://ajax.asp.net/docs/Overview/installing/default.aspx

For changes between ctp and beta, go to:

http://ajax.asp.net/files/AspNet_AJAX_CTP_to_Beta_Whitepaper.aspx?tabid=47

For a feature matrix of what is in each install, go to:

http://ajax.asp.net and click on Feautre Matrix in tabbed panels.

Updating Issue: when Im trying to update from 1.0.60504.0 to 1.0.60731.0

Hi guys,

I'm developing a site (which is still Local and not uploaded yet) that uses Atlas technology.

Everything was good since I just tried to update Atlas Toolkit and Atlas Toolkit Extender to add some extra feature like rating and etc.

I got "Object reference not set to an instance of an object." !

firstly I thought it's because of my settings but I search and found that there is no problem in that matter, when I replaced new ones (Microsoft.AtlasControlExtender.dll, and AtlasControlToolkit.dll) with older ones, the problem resolved.

But I can't use new features on my site!SadConfused

Can anybody help please?!

Just a thought, but have you replaced Microsoft.Web.Atlas.dll as well? (you will need to if you are updating the toolkit)

Well, I did it, but when I saw your message I make it double check and for more accuracy I copy all DLL's related to Atlas from Atlas toolkit's sample website's bin folder, the problem still exisis!

Here is the stack trace for the error it may helps:

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.AtlasControlExtender.ExtenderControlBase`2.ConnectDataBindingHandlers() +241
Microsoft.AtlasControlExtender.ExtenderControlBase`2.OnInit(EventArgs e) +31
System.Web.UI.Control.InitRecursive(Control namingContainer) +345
System.Web.UI.Control.InitRecursive(Control namingContainer) +196
System.Web.UI.Control.InitRecursive(Control namingContainer) +196
System.Web.UI.Control.InitRecursive(Control namingContainer) +196
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1795


That's helpful - thanks.

You'll get this exception if the extender can't find one of the target controls (e.g. the value in TargetControlID). I've made a code change to help with debugging this, but double-check to make sure that each of those targets is correct.

You can also try handling the OnResolveClientID event that the extender will raise when it can't find a target as well to work around this.


I double-checked those but everything seems to be just fine!

Plus with no change in codes and just with replacing new DLLs with older ones this problem arose!

I'm just confused! I change all references through the refernces page and I think everything must be in its place, but still I stuck!

and the Debugger won't help me anymore! and this stack trace is the only thing I have!

Please Help!


Did you try handling OnResolveClientID?
I wonder if your situation is anything like http://forums.asp.net/thread/1366243.aspx ?

Yes it's the same code - but we're still not sure how folks are getting into that state.


Well, I havre to say "I'm not sure!"

you know, because Atlas is a new technology and I'm new to it too, when I want to add some feature to my site, FIrst I try to check it in a Test project to be sure, but situation is really different now!

because I have lots of Atlas extender's controls on my pages (specially in my Master page) and they are all good until I update DLL's, it's even harder to understand.

and for you last question, Yes I handled that handler but still same Error, I don't know but I think this error would happen even sooner than that you may think in its life time so this handler wont be any help.


Could you (or someone) paste in code that causes this? The fix we have didn't address the problem, so we're not sure what the exact scenario is. If you have the ASPX that causes it, that would be very helpful.

well,

I can't paste codes here (as they are more than 20 ASPX pages)!

but if I could it would not be hepful because we can't find the source of error and Stack trace is no help for ASPX pages I think.

but, let me tell you the scenarion one more time,

I just started to develope an Atlas Based web site but it takes such long time that I can now use July CTP Atlas Toolkit Control too!, but I have been using previous version of toolkit before, and this site contains some features like autoupdate panels, collapsible panels, alwaysvisible controls and all of them works well with previous version of Toolkit but as I got july CTP, and I found Ratings really helpful, I decided to use it, when I tried to add rating (which surely tries to update related DLLs such as Atlastoolkit, and web.atlas and atlas extenders) it just stuck! and this Null refernce error message became to be a constant part! (consider that the site uses some features specially Alwaysvisible toolkit extender in Master page that all of my pages derived from)

first I thought there is some code related error, but as I revert the DLLs the error disappeared!

That's it. thanks for you participation, but is there somebody to help?


For some horrible crossposting, just to make sure you're aware: http://forums.asp.net/2/1367145/ShowThread.aspx#1367145 .


Sweet, that was the bit of context I needed. I've got the exception reproing now...I'll see what the story is.

Thanks!


yes I know and I visited your Thread too, but I got none helpful yet. thanks for making me informed

Everyone -

I believe I've got a fix for this issue (thanks torchern13 for helping pull the pieces together).

If you're running into this issue, please pick up changelist 2820 (or later), build it, and post back here if it does not.

http://www.codeplex.com/SourceControl/ListDownloadableCommits.aspx?ProjectName=AtlasControlToolkit

Thanks,

Shawn

Wednesday, March 21, 2012

Use AJAX Extension without using the ASP.Net AJAX Enables Web Site Template

I'm developing a web app using a CMS and I want to use the ASP.Net AJAX Extension. Since I'm using a CMS, I cannot use the VS template.

I tried referencing the DLLs but I'm getting a 'Sys' is undefined javascript error.

Hi ubelt,

If you are not using a template, you will have to manually update your web.config file with all the setting required for AJAX, that's why you are getting this error.
In the documentation you can find exactly how to do it.

Hope this helps,

Juan

Use Custom Objects as Extender Control Properties - Part II

I thought this post -http://pietschsoft.com/Blog/Post.aspx?PostID=1377 - was very useful in further developing a custom ajax control extender. Thanks to Chris Pietschmann for posting his work.

I expanded his work to override the ConvertFrom method to JSON deserialize a string back to the custom object. In this example, I am using a Person object. Please refer to Chris's article for code and adapt the code with the changes I made below in bold italics:

GenericTypeConverter class:

namespace SandboxClass{public class GenericTypeConverter<T> : TypeConverter {public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value, Type destinationType) { JavaScriptSerializer jss =new JavaScriptSerializer();string s = jss.Serialize(value);return s; }public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value) {if (value is string) { JavaScriptSerializer jss =new JavaScriptSerializer(); T t = jss.Deserialize((string)value);return t; }else return base.ConvertFrom(context, culture,value); } }}
Person class:
namespace SandboxClass{ [TypeConverter(typeof(GenericTypeConverter<Person>))]public class Person {private string _FirstName;public string FirstName {get {return _FirstName; }set { _FirstName =value; } }private string _LastName;public string LastName {get {return _LastName; }set { _LastName =value; } } }}
 
Default.aspx
 
public partialclass _Default : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) {if (!Page.IsPostBack) { // serialize object to string to pass to client SandboxClass.Person person =new SandboxClass.Person(); person.FirstName ="John"; person.LastName ="Doe"; ajaxControlExtender.MyPerson = person; }else { // deserialize object back from client to your custom object, in this example, the Person object SandboxClass.GenericTypeConverter gc = System.ComponentModel.TypeDescriptor.GetConverter(typeof(SandboxClass.Person))as SandboxClass.GenericTypeConverter; SandboxClass.Person person = (SandboxClass.Person)gc.ConvertFromString(ajaxControlExtender.ClientState); Label2.Text = person.FirstName +" " + person.LastName; } }}
 
Also, in addition to step 5 of Chris's post and after manipulating the object on client-side, I am assigning the object to the ajax control extender ClientState property
to maintain state back to the server so the deserialization process can perform. Below is an example to include in the ajax control extender js file:
 
this._MyPerson.FirstName ='Jane';this._MyPerson.LastName ='Smith';this._MyPerson = Sys.Serialization.JavaScriptSerializer.serialize(this._MyPerson);this.set_ClientState(this._MyPerson);
Enjoy!

Thanks for your sharing.


Continuing to expand on this... It looks like this requires more work when one wants to serialize and deserialize an object with nested objects. Ugh... Any input or ideas to quickly move this along would be appreciated. I am thinking this will involve some recursive logic.


As an additional reference -http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx

It looks like I need to implement a JavaScriptResolver...


Well well... Sure enough, the JavaScriptResolver solves the problem with nested objects. The link in my previous post above explains it all.

Modified the code below in bold italics -

namespace SandboxClass{public class GenericTypeConverter : TypeConverter {public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value, Type destinationType) { JavaScriptSerializer jss =new JavaScriptSerializer(new SimpleTypeResolver());string s = jss.Serialize(value);return s; }public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,object value) {if (value is string) { JavaScriptSerializer jss =new JavaScriptSerializer(new SimpleTypeResolver()); T t = jss.Deserialize((string)value);return t; }else return base.ConvertFrom(context, culture,value); } }}

I am looking to move this JSON serialization of a custom object out of an AJAX control extender into a custom AJAX client control.

I have this part in my custom AJAX client control -

 IEnumerable IScriptControl.GetScriptDescriptors() { ScriptControlDescriptor descriptor =new ScriptControlDescriptor("CGAjaxClientControls.CGRadioButtonList",this.ClientID); descriptor.AddProperty("result",this.Result); descriptor.AddProperty("targetAction",this.TargetAction);return new ScriptDescriptor[] { descriptor }; }
The 'result' is just a string. That's the easy part but 'targetAction' is a custom object with nested objects as well.
The problem is I get this error message trying to deserialize on the client.

Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'String'. Parameter name: data

Here is the $create -

Sys.Application.add_init(function() { $create(CGAjaxClientControls.CGRadioButtonList, {"result":"Test","targetAction":{"ID":0,"TargetRadioButtonListId":"CGRadioButtonList1","RadioButton":[{"ID":0,"Text":"Yes","Value":"True","Selected":false,"Container":"panel","TargetControlId":"divCGRadioButtonList1Y"},{"ID":1,"Text":"No","Value":"False","Selected":false,"Container":"panel","TargetControlId":"divCGRadioButtonList1N"}]}},null,null, $get("CGRadioButtonList1"));});

Can anyone help me crack this? I do notice the type resolver tags are not getting added.

Thanks!


I think I've got this figured out. It is not required to deserialize the object when you create a custom AJAX client control. It's already done for you through IScriptControl.