Showing posts with label service. Show all posts
Showing posts with label service. Show all posts

Monday, March 26, 2012

Property value undefined after succesfull web service call

Hello,

hopefully I can explain my problem.

I started to create extended control with ajax control toolkit. Idea is, that I have textfield which works so

that it suggest values every time when user hits key. Like that --> http://www.google.com/webhp?complete=1&hl=en

Now in SearchTextBoxBehavior.js file I have two propertys, which one hold id for listbox which shows suggestions.
(I think in that google example, the control is span or div element.)


Ok, I have succesfully created event, which is occurred when user hits key in textfield. Webservice call is made in bold code line-->

1_onkeyup : function() {
23 var targetButton = $get(this._TargetButtonID);
4 var targetListBox = $get(this._TargetListBoxID);
5
6if(targetButton && targetListBox) {
7 targetButton.disabled =true;
8
9// unescape() convert′s a string to URL-encoded form10 var searchValue = unescape(this.get_element().value);
11
12if(searchValue !="") {
13// Set suggestion visible14 targetListBox.style.visibility ="visible";
15
16MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded);
17 }
18else {
19// Set suggestion hidden when there is no search value inserted20 targetListBox.style.visibility ="hidden";
21 }
22 }
23
24 },
 
Web service call is succesfull, and returns into function:
 
1_onSucceeded : function(Result) {23var targetListBox = $get(this._TargetListBoxID);45var table = Sys.Preview.Data.DataTable.parseFromJson(Result);67...89}
 
Problem is, that in that _onSucceeded function, propertythis._TargetListBoxID is
undefined. In function, where I made web service call, the property was ok, and I could
make instance about control.
 

Hi,

you need to modify the context under which the callback is executed. This can be done with a delegate and the Function.createDelegate method:

MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,Function.createDelegate(this, this._onSucceeded));



Hi,

it worked, thanks. :)


Yesterday evening I managed to circulate problem, with solution below.

1var inputParams =new Array();2inputParams[0] =this._TargetListBoxID;3inputParams[1] =this._TargetButtonID;4inputParams[2] =this._ListControlTextField;5inputParams[3] =this._ListControlValueField;67MyCompany.WebServices.MySearch.GetDataTableFromWebservice(searchValue,this._onSucceeded,this._onFailed, inputParams);

Hi,

yes, as your code shows, you're passing a context object as the last parameter to the proxy method. This is useful especially if you want to access only certain references in the callback and not the whole instance.


Hi All,

huygens...is there any way you can post your full code? I'm looking to do something similar with the toolkit. Would be greatly appreciated.

proxy and authentication services

Hi All,

I'am testing some features of AJAX Library and also the services that they offer. I have a question about this service. where does this service run and how do i point it to my SQL database where my users are stored. i think in the web.config but show some code please.

Kind regards,

Well i read some info from another thread.and saw that you can use your own webservice. So i want to use my own webservice, but in this example its pointing to a webservice only and not his method. How does this work? how do you configure it to go to the right login method. Thanks in advance

Yes, you can use your own authentication Web service.
You configure the path to your own Web service like it's shown in this link:http://ajax.asp.net/docs/mref/595cde79-7340-40f0-ba08-2efaff3d4d0c.aspx

Your web service needs two methods Login and Logout:

using System.Web.Services;
using Microsoft.Web.Script.Services;

[ScriptService]
public class MyAuthenticationService : System.Web.Services.WebService
{
[WebMethod]
public bool Login(string userName,
string password,bool createPersistentCookie)
{
//Place code here.
return true;
}

[WebMethod]
public void Logout()
{
//Place code here.
}
}

This same code will be shown in the next release of the documentation.

Hope this helps,

MaĆ­ra


Hi Maira,

Thanks for your reply. So the only thing thats left to do is changing the path of your authentication service?

Kind regards,


