Showing posts with label heres. Show all posts
Showing posts with label heres. Show all posts

Saturday, March 24, 2012

Namespace Help Please (Custom Composite Control/Extenders Project)

Ugh! Okay, so here's the situation. I have 2 custom extenders and a compsite control in a dll project. What is the best way to organize the files? I want to be able to access the extenders from any asp page as well.


The extenders are: DropZoneExtender and DragItemExtender
The control is: DragDropRepeater

Here's the file structure I have for the project ..

My problem is that while there are no immediate namespace issues, when the page is loaded I get the familiar "Assertion Failed: Unrecognized tag dropzone:DropZoneBehavior" popup.

Here's what the code looks like:

// DropZoneBehavior.js

Type.registerNamespace('DropZone');
DropZone.DropZoneBehavior = function() {
DropZone.DropZoneBehavior.initializeBase(this);
...
// code
..
}
DropZone.DropZoneBehavior.registerSealedClass('DropZone.DropZoneBehavior', AtlasControlToolkit.BehaviorBase, Sys.UI.IDropTarget);
Sys.TypeDescriptor.addType('DropZone', 'DropZoneBehavior', DropZone.DropZoneBehavior);

 
// DropZoneExtender.cs#region Assembly Resource Attribute[assembly: System.Web.UI.WebResource("DragDropRepeater.DropZone.DropZoneBehavior.js","text/javascript")]
#endregion
namespace DropZone
{
[ClientScriptResource("DropZone","DropZoneBehavior","DragDropRepeater.DropZone.DropZoneBehavior.js")]
[RequiredScript(FrameworkScript.AtlasUIDragDrop)]
public class DropZoneExtender : ExtenderControlBase
{
}
}
Anyone have any suggestions?

Hey,

I tried to fin the post, but no luck. Look for Case - Sensitive on the Atlas lists. The last Atlas Update made changes for Safari, and for some reason it needs the Namespace lowercase.

here is the current Script namespace. Now lowercase.

Sys.UI.DraggableListItem.registerSealedClass('Sys.UI.DraggableListItem', Sys.UI.Behavior);
Sys.TypeDescriptor.addType('script', 'draggableListItem', Sys.UI.DraggableListItem);

So change your:

DropZone.DropZoneBehavior.registerSealedClass('DropZone.DropZoneBehavior', AtlasControlToolkit.BehaviorBase, Sys.UI.IDropTarget);
Sys.TypeDescriptor.addType('dropzone', 'DropZoneBehavior', DropZone.DropZoneBehavior);

also change your

[ClientScriptResource("dropzone", "DropZoneBehavior", "DragDropRepeater.DropZone.DropZoneBehavior.js")]

Here is the link!!!

http://forums.asp.net/thread/1276996.aspx

Good luck.

Eric Wild


I figured it out, and actually its a little more complicated. I'm considering making a blog post about it.

Oh and lol .. remember, when you are creating the extenders from scratch .. make sure you mark the javascript files as an embedded resource. *smacks forehead* I used the example of the ReorderList, which is essentially what I'm creating where its based on the non-list versions of the dragdropUI and where reordering is not important, just the dragdrop.

Wednesday, March 21, 2012

Need Opinion

Hello all, =)

I have question(s) regarding the way I add JavaScript functions and I need opinion(s). Here's one of my example:

HTML:
...
<asp:TextBox ID="txtUserName" MaxLength="30" runat="server" />
<asp:Button ID="btnAddUser" Text="Add User" OnClientClick="return ValidateUser();" OnClick="AddUser" runat="server" /
Code Behind:
protected void Page_Load(object sender, eventargs e)
{
LoadMy_JavaScripts();
}

private void LoadMy_JavaScripts()
{
string script = "";
script += "function ValidateUser()";
script += "{ ";
script += " do something here ...";
script += "}";

System.Web.UI.ScriptManager.RegisterClientScriptBlock( ... ... );
}

As you can see how I register my javascript functions. Most my pages, LoadMy_JavaScripts() contains more than 20+ javascript functions. Every time when there's a postback (partial or not), this LoadMy_JavaScritps() is called again. I have developed more than 100+ pages of .aspx with ajax and all of them are working fine with the way I am doing.

Now I am wondering if what I am doing is right or not. I know that I can add the .js file directly to the ScriptManager using ScriptReference.

from the example above: if i move that ValidateUser function into a .js file, when should i add the .js file to the scriptmanager? Is it at Page_Load? I do not want to add it directly to the <asp:ScriptManager ... > because other pages do not use this function.

Any feedback/opinion would be sweet ... ta ta ...

The 'best practice' on this is to put all your .js in a separate file (or files as needed) and then add them as scriptreferences. THis makes them easier to control and maintain, lets your clients' browsers cache the information, stops you from having to resend the same stuff on every page_load, and so on.

If your scriptmanager is on a Master page (as you indicate) then you use a scriptmanagerproxy on the content page to load additional page-specific script files. ALternatively, you can add a scriptreference programmatically if you want. Embedding javascript in your codefile is a lot more prone to error, no matter how good you are it's easy to forget to add an important syntax bit when you're doing string concatenation.

As a sidenote, when you must concatenate strings, it's almost always a good deal more efficient to use the a StringBuilder object than it is to do += style string concatenation.


Paul,

thanks again, ... i don't have any problem with string concat. =) ... javascript is easy to debug anyway.

Thanks for your input ... before i used to add the javascript druing databound later on i moved everything to a function as i am doing right now. I guess I'll start storing them in a .js file. It makes more sense ... ... =)


Anytime; glad to help. FWIW, I used to do string concat that way too until I heard about the performance hit, which I gather can be pretty signficant if there are enough concatenations.