Showing posts with label parameters. Show all posts
Showing posts with label parameters. Show all posts

Wednesday, March 28, 2012

PageMethods and Objects

Is it possible to send objects as parameters for a PageMethod and to return objects as the result of a PageMethod? I have a large amount of data (and multiple data types) that I want to collect from a form then send it to the server, and it would simplify things greatly if I could create an object rather than sending a bunch of individual parameters.

Thanks

Patrick

Yes, you can.

Among the list of of useless responses that one is very close to the top. Now I'll admit I didn't ask how to use objects in page methods if it's possible, but I tend to think the how is implied by the fact that I took the time to ask the question in the first place. Sense I appear to be wrong in my assumptions here is the followup question...

How do you use objects as a parameter or return value when calling a PageMethod? As far as I can see if I have a class defined in my website (call it MyClass) there is no equivilant class available in the client script.

Patrick


Sorry for the short response. First take a look athttp://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx (especially the last example on the page) and see if that answers your questions.

If you retrieve something from the web service (or page method), modify it on the client, and then send it back, you shouldn't have to do much. (The serialization should do all the work for you.) But it sounds like you might need to instantiate an object of this complex type on the clientfirst. In that case, notice the [GenerateScriptType(typeof(ColorObject))] attribute on the web service. That's the indicator to ASP.NET AJAX that the proxy it generates should include a definition of that type.


The short answer is that you can, and all you have to do is write your pagemethod signature as you would for a server-side call but w/ the webmethodattrbiute added. The framework reflects on those WebMethods and makes proxy classes in javascript to represent all the objects in the parameters and return types for you. Pretty cool feature, if you ask me. THe only downside (sorta) is that it chokes on certain complex objects (e.g. objects nested in objects), so you might have to write your own custom converter, per the link the other guy sent you.


Thanks for the link. I've taken a look and the samples look like they will work for me.

Monday, March 26, 2012

PageMethos Output parameters

Can i do something like this:?

[WenMethod]
public void Do(int x,out int y)
{
y = 3;
}

and get the 'y' value in my JavaScript?

I've never tried it with that syntax, but I have done:

[WebMethod]

public string Do(int x)

{ return 3;

}


hello.

well, if i recall correctly, output parameter aren't supported yet...

Wednesday, March 21, 2012

parameters in a query string to a cascading combo box...

hi all.. i have 3 combo boxes working with the cascading extender.

the problem i facing is that the first combo data depends on an item from the query string...

since now the method is a web method, i dont have access to the querystring, (i can write the code, but it always returns nothing)...

any idea how can i catch this value? for the trace i made that's the only problem i'm having with it...

Might you be able to save the relevant information on the server in the page/session state and access it there from your web method?


hi there.. i don't understand what you mean...

Hi,
By save the relevant information on the server, means that instead of passing the value in the querystring, you could for example save what you need into a session variable (Session.Add("VariableName", Value) ... and then access it in your webservice...

 <WebMethod(EnableSession:=True)> _Public Function GetContent(ByVal contextKeyAs String)As String Dim TranslationAs String =""Dim langNbAs Integer = -999Try If (Session("ParamLang2") IsNotNothing)Then langNb =CInt(Session("ParamLang2"))End If Catch ExAs ExceptionEnd Try . . . . . . . . end function

well.. that's a good idea..

Thanks :)

Parameters passing with ClickBehavour

I have read Wilco's post: http://www.wilcob.com/Wilco/Atlas/DeclarativelyInvokingJavaScript.aspx#comments

But still cannot pass a parameter to a function call.

<scriptlanguage="javascript"type="text/javascript">
functoin MyHandler(sender, args) {
var dc = sender.get_dataContext();
var descr = dc.getProperty("Description");
alert(descr);
}
</script>

[...]

<atlas:Button ...>
<ClickHandler="MyHandler"/>
</atlas:Button
is the example, on the page, but I dont get how I can get bind for example an ID to be passed to my function.

Thanks all :)

Hi,

you are using the function as an event handler (for the click event) thus it's normal that you cannot pass parameters to it; only the object that raises the event (the Button instance in this case) should pass parameter to event handlers.

What you could do is retrieve the ID parameter in the event handler. Which are your requirements?
Thanks for your reply :)

I have a datasource retrieved from the web service and is binding it toa list. For each row of the list, there is a "link" where the user canclick on to call the JS function passing in the ID that hopefully canbe binded to.

For example:

Data Source:

Name || ID

Joe Doe || 0
Garbin || 1

And the list will be outputtied as:

<a href="http://links.10026.com/?link=#" onclick=functiontoCall( 0 )> Joe Doe </a>
<a href="http://links.10026.com/?link=#" onclick=functiontoCall( 1 )> Garbin </a
Something similar to the above is what I am trying to do.

Thanks :)

Parameters... :(

Hi,

I have a menu with divs (items)...and I want to make one function to handle all menu items..

I have the following code:

var sCurrentPage = "";

<font size=2></font></p><p><font color=#0000ff size=2>function</font><font size=2> MouseClick(sender)
{
</font><font color=#0000ff size=2> if</font><font size=2> ($(sCurrentPage))
$(sCurrentPage).style.backgroundColor = </font><font color=#800000 size=2>"#FFFFFF"</font><font size=2>;
</font><font size=2>
sCurrentPage = sender.get_id();
$(sCurrentPage).style.backgroundColor = <font color=#800000 size=2>"#BBBBFF"</font><font size=2>;
</font></font><font size=2>}</font></p><p><font size=2></font>...</p><p>//my atlas script</p><font size=2><p><label id=</p></font><font color=#800000 size=2>"MenuItemNutriente"</font><font size=2>>
</font><font size=2><behaviors>
<clickBehavior </font><font size=2>click=</font><font color=#800000 size=2>"MouseClick"</font><font size=2> />
</behaviors>
</label><p></p></font>

The "sender" parameter is allways the clickBehavior object. How can I get the Label object that are firing the event?

thanx :)

I'm having trouble parsing all the HTML formatting above - does this question involve the Atlas Control Toolkit?