Showing posts with label custom. Show all posts
Showing posts with label custom. Show all posts

Wednesday, March 28, 2012

Calling Javascript function as a property for an extender

Hi,

I have written a custom extender. In this custom externder, after a specific function is called, I would like to call another javascript function. This custom extender is re-used in various scenarios.So the javascript function to call is different in different scenarios. Code for all these scenarios cannot be put in the extender js file. So I would like to pass a dynamic javascript function name as a property value to the extender, and also give it the path of the js file which contains this javascript function. However I am unable to write this.

Can some one help please


Regards

Raj

Hi,

You can use eval function to invoke a function with its name.

For instance:

// in the .js file of the extender

function handler()
{
// a specific function
eval(_functionNameFiled + '();'); //_functionNameFiled is a field that hold the name of the function to be invoked
}


Marked your property asExtenderControlMethod, make this property as a function interface

Calling Custom Client Method with xml-script

Here is the situation, I have created a custom class that inherits from the ATLAS foundation client classes, I can initialize it with no problems with-in the xml-script, but what I want to do next is have a button call a method that of my custom client class, I know to add the button and click behavior but after that I am not sure what to declare as all the examples that I find are for web services and global javascript functions. Here is a tiny excerpt of the code I am working with to help:

I want to call MyContainer.AdjustThumbnailDimensions method and pass in the attributes from the two text form fields. Any help would be greatly apprieciated.

1<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">4<html xmlns="http://www.w3.org/1999/xhtml">5<head runat="server">6 <link href="CSS/Thumbnail.css" rel="stylesheet" type="text/css" />7 <title>Untitled Page</title>8</head>9<body>10 <form id="form1" runat="server">11 <atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />1213 <div id="ThumbnailContainer" thumbnailHeight="150" thumbnailWidth="100">14 <div class="Thumbnail" img="Images/Space.gif" label="Test Thumbnail"></div>15 <div class="Thumbnail" img="Images/Joker.jpg" label="Joker"></div>16 <div class="Thumbnail" img="Images/Space.gif" label="Another Test"></div>17 </div>1819 height <input type="text" name="tHeight" value="150" size="4" /> width <input type="text" name="tWidth" value="100" size="4" /> <input id="adjustDimensions" type="button" value="Adjust Thumbnails" onclick="AdjustThumbnailDimensions( document.forms[0].tWidth.value, document.forms[0].tHeight.value );" />20 </form>21 <script>22My.Client.UI.MyContainer = function( associatedElement ) {23 My.Client.UI.MyContainer.initializeBase(this, [associatedElement]);2425 var m_Thumbnails = new Array();26 var m_ThumbnailHeight;27 var m_ThumbnailWidth;2829 this.initialize = function() {3031 for( var index = 0; index < associatedElement.childNodes.length; index++ ) {32 thumbnail = associatedElement.childNodes[index];33 m_Thumbnails[index] = new SGP.SPI2.Client.UI.Thumbnail( thumbnail );34 m_Thumbnails[index].initialize();3536 m_Thumbnails[index].set_ThumbnailHeight( m_ThumbnailHeight );37 m_Thumbnails[index].set_ThumbnailWidth( m_ThumbnailWidth );38 }39 }4041 this.AdjustThumbnailDimensions = function( width, height ) {4243 for( var index = 0; index < thumbnails.length; index++ ) {44 m_Thumbnails[index].set_ThumbnailHeight( height );45 m_Thumbnails[index].set_ThumbnailWidth( width );46 }4748 }4950}51My.Client.UI.MyContainer.registerClass( "My.Client.UI.MyContainer", Sys.UI.Control);52Sys.TypeDescriptor.addType("script", "MyContainer", My.Client.UI.MyContainer);53</script>54 <script type="text/xml-script">55 <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">56 <references>57 <add src="Thumbnail.js" />58 </references>59 <components>60 <ThumbnailContainer id="ThumbnailContainer" />61 <button id="adjustDimensions">62<!-- What to do here ?? -->63<click>64 <invokeMethod />65 </click>66 </button>67 </components>68 </page>69 </script>70</body>71</html>
Thank youOk, I have figured out what I was missing from more disection of the ATLAS runtime and hunting around for more examples of invokeMethod. I had to add the method getDescriptor and then I was able to reference my method. Now the next phase to bind the parameters to the form fields.

Monday, March 26, 2012

Call webservices that expect bytes array

Do I need to write a custom converter to be able to call a webservice that has a byte[] argument?

What javascript types should I pass in to pass into the remote call?


Thanks,
Julien

Julien:

The closest type contained in JavaScript to a byte[] array would be the string, represented as an array of characters without encoding.

