Showing posts with label namespace. Show all posts
Showing posts with label namespace. Show all posts

Saturday, March 24, 2012

Namespace for client side Postbacks

Does anybody know what the Ajax namespace for implementing a clientside (javascript) postback is? Ideally I would like to fire a partial postback event to an update panel, pass in some arguements and then capture the event in the codebehind.Did you ever find an answer to your question? I've been looking for the same thing without any success. Every example I find is all about doing things on the client side nothing about the server side using .Net AJAX.

nope. It seems that there is no direct method to call a postback from JS. I find people asking for it all over the place though, so I would hope that MS includes it in the next version.

The work around is pretty good though. You basically have two options, I use option #1.

1) Set a hidden field as a trigger. Through JavaScript, update the value of the hidden field. This causes the Ajax postback as desired.

2) I have read about people placing a "submit" button in a hidden DIV and setting that as the trigger. Again, you submit the button via JS.

Let me know if you get stuck and I can send you code.


Thanks for your reply, actually I'm trying to write a control that uses the UpdatePanel. I wrap my control in it and I've tried adding some buttons to the triggers collection, but when I click the button it performs a normal postback. Is there anything special you've found that needs to be done for something like this to cause an ajax postback? What I'm doing here sounds kind of like your second suggestion, but it doesn't seem to work.

Anything INSIDE an Update panel should cause only an "Ajax" postback, and that includes other controls. Make sure you have the attribute Updatemode set to conditional. Like so:

<

asp:UpdatePanelID="UpdatePanel1"runat="server"UpdateMode="conditional">

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.

Namespace Question

The AtlasControlToolkit has a root namespace of AtlasControlToolkit, and the class files also have a namespace AtlasControlToolkit specified. To register the control, the namespace AtlasControlToolkit is used.

I am writing a new extender and am wrapping into a toolkit framework so that the next time I decide to add a control, my "toolkit" is already setup. I have specified a root namespace of My and my class files contain a namespace dictating My as well. In order to register my toolkit, I am forced to use "My.My". Where does the AtlasControlToolkit lose this extra level? Having My.MyAutoComplete is much nicer than My.My.MyAutoCompleteConfused

I'm not sure I fully understand your question. What do you mean by "register my toolkit" exactly?

Are you using VB? VB specifies a default root namespace, whereas C# does not. So if you apply a namespace, yes, you'll get the doubling up. So in your case, change the Default Namespace in the project properties to "My" and then don't add a namespace to your class files.


Yes, I am using VB. For not understanding my question, you did a darn good job of answering it! Smile Now if only you could solve my other problems haha.
Better lucky than good...:)

Namespace registered once but used in severel Files

Hi everyone!I'm sorry for my english, it's a bit rusty, because I'm german.My problem:I am developing a custom webcontrol, which is inherited from WebCrontrol and IScriptControl. Everything works fine on codebehind (I think ;)). I have also developed 4 JS-Files.In JSFile1.js I registered my namespaces (i.e. "Sample", "Sample.Control", Sample.Collection").In JSFile2.js I DO NOT register any Namespace, but I want USE the registered namespaces. But when I start my webapplication, IE says that "Sample" is unknown in JSFile2.js. Is my way of implementation possible at all?I hope you guys understand what I want. :)Thanks and greetsPuppetMasterP.S. I'm sorry for doubleposting, haven't seen this area at first.

Sounds like you may have an issue with the order of files being added into the page. Make sure JSFile1.js comes before JSFile2.js when your page is rendered.

-Damien


I fixed the problem. It was a simple comma. One comma to much...What is it called like? "wood for the trees" or something? :)Thanks and greetsPuppetMaster

Glad you fixed it. Please mark this topic as answered / resolved.

-Damien

Namespace undefined in gadget

I've developed a very simple gadget. It works on my computer well. I've installed it on LiveCom and it doesn't work. I am sure I amdoing all good, as Atlas documentation writes but I get an error.

Details: on button click I call a function (as in Atlas examples):

function DoSearch()
{
MyNamespace.MyGadgetBridge.Search(.................);
}

The error is: MyNamespace is undefined.

Also of course I have

<atlas:ScriptManager runat="server" ID="scriptManager">
<services>
<atlas:servicereference path="~/HelloWorldService.asmx" />
</services>
</atlas:ScriptManager>

Defined in Gadget:

<

Scripts><atlas:scriptreferencepath="rssgadget_wt.js"/></Scripts>

