Sunday, March 11, 2012

application design - can ASP.NET AJAX do this?

Why don't you use an <iframe> for this?


We're doing the exact same thing, and what I'm planning to do is to use UserControls (.ascx). After making some test, everything worked fine except that if you have any clientside scripting on your UserControls, it would not be created :(


I've done the ascx thing described in the second response as well, it works pretty good (check out Scott Guthrie's blog athttp://weblogs.asp.net/scottgu/archive/2006/10/22/Tip_2F00_Trick_3A00_-Cool-UI-Templating-Technique-to-use-with-ASP.NET-AJAX-for-non_2D00_UpdatePanel-scenarios.aspx for details). It's probably how I'd approach this, though I don't necessarily know all your constraints.


wackoyacky, can you go into more detail on the UserControls? like, does the UserControl for each tab have its own <form> tag? i'm sure i'll end up creating a similar test app like you did, but a bit of a roadmap before i go would be very nice.Smile in regards to the clientside scripting problem, is it AJAX that doesn't work, or custom javascript, or...?

Scott Guthrie's approach that paul.vencil pointed out (thanks Paul!) is appealing as well, but i'll have to look into the ascx approach in more detail to see if this is our solution.


I'll assume you have already an idea on how to load user controls dynamically. Ok, here's what I have tested so far. I'm doing an online Resume that were divided into 4 sections: Personal Details, Education, Employment, Addtl Info. So basically I just have one page, a set of linkbuttons, usercontrols and a panel.

1.) Created linkbuttons for each of the section.

2.) Created UserControls (.ascx) for each of these sections.

3.) On Onclick event of link buttons, I load the respective usercontrol for the clicked linkbutton on a panel. All sections will be loaded on the same panel, so make sure you clear first the panel before loading a control.

4.) Just placed everything inside the updatepanel.


The problems I have encountered so far, was that if there are any clientscript(user defined) referenced or written on your usercontrol it will not work properly, though I'm having the idea of having it registered on codebehind if I could not find a solution at all. The other scenario I haven't tested is how about if there's a control in the usercontrol that requires a full postback.



If you use MS AJAX and if you want to include additional client-side script, the preferred way is register it using MS AJAX''s ScriptManager and call its static methods. I have registered the client script but somehow it won't work unless it's registered using ScriptManager. But if you have external source client script (.jsfile), you can use the Page'sClientScript.RegisterClientScriptInclude method,

For control that requires full postback, you can use ScriptManager.RegisterPostBackControl with the control as parameter. See this link:

http://ajax.asp.net/docs/mref/M_System_Web_UI_ScriptManager_RegisterPostBackControl_1_62fe17e7.aspx

happy coding!

Eriawan K.


@.eriawan

Yup, I was able to make the javascript work by using the Scriptmanager, both inline and external .js file, one thing though if you reference a .js file you have to add this line of code on your .js file

if( Sys && Sys.Application ){
Sys.Application.notifyScriptLoaded();
}

For full post back I've used the trigger tag option on the update panel to set the control to make full postback. I'll try to check on ScriptManager.RegisterPostBackControl .


The cool thing about ScriptManager.RegisterPostBackControl is you can make a control that is within an UpdatePanel to be treated as a full postback control (ordinary non AJAX control).

But this little trick is not so often mentioned in MS AJAX samples, but it's available in the documentation.

No comments:

Post a Comment