To the best of my knowledge, the only way to pass a undetermined amount of data to a web service using JavaScript would be to use the HTTP POST protocol.

A code snippet:

<html>
<head>
<title>Sample JavaScript Web Service with Byte Array</title>
<script type="text/javascript" language="javascript">
function load()
{
var form = document.createElement("form");
form.action = "http://www.samplesite.com/services/sampleservice.asmx/function";
form.encoding = "multipart/form-data";
form.method = "post";

var textbox = document.createElement("input");

form.appendChild(textbox);

var button = document.createElement("input");
button.type = "submit";
button.value = "Send to WS";

form.appendChild(button);

document.getElementById("container").appendChild(form);
}
</script>
</head>
<body onLoad="load()">
<div id="container"></div>
</body>
</html
That should do it! It does not take advantage of any of the Atlas Framework, but it would work the same from within an synced object initialization.

Good Luck!

Deavon McCaffery
JavaScript does not handle binary arrays. What is your scenario and what do you want to do with the binary data on the client?

call web service using ASP.NET AJAX with javascript without callback function

Hello,

I'm trying to create a custom validator with a ValidatorCalloutExtender all in an Update Panel. As everyone knows the callouts do not currently display automatically after a server post-back and will only work for custom validators which utilize client-side validation.

When i call the javascript function from validator callout extender i must return the args.IsValid method before the function ends. If i use a callback function and try to return the args.IsValid from there the validator can't react because the IsValid method is set to late.

In conclusion, with AjaxPro framework this example works

 function descriptionRequiredValidate(source, args){
var ajaxResult = FileAdmin.AjaxMethods.IsDescriptionRequired(...);
var descriptionText = document.getElementById("tbFileDescription");
var descriptionRequired = ajaxResult.value;
if(descriptionText.value =="" && descriptionRequired){
args.IsValid =false;
}
else{
args.IsValid =true;
}
}
As you can see no callback function is required but when i try to use the ASP.NET AJAX with a web service i can't read ajaxResult. Do i make a mystake somewhere or this tipe of response(without callback) only works with ajaxpro 

Your simplest path is to move your final declaration of validity to the OnSuccess handler of the service call.

Saturday, March 24, 2012

Call function from the custom extender

var sbFunc =new Sys.StringBuilder(this._callbackFunction);

sbFunc.append(

"('");

sbFunc.append(

this.get_element().id);

sbFunc.append(

"','");

sbFunc.append(foo[foo.length-1]);

sbFunc.append(

"','");

sbFunc.append(

this.get_serviceParameter());

sbFunc.append(

"')");

sbFunc.append(

";");

window.setTimeout(sbFunc.toString(), 0);

This code works fine until first postback. After, it still call function, but function really never get called. Function is located on the bottom of aspx file (Default.aspx). Why is it happens so? Maybe I put my custom function in a wrong place? I will appreciate any help.

Where is this code? Inside a custom JavaScript control?

When you say the "first postback", do you mean an async postback via an UpdatePanel?

Could you maybe share the rest of the page with us so we can see where everything is?


Steve Marx:

Where is this code? Inside a custom JavaScript control?

When you say the "first postback", do you mean an async postback via an UpdatePanel?

Could you maybe share the rest of the page with us so we can see where everything is?

Sorry, description was too short. I have custom extender. I want to be able call function that's inside aspx page on which I drop that extender. I wrote a piece of code you can see above. window.setTimeout(sbFunc.toString(), 0); That piece of code really works fine.

For instance ifthis._callbackFunction='__callbackFunc' and I have Default.aspx file:

<asp:UpdatePanelrunat="server"ID="UpdatePanel1"ChildrenAsTriggers="false"UpdateMode="Conditional">

<ContentTemplate>

Customer:

<br/><uc1:AutoTextID="atCustomer"runat="server"Width="230"CompletionInterval="2000"CompletionSetCount="10"EnableTheming="false"EnableViewState="true"MinimumPrefixLength="1"ServiceMethod="getListNames"ServicePath="http://olexiy.esconline.cc/test2/WebService.asmx"/>

...

</ContentTemplate></asp:UpdatePanel>

...

<script type="text/javascript">

function __callbackFunc(arg0, arg1, arg2) {

alert('hello world!');

}

I can actually see this message box "hello world" up until some async postback will happen in UpdatePanel1 ('caused by some other component). Afterwards I don't see message box "hello world" anymore.

</script>


Sorry for the slow reply... I still don't how you're injecting the JavaScript you want to run.

My best guess is you're using Page.Register* instead of ScriptManager.Register*... if so, make sure you're using the ScriptManager method.


Actually I use neither one. If I try to register java script with callback function in ScriptManager then script does not receive call at all, meaning that message box is not coming up.