and simple bridge:

<?xml version="1.0" encoding="utf-8" ?>
<bridge namespace="MyNamespace" className="MyGadgetBridge" >
<proxy type="WSWrapper, App_Code" />
<method name="Search">
<input>
<parameter name="searchKeywords" />
</input>
</method>
</bridge>

It works on my computer. I get this error only on LiveCom, why? what is wrong?

Please help. Thank you.

hello.

can you give more info on this? i haven't tried using bridges from a gadget, but i have called remote web services without any problems by using the iframeexecutor client class...


There is all info you need I think. I am not doing anything difficult. Just the most simple example gadget with brige and javascript call. You can rework Atlas example gadget from documentation to use javascript call instead of declarative for 10 min to have call like:

function DoSearch()
{
MyNamespace.MyGadgetBridge.Search(.................);
}

The error is: MyNamespace is undefined.

This error I get on LiveCom, but woks on my computer

Maybe to install the gadget on LiveCom Microsoft should "allow" my gadget or bridge work there... I do not understand this.

Also I don't understand the process of installation of gadget on LiveCom. What files are copied? How it works from there?

In the call MyNamespace.MyGadgetBridge.Search(.................);
what bridge is called, my or that was installed on LiveCom?


hello.

well, if it's undefined, then the problem is that you're not putting the correct link on the gadget...


Mr.Luis Abreu,

Can you please give me a *hint* as to how you are executing cross domain requests using IFrameExecutor class?

It would be immensely helpful if there is any documentation.

Thanks

Indo.


hello again.

well, here's a quick example i've build a couple of months ago. it uses the amazon service, which is wrapped on a "local" web service. don't forget to uncomment the iframe handler on the web.config file. here's the code (i've built it in april and haven't run in with the latest ctp):

aspx file:

<%@. Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager runat="server" ID="manager" EnableScriptComponents="false" />
<atlas:Gadget runat="server"
Description="A gadget that let's you search Amazon.com."
ID="myGadget"
Title="Book Search by author name v2">
<ContentTemplate>
<input type="text" class="text" id="_txtSearch" name="_txtSearch" value="enter the name of the book you're interested in" />
<input type="button" id="_btSearch" value="Search" onclick="handleClick()" /><p></p>
<span id="t"></span>
<div id="_content">
</div>
<div id="_panel">
</div>
</ContentTemplate>
<Services>
<atlas:ServiceReference Path="AmazonHelper.asmx" />
</Services>
<Styles>
<atlas:StyleReference Path="~/cap12/livroatlasgadgetv2.css" />
</Styles>
<Scripts>
<atlas:ScriptReference Path="gadgetaux.js" />
</Scripts>
</atlas:Gadget>
</form>
</body>
</html>

js file

// JScript File
function handleClick()
{
LivroATLAS.AmazonHelper.GetBooks(
document.getElementById("_txtSearch").value,
1,
_onCallback);
}

function _onCallback( res )
{
var htmlContent = "";
var totalPages = res.TotalPages;
var currentPage = res.CurrentPage;

var books = res.BooksInCurrentPage;

for( var i = 0; i < books.length; i++ )
{
htmlContent += "<span><a target='_blank' href='" + books[i].Url + "'>" + books[i].Title + "</a></span><br /><span>" + books[i].Authors.join( "<br />" ) + "</span><p />";
}

if( htmlContent != "" )
{
document.getElementById("_content").innerHTML = htmlContent;
}
else
{
document.getElementById("_content").innerHTML = "No books found for that author.";
}

_fillPanel( currentPage, totalPages );
}

function _fillPanel(currentPage, totalPages)
{
document.getElementById("_panel").innerHTML = "";
for( var i = 0; i < totalPages; i++ )
{
var page = null;
if( currentPage != i + 1 )
{
page = document.createElement( "a" );
page.href = "javascript:;";
page.innerText = i + 1;
page.attachEvent( "onclick", _navigateToPage );
page.title = "Navigate to page " + (i + 1 );
}
else
{
page = document.createElement( "span" );
page.innerText = i + 1;
}
document.getElementById("_panel").appendChild( page );
}
}

function _navigateToPage()
{
LivroATLAS.AmazonHelper.GetBooks(
document.getElementById("_txtSearch").value,
event.srcElement.innerText,
_onCallback);
return false;
}

document.getElementById("_txtSearch").select();
document.getElementById("_txtSearch").focus();

asmx file

