Saturday, March 24, 2012

Listview passing parameters problem

I use Listview by declaretive method and bind a method of webservice to it.But i want to pass parameters to its select method so i could select data with some restriction values.How can i do this?

<components>

<dataSource id="dataSourceMV" serviceURL="MainPageWebService.asmx"autoLoad="true" loadMethod="SelectMostValuableList" />...

Thanks

Hi,

first of all I have a question: really is your service method being called, even without parameters? (see the end of my post).

The DataSource control exposes aparameters object that you can use to pass parameters to your method. To do this, you have to expand the parameters object by adding a property with theexact name of the parameter, as declared in your method signature.

For example, suppose that I want to set the myparam parameter with the value of a textbox:

<dataSource id="dataSourceMV"
serviceURL="MainPageWebService.asmx"
serviceType="Handler"
autoLoad="true"
loadMethod="SelectMostValuableList"
>
<bindings>
<binding dataContext="myTextBox"
dataPath="text"
property="parameters"
propertyKey="myparam"
direction="In"
/>
</binding>
</bindings>
</dataSource>

Notice that you have to set theserviceType attribute to "Handler" if you want to be able to call a service method, otherwise you have to use a DataService.

Ok, now the bad news: probably this example will not work at all, because there's a bug in the March CTP that makes impossible to call service methods from a DataSource control, so you'll have to use a DataService (or declare a method calledGetData in your web service, that returns structured data).


Hi,

just a precisation on my previous post (I'm unable to edit it, maybe due to a forum upgrade?): using the March CTP is not possible to call, from a DataSource control, service methods defined in classic web services (i.e. classes that inherit from the System.Web.Services.WebService class), but it is possible to call methods defined in a class that inherits from the DataService class.


I dont understand how to use in webservice code ,in below code i want to access (send) parameter1.What do i have to exactly write in listview's datasource

<components>
<dataSource id="dataSource" serviceURL="MainPageWebService.asmx" autoLoad="true" loadMethod="SelectMostValuableList" />
<listView id="dataContents" itemTemplateParentElementId="masterTemplate" propertyChanged="onChange" >
<bindings>
<binding dataContext="dataSource" dataPath="data"property="data" ></binding>
</bindings>
<layoutTemplate>
<template layoutElement="masterTemplate"/>
</layoutTemplate>
<itemTemplate>
<template layoutElement="masterItemTemplate">
<label id="masterName">
<bindings>
<binding dataPath="miktar" property="text"/>
</bindings>
</label>
</template>
</itemTemplate>
</listView>
</components>

[DataObjectMethod(DataObjectMethodType.Select)]
public BLL.Collections.EnDegerlilerAtlas[] SelectMostValuableList(string myParameter1)
{
return MainPageWebService.Data7.ToArray();
}
Hi,

where does the myParameter1 value come from? Is it a form parameter, a bound value? Knowing this I can show you the appropriate code.
i want to pass just form parameter value like <input id="Hidden1" type="hidden" value="myParameter1" /> myParameter1 value to dataService.

Hi,

since we want to set parameters declaratively, we should upgrade the hidden field to an Atlas control, but no wrapper for the hidden field is provided by the framework. At this point, you could try to use a <textBox /> control:

<textBox id="myHiddenField" />

and then declare the DataSource control in this way:

<dataSource id="dataSource"
serviceURL="MainPageWebService.asmx"
loadMethod="SelectMostValuableList"
autoLoad="true"
>

<bindings>
<binding dataContext="myHiddenField"
dataPath="text"
property="parameters"
propertyKey="myParameter1"
direction="In"
/>
</bindings>

</dataSource>

In the declaration above, the value of the hidden field is bound to the value of myParameter1.


Hi All and Garbin,

When i execute the code that Garbin has provided, I get an error:

Assertion Failed: Could not resolve reference to object named "ctl00_ContentPlaceBody_HiddenLabel" for "dataContext" property on object of type "Sys.Binding"

and my page doesn't work.

Declaration of this Label is:

<

asp:LabelID="HiddenLabel"runat="server"></asp:Label>

Xml Script:

<components>
<dataSource id = "dataSource"
serviceURL = "EventsWebService.asmx"
autoLoad = "true"
loadMethod = "GetGeneralEvents"
>
<bindings>
<binding dataContext = "ctl00_ContentPlaceBody_HiddenLabel"
dataPath = "text"
property = "parameters"
propertyKey = "ClientLogin"
direction = "In"
/>
</bindings>

The --> dataContext = "ctl00_ContentPlaceBody_HiddenLabel" <--

portion is hard coded as currently i don't know how to pass the generated control id to the XML Script.

Urgent help is HIGHLY appriciated. :)


Ok, I failed to understand "upgrade your hidden field to an Atlas Control"

so now code lOOks like this:

<

labelid="HiddenLabel"><%=CurrentClient.Login%></label>

<dataSource id = "dataSource"
serviceURL = "EventsWebService.asmx"
autoLoad = "true"
loadMethod = "GetGeneralEvents"
>
<bindings>
<binding dataContext = "HiddenLabel"
dataPath = "text"
property = "parameters"
propertyKey = "ClientLogin"
direction = "In"
/>
</bindings>
</dataSource>
.

.

.

<label id="HiddenLabel">
<bindings>
<binding property="text" dataPath="text" />
</bindings>
</label>

:( but still i have an error saying :

No data context available for binding with ID "" and dataPath "text" on object of type "Sys.UI.Label"


Hi,

ok, let's start with the last snippet you posted. The <binding /> inside the dataSource control has dataContext="HiddenLabel". This means that there must be an Atlas control with the id of "HiddenLabel". This control is declared below, but encapsulates a binding that isn't needed. Try to remove it:

<label id="HiddenLabel" />
Hi,

Sentimotive:


I failed to understand "upgrade your hidden field to an Atlas Control"


when I say "upgrading something to an Atlas control", I mean associate to a portion of static HTML (one element or a whole set of elements) an Atlas control.

For example, if you declared a textbox like

<input type="text" id="myTextBox" />
you can upgrade it to an Atlas TextBox by adding a control in the xml-script section:

<textBox id="myTextBox" />

Now, myTextBox is also an Atlas control (before, it was only a DOM element), and the element is encapsulated inside the control.
Regarding the hidden field, there isn't a specific Atlas control that wraps it. What you could do in this case is upgrade the hidden field to a TextBox and use the text property to get the hidden field's value:

<input type="hidden" id="myHiddenField" />
<textBox id="myHiddenField" />

But the above code is a sort of hack, and the best approach would be to write a specific Atlas control that wraps the hidden field element.
Hi,

btw, coding a little Atlas control that wraps an hidden field element is not difficult:

Type.registerNamespace('AtlasUI.HiddenField');

AtlasUI.HiddenField = function(associatedElement) {
AtlasUI.HiddenField.initializeBase(this, [associatedElement]);

// get/set the value.
this.get_value = function() {
return this.element.value;
}
this.set_value = function(val) {
if(val != this.element.value) {
this.element.value = val;
}
}

// Allow declarative programming against this control.
this.getDescriptor = function() {
var td = AtlasUI.HiddenField.callBaseMethod(this, 'getDescriptor');

td.addProperty('value', String);

return td;
}
}
AtlasUI.HiddenField.registerClass('AtlasUI.HiddenField', Sys.UI.Control);
Sys.TypeDescriptor.addType('script', 'hiddenField', AtlasUI.HiddenField);

No comments:

Post a Comment