Besides that, you need to enable the authentication service in the configuration file. (I don't know if you already did)


Hi Maira,

Yes i already enabled the authentication service in my configuration file. thanks for your info

Regards

Saturday, March 24, 2012

Question about adding data to a databse (Im new to Atlas)

I'm wondering how I use Atlas to dynamically add data to a database using the default.aspx.cs file and not a web service. Any help is appreciated.

hello.

well, you have 2 options (one sucks more that the other :D):

1. use page method

2. use an updatepanel.

Question about object returned from web service...

I have the following script code:

<

scriptlanguage="javascript"type="text/javascript">

<!--

function

Button1_onclick() {

ret = SimpleService.ReturnDataTable(

"fi","la","te", OnComplete, OnTimeOut, OnError);

return

(true);

}

function

OnComplete(arg) {

document.getElementById(

'Text1').value = arg;

//alert(arg);

}

function

OnTimeOut(arg) {alert("TimeOut encountered when calling Say Hello.");

}

function

OnError(arg) {

<

scriptlanguage="javascript"type="text/javascript">

<!--

function

Button1_onclick() {

ret = SimpleService.ReturnDataTable(

"fi","la","te", OnComplete, OnTimeOut, OnError);

return

(true);

}

function

OnComplete(arg) {

document.getElementById(

'Text1').value = arg;

}

function

OnTimeOut(arg) {alert("Error encountered when calling Say Hello.");

}

function

OnError(arg) {

alert(

"Error encountered when calling Say Hello.");

}

// -->

}

</script>

And this is the webservice method it calls:

publicDataSet ReturnDataTable(String Name,String Last,String Test)

{

DataSet ds =newDataSet();DataTable dt = ds.Tables.Add("RandomTable");DMStoDD dd =newDMStoDD();DataColumn column1 =newDataColumn();

column1.ColumnName =

"Name";

dt.Columns.Add(column1);

DataColumn column2 =newDataColumn();

column2.ColumnName =

"Last";

dt.Columns.Add(column2);

DataColumn column3 =newDataColumn();

column3.ColumnName =

"Test";

dt.Columns.Add(column3);

DataRow row;

row = dt.NewRow();

row[

"Name"] = Name;

dt.Rows.Add(row);

row = dt.NewRow();

row[

"Last"] = Last;

dt.Rows.Add(row);

row = dt.NewRow();

row[

"Test"] = Test;

dt.Rows.Add(row);

return ds;

}

Is there something wrong with the way I'm calling my DataSet/DataTable?

Also, what properties does the client side object 'arg' have?

J

arg should have whatever properties are public on the server-side object (I believe) but only if you have a [ScriptService] attribute on the web service, and only if you have a jsonconverter defined for the data type. The default converter works pretty well for most data types, but seems to choke a bit on certain things. I've never done dataset/datatables (typically I roll my own collection for those applications) but from what I've read you can get a dataset converter if you use the Futures dll and make the appropriate changes to your web.config to suppor tit.

Wednesday, March 21, 2012

Question about using AJAX to update a GridView

I'm pretty new to AJAX, but so far I have managed to get a web page working that calls a web service, and the web service returns an array of objects. I would like to use those objects to populate a GridView. But so far, I have been unable to find a way to do that from the javascript on the page. Is this possible?

Hi Ian,

The Microsoft GridView does not have that ability currently. If you're interested, there are other 3rd party grids out there that currently provide a client-side model for adding rows.

-Tony


hi Ian,

did you tried to use ObjectDataSource? take a look at it this linkhttp://www.gridviewguy.com/ArticleDetails.aspx?articleID=139 may be helpful to you.

regards,

satish.


OK, since there's no easy way to do this now, and I don't have the budget for a pre-packaged control, I just did it manually with good old HTML tables and javascript. Thanks for the help though.

Question on DynamicUpdate properties...

When using this feature - my understanding is that the principle around it is to use a web service.

Say for a popup form modal or otherwise... one was to use it...

how do you go about setting security principles and otherwise preventing someone that shouldn't have access to it beyond the mere fact you can authenticate prior to...my concern is security using this feature...are there any examples to look at that do not use the profile services that guards against someone using a tool like fiddler from manipulating and querying or otherwise being able to submit when using Atlas dynamic behaviors in this manner?

I'm not sure I understand what security issues you feel DynamicPopulate introduces (that aren't already present). Could you outline a scenario, perhaps?

Question: Using CascadingDropDown with OleDb

I'm curious. Do youhave to use a Web Service when trying to pull items for a cascading drop down from a database or is there another (perhaps simpler) way? I'd love to be more enlightened on the subject. Thanks in advance.

Hi Venom,

VenomZ302:

Using CascadingDropDown with OleDb

I have made a sample. Hope it helps.

ASPX:

<%@. Page Language="C#" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> State:<asp:DropDownList runat="server" ID="dlState"> </asp:DropDownList> City: <asp:DropDownList runat="server" ID="dlCity"> </asp:DropDownList> <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="dlState" Category="State" PromptText="Select a state" ServicePath="../WebService/CityServiceOledb.asmx" ServiceMethod="GetStates" LoadingText="Load Text..."> </cc1:CascadingDropDown> <cc1:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="dlCity" ParentControlID="dlState" Category="City" PromptText="Select a city" ServicePath="../WebService/CityServiceOledb.asmx" ServiceMethod="GetCities" LoadingText="Load Text..."> </cc1:CascadingDropDown> </form></body></html>

WebService:

<%@. WebService Language="C#" Class="CityServiceOledb" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections.Specialized;
using System.Collections.Generic;
using AjaxControlToolkit;
using System.Data.OleDb;
using System.Web.Script.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class CityServiceOledb : System.Web.Services.WebService {

protected OleDbConnection cn;
protected OleDbCommand cm;
protected OleDbDataReader myReader;
private string strSql = "";
//private string conStr = "data source=TASKONE\\SQLEXPRESS;initial catalog=TestDB;user id=sa;pwd=password;Pooling=True; Min Pool Size=0; Max Pool Size=1000; Connection Lifetime=30;";

//private string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\MyWork\\DB\\YourDBName.mdb";
//using Microsoft Office2007
private string conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\MyWork\\DB\\Database1.accdb";
public CityServiceOledb() { }

[WebMethod]
public CascadingDropDownNameValue[] GetStates(string knownCategoryValues, string category)
{
strSql = "SELECT * FROM tb_State";
GetDr(strSql);
List<CascadingDropDownNameValue> myList = new List<CascadingDropDownNameValue>();
while (myReader.Read()) {
myList.Add(new CascadingDropDownNameValue(myReader["StateName"].ToString(), myReader["StateID"].ToString()));
}
myReader.Close();
return myList.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetCities(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int stateID;
if (!kv.ContainsKey("State") || !Int32.TryParse(kv["State"], out stateID))
{
return null;
}
List<CascadingDropDownNameValue> myList = new List<CascadingDropDownNameValue>();
strSql = "SELECT * FROM tb_City WHERE StateID=" + stateID.ToString();

GetDr(strSql);
while (myReader.Read())
{
myList.Add(new CascadingDropDownNameValue(myReader["CityName"].ToString(), myReader["CityID"].ToString()));
}
myReader.Close();
return myList.ToArray();
}

#region DB Operate
public void Open()
{
if (cn == null)
{
cn = new OleDbConnection(conStr);
cn.Open();
}
}
public void Close() {
if (cn != null)
{
cn.Close();
cn = null;
}
}

public OleDbDataReader GetDr(string strSql) {
Open();
cm = new OleDbCommand(strSql,cn);
myReader = cm.ExecuteReader();
//myReader = cm.ExecuteReader();
return myReader;
}
#endregion DBOperate

}

Note: You should add two tables with the name "tb_State" and "tb_City" into your Database ,which is used in your project , before you using this demo.

Table "tb_State" has two fields with the name "StateID"(primarykey) and "StateName"(Text).

Table "tb_City" has three fields with the name "CityID"(primarykey)、"StateID"(Number) and "CityName"(Text).

VenomZ302:

I'm curious. Do youhave to use a Web Service when trying to pull items for a cascading drop down from a database or is there another (perhaps simpler) way? I'd love to be more enlightened on the subject. Thanks in advance.

We are not limited to use Web Service. Sometimes, we may add the implement code into our *.cs file directly. Here is the sample:

using System;using System.Web.Services;using AjaxControlToolkit;public partialclass CascadingDropDown_CascadingDropDown : CommonPage{protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) {// Get selected values } [WebMethod] [System.Web.Script.Services.ScriptMethod]public static CascadingDropDownNameValue[] GetDropDownContentsPageMethod(string knownCategoryValues,string category) {
 //obtain data from Database.
 return;
 }}
Note: We needn't to set the ServicePath property for the control in this case. Just like below.
<ajaxToolkit:CascadingDropDown ID="CascadingDropDown2" runat="server" TargetControlID="DropDownList2"
Category="Model" PromptText="Please select a model" LoadingText="[Loading models...]"
ServiceMethod="GetDropDownContentsPageMethod" ParentControlID="DropDownList1" />
Details please dip into the Ajax ControlToolkit source code.

If I misunderstood you, please let me know.


Thanks for the information. I really appreciate it. Now, however, I've progressed to the point where I need to understand more of the error codes that are given. Most specifically, error 12030, as found in my thread here: http://forums.asp.net/t/1138732.aspx

Thanks again.


Hi Venom,

Error code: 12030

ERROR_INTERNET_CONNECTION_ABORTED
The connection with the server has been terminated.

In your case, it seems like your webservice doesn't work properly.I suggest that you should add break points into your webservice and debug step-by-step.

Note: If you made some modifications in your webservice and before you debug , please reset your aplication by saving your web.config file.Good luck! Big Smile

Questions about bindings, tables, listviews...

I have a web service with a method, for example, GetCities, returns an array of cities. I want to bind it to a grid-like structure, the first column being the city name and the second a delete button. Then I want to implement the delete button that deletes the city and refreshes the list. All that within an .ascx control - I want to be able to place multiple of these on the same page.

I struggled with this with Atlas - it doesn't seem like a listview is the right way to go for this and I am not sure how to get the delete button to invoke some method to delete a row.

Anyone has a working example of something like this end-to-end?

Thx
dB.

A listview is appropriate for that. Check out this post (which uses server controls, but that'll give you the general idea).http://forums.asp.net/1123018/ShowPost.aspx