<%@. WebService Language="C#" Class="LivroATLAS.AmazonHelper" %>
using System;
using System.Web;
using System.Web.Services;
using Amazon;
using System.Configuration;

namespace LivroATLAS
{
public struct BookInfo
{
string _title;
public string Title
{
get { return _title; }
set { _title = value; }
}

string _asin;
public string Asin
{
get { return _asin; }
set { _asin = value; }
}

string[] _authors;
public string[] Authors
{
get { return _authors; }
set { _authors = value; }
}

string _url;
public string Url
{
get { return _url; }
set { _url = value; }
}

public BookInfo(string title, string asin, string[] authors, string url)
{
_title = title;
_asin = asin;
_authors = authors;
_url = url;
}
}

public struct TotalBookInfo
{
private int _currentPage;
public int CurrentPage
{
get { return _currentPage; }
set { _currentPage = value; }
}

private int _totalPages;
public int TotalPages
{
get { return _totalPages; }
set { _totalPages = value; }
}

private BookInfo[] _booksInCurrentPage;
public BookInfo[] BooksInCurrentPage
{
get { return _booksInCurrentPage; }
set { _booksInCurrentPage = value; }
}

public TotalBookInfo(int currentPage, int totalPages, BookInfo[] books)
{
_currentPage = currentPage;
_totalPages = totalPages;
_booksInCurrentPage = books;
}
}

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AmazonHelper : System.Web.Services.WebService {

[WebMethod]
[Microsoft.Web.Services.WebOperation(true, Microsoft.Web.Services.ResponseFormatMode.Json, true)]
public TotalBookInfo GetBooks( string author, int currentPage ) {
AWSECommerceService service = new AWSECommerceService();
ItemSearchResponse resp = service.ItemSearch(this.GetItemSearch(author, currentPage) );

if (resp.Items[0].Item == null)
{
return new TotalBookInfo(1, 1, new BookInfo[0]);
}

System.Collections.Generic.List<BookInfo> books = new System.Collections.Generic.List<BookInfo>();
foreach (Amazon.Item item in resp.Items[0].Item)
{
books.Add(new BookInfo(item.ItemAttributes.Title, item.ASIN, item.ItemAttributes.Author, item.DetailPageURL));
}

TotalBookInfo info = new TotalBookInfo(currentPage, Convert.ToInt32( resp.Items[0].TotalPages ), books.ToArray());

return info;
}

private ItemSearch GetItemSearch(string author, int currentPage)
{
ItemSearchRequest request = new ItemSearchRequest();
request.Author = author;
request.Count = "5"; //just to be safe :)
request.ItemPage = currentPage.ToString();
request.SearchIndex = "Books";

ItemSearch search = new ItemSearch();
search.Request = new ItemSearchRequest[] { request };
search.SubscriptionId = ConfigurationManager.AppSettings["AmazonId"];

return search;
}

}

}


Thanks for the reply. In one of your posts above, you said you implemented remote web services call using "iframeexecutor client class" ... Thats what I am really interested in. Basically how to do cross-domain calls from the client side without using Helper-webservice.

Any help would be appreciated.

Thanks again,

~Indo.


hello.

if i recall it correctly, there's not much into it. you just need to enable the iframecall.axd handler on the server side and you'll get the call made automatically (ie, the client side proxy will detect that you're invoking a remote web service and it'll use the handler automatically).


Hello...

I don't know if this will solve your problem, but I was receiving the same JavaScript error when implementing a bridge to call a remote web service.

The solution was as simple as adding this tag inside <microsoft.web> in web.config file:

<

webServicesenableBrowserAccess="true"/>

Hope this helps

Jaime


hello Luis

I see in your example following rows:

<atlas:Gadget runat="server"

I use MS AJAX v 1.0 b2 and I can't find this tag (I try asp:Gadget )

and second question - linkhttp://atlas.asp.net/docs/Walkthroughs/DevScenarios/gadget.aspx is not correct now. I have not found correct link :(

Please, help me. Thanks


hello.

unfortunately, gadget integration has been removed from atlas and i think it won't make it when v1.0 is out.


How I can call of web-service? should I create SOAP message?

Thanks


hello again.

as i told you in my previous mail, you cannot use the gadget control since it has been removed from the ajax extensions platform. i think that now you're supposed to use the API of live.com


It is very a pity :(
Thanks again

hello.

well, you can still use AJAX extensions in your gadget, though you do need to write more code without the gadget control.