Showing posts with label client. Show all posts
Showing posts with label client. Show all posts

Wednesday, March 28, 2012

ExtenderControlProperty expression without quotes

How do I create an extender control property that will refer to a client function handler (or client object, or any client expression)?

If I create an extender propety as string (eg. string Property1), it will be rendered in client control creation as a quoted string:

$created(myComponent,{"Property1" : "value in quotes", ...

However I want it to be passed as client-side expression like that:

$create(myComponent,{"Property1": value without quotes, ...

I need something similar to ExtenderControlEvent attribute, which references a client-side handler, but it can only reference the ajax handler like MyFunction(EventArgs), and not any function with custom parameters, nor any custom client object).

In your client-side setter for the property, you can use: "this._expression = eval(value);".
I would suggest that, in your server-side setter, you make sure to check to make sure the developer doesn't try to use any parameters and to remove "()" from the value. If you don't, the above expression will execute the function and set this._expression to the return value of that function instead of setting this._expression to the function itself.

Hope that helps.

Monday, March 26, 2012

Exposing web service that returns DataSet

Hi,

Is there anyway to call web service(asmx) method that returns DataSet from client javascript that uses

AJAX <ScriptManager> (that generates auto js proxy) , I know that custom classes works as a return value, what about DataSets?

If Yes I can I process those DataSets , in client callback functions?

TNX

Leeor

leeorc

dont know if you can do this and whether it is an issue for you but if you do move to datasets then you will be restricting your web service to .net consumers only


http://weblogs.asp.net/infinitiesloop/archive/2006/12/14/ajax-futures-december-ctp-returning-datasets-datatables-and-datarows-from-a-webservice-or-pagemethod.aspx

Expand/collapse CollapsiblePanelExtender in Server Code?

Is there a way to expand/collapse a CollapsiblePanelExtender panel in server code? I have seen the post re: client side, but need to do it on the server during a postback.

Try using the Collapsed property of the CollapsiblePanelExtender server side.

/Klaus


Hi there!

You can set the extender's "Collapsed" property programmatically. This will collapse the panel (but without the fancy animation):

cpe1.Collapsed =true;

If you want your panel to slide in/out, you will have to trigger its behavior in JavaScript. You might register the script via Page.ClientScript.RegisterClientScriptBlock or Page.ClientScript.RegisterStartupScript to use it in code behind or call it onload/onunload. This example toggles a CollapsibePanelExtender using a JavaScript function:

1<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="Test.WebForm4" %>
2<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>34<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
56<html xmlns="http://www.w3.org/1999/xhtml" >
7<head runat="server">
8 <title>Untitled Page</title>
9 <script language="javascript" type="text/javascript">
10 /*
11Toggles a CollapsiblePanelExtender
12*/
13function Toggle(behaviorId, open) {
14// Find the behavior instance
15var behavior = $find(behaviorId);
16if (!behavior) return;
1718// Open or close the panel
19if (open){
20behavior._doOpen();
21}
22else{
23behavior._doClose();
24}
25}
26 </script>
27</head>
28<body>
29 <form id="form1" runat="server">
30 <div>
31<asp:ScriptManager ID="ScriptManager1" runat="server">
32</asp:ScriptManager>
33<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px" BackColor="Aquamarine">
34PANEL
35</asp:Panel>
36<a href="#" onclick='javascript:Toggle("bhv1",true);'>Expand</a>
37<a href="#" onclick='javascript:Toggle("bhv1",false);'>Collapse</a>
38<ajax:collapsiblepanelextender runat="server"
39BehaviorID="bhv1" ID="cpe1"
40TargetControlID="Panel1"41Collapsed="false" />
42 </div>
43 </form>
44</body>
45</html>

HTH and best regards,
Thomas

Executing custom client script after an UpdatePanel callback. How to do it?

I have a series of update panels doing their dance, andafter they are done, I'd like to execute a custom javascript function on theclient. I tried to add a separate update panel with a literal as a placeholderfor a javascript injection and set some code in the literals text property likethis:

protected void CallBackEventMethod()
{
javascriptInjectionLiteral.Text = @dotnet.itags.org."<scriptlanguage='javascript'>alert('waz up');</script>";
}

Woe is me, this does not work. Can anyone point me in the right direction as tohow I would execute client side logic after a server callback which is firedfrom an update panel?

Thanks,

bd

hello.

just add your script to the page by calling one of the registerXXX methods of the clientscriptmanager class.


yes but how do I then _call_ the script when the callback has completed it's processing?

In other words, how do I call the client side method once the CallBack has completed its processing?

bd
ok I see, RegisterStartupScript will call that method on the return of a CallBack as well as a postaback.

sweet

thanks for your help Luis,

bd

Executing Client Side JS after an async postback event returns

My issue has to do with firing a purely client side javascript event after the async postback returns from the server. I have scoured the documentation and these forums and not found, what I am sure to be a very simple thing to do. If anyone can point me in the right direction that would be greatly appreciated.

TIA

more information would be helpful.

Are you using JavaScript for the postback or an Ajax control, or what?


I'm using the AJAX ASP.NET controls. I have a single update panel that when it returns from processing an async event, I want it to automatically execute a JavaScript method that performs some UI effects.


This is exactly the same problem that we are experiencing. We are having a terrible time accomplishing this task and we need help as well.

If we register a "start-up" JavaScript block, it runs only once when the page first loads. It does not run again, even if we execute the same code.

Please help!


I think I found a solution:

http://ajax.asp.net/docs/overview/AJAXClientEvents.aspx

This describes how you can run client-side events after every successful AJAX UpdatePanel refresh. I used "PageLoading" and "PageLoaded" methods to accomplish what I need.


I have now found how to get back to the client-side JS by implementing this :

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);function EndRequestHandler(sender, args) { //do stuff here }

However, what I can't figure out now is what information is available to be able to figure out, for example, what event triggered the postback event, or what methods were invoked on the server or client side so that I can call the function that i want to process.



check out:

http://www.codeguru.com/csharp/.net/net_asp/scripting/article.php/c5337/


The final solution I came up with did indeed involve the aforementioned EndRequest but also capturing data from the BeingRequest. Not sure if there is a more elegant solution, but here's my JS.

1//This is a global JS variable that will be passed2var _PostBackElement;34//this sets the beginrequest and endrequest handlers5window.onload = function()6{7 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);8 Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);9}101112function BeginRequestHandler(sender, args)13 {14//This captures the element that Creates the15 //async postback into the global variable16 _PostBackElement = args.get_postBackElement();17 }1819function EndRequestHandler(sender, args)20 {21//check for the existence of the ID of the element that22 //caused the postback23if (_PostBackElement.id.indexOf("mSaveSearchButton") > -1)24 {25//do stuff here26 }27else if (_PostBackElement.id.indexOf("mSavedSearchLinkButton") > -1)28 {29//do other stuff30 }31 }

Basically, this captures the ID of the requesting element and then sets it in a global variable, then you use that to determine what action was being taken and on the EndRequest do whatever subsequent UI stuff you want.

That's it!


Try ScriptManager Register Startup Script instead of Page ClientScript Manager.

Execute client script in a async postback

Hi,

I´ve just replaced the july atlas ctp with ajax 1.0. I have a button as part of a UpdatePanel. In the serverside clickevent of the butten I want to call a client script but it doesn´t work. Even a simple alert('test') doesn´t work. I´ve used Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "alert('test');", true); as well as the similar command ScriptManager.RegisterClientScriptBlock. Can anybody help me?


Thx

Hi,

You need to call the new static registration method on ScriptManager to register the script. For the first parameter pass in the button that's inside the UpdatePanel to get its script to be sent down along with the UpdatePanel's new contents.

Thanks,

Eilon


hello.

btw, i have 2 questions about the new methods:

1. what happens if you're aa component developer? i mean, say that you need to support full and partial postbacks so that you allways sent something back to the client side. if you use the the new registerXXX from scriptmanager, you're creating a dependency between your control and ajax extensions. what happens if you don't wont ajax extensions on your app?

2. even though i see the possibilities in associating a script with a control placed inside an updaptepanel (while performing the script registration), what happens when you just need to insert a script back on the page during a partial postback? an example; you have a simple page with an updatepanel and you set the childrenastrigger to false. the objective of the panel is to let you get info from the controls, do some server side processing and then return a script to client (yes, a little off, but it's something that might be used by the old instance page methods fans since there's no instance page methods in the current release). since the chidrenastriggers is set to false, you can't send back a script from the server side (even though you assaociate it with a control inside the updatepanel) because the panel isn't being refreshed and due to that, it won't be included in the page.


More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon


Finally it works, thanks a lot!

Eilon:

More info about script registration in my recent post:http://forums.asp.net/thread/1440058.aspx

Thanks,

Eilon


hello.


still some questions remain:

1. my controls must always link to the ajax extensions dll even if the pages that use them aren't using ajax

2. i've presented a scenario where i just use an updatepanel to get all the controls on the server side and i need to send back a javascript message to the client. how can i accomplish this (i've set the childrenastrigger to false since i don't want to refresh the panel). if there was an overload for inserting javascript on the page without associating the instruction to a control, it would solve my problem (note that in those cases, i know that there's no chance of cleaning the script but i'd prefer to have that option since most of the time i'll be sending method calls from the server side).


Hi Luis,

1. See another of my recent posts:http://forums.asp.net/thread/1445844.aspx

2. The way I would like to see this implemented is that instead of the page registering the script, the page should add a control to the UpdatePanel and that control should register its own script. Nevertheless, it's a suggestion I've been considering myself. For example maybe if you pass in the Page or something we'll always include the script. I'm just afraid that it's a feature that people will abuse to no end and perhaps cause even more problems than it solves. Definitely under consideration, though.

Thanks,

Eilon


you may also look here:

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

Wednesday, March 21, 2012

Evaluate a returned object from Client-side callback

Ok...I'm a n00b to the Microsoft was of doing AJAX - I've been using Prototype.

I ran the tutorial video for the client callback, and had that working correctly.

Unfortunately, my real-world scenario is returning an object which from what I've been reading is neatly serialized by the Microsoft AJAX stuff into a JSON string/object/"thing".

This is where my brain explodes.

I don't know how to get the information out of this ethereal "thing" that's being returned by my web service. I can see the "stuff" when I look at it with Tamper Data, but don't know how to get at it.

Here's my client-side call:

function GetLicenseeDetails()
{
var retVal = eval(GetLicenseeInfo.LicenseeInfo(document.getElementById('<%= ddlLicensees.ClientID %>').value, OnComplete, OnTimeout, OnError));
alert(retVal);
return(true);
}

The alert I've thrown in there just reports 'undefined'.

If anybody's got a good place they can point me to learn what I'm doing wrong, I'd appreciate it very much. I'm hoping it's something simple...

Thanks in advance,

Ric

Hi

The calls are asynchronous which means that the reqyurn value is not immediately available to you. You will get the return object only in the OnComplete method.

function OnComplete(retVal) {

alert(retVal);

}