Showing posts with label call. Show all posts
Showing posts with label call. Show all posts

Wednesday, March 28, 2012

Programmatically Select a listview item

Can't seem to figure out how to do this. The listview class browser doesn't list much in the way of an API call to do this. Anyone know if this is possible?Did you figure this out?

ListView.SelectedListViewItemCollection listViewItemCollection = this.ListView1.SelectedItems;

foreach ( ListViewItem item in listViewItemCollection)
{
//Your code goes here
}


ListView1.Items(0).Selected = True
ListView1.Select()

The first line indicates what item is to be selected, and the second line is what actually selects it. The most common mistake is leaving out the second line.

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.

Saturday, March 24, 2012

Question about generated proxies

I'm looking at the following example where all of the functions calling web services use a common call back function.

http://www.asp.net/AJAX/Documentation/Live/ViewSample.aspx?sref=Sys.Net.WebServiceGenerics/cs/generics.js

I can see how organization might be a little better using the call back function and a switch statement, but are there performance benefits? Which would have better performance, individual call back functions or the all in one version? Are there any other benefits or detriments between the two?

thanks

Nick

There is no performance benifits in using a common callback. You can use the Common Callback when you have to process similar kind of logic for more than one web service call result.

Wednesday, March 21, 2012

question on Ajax and .NET method

hi all,

is it possible to pass a javascript object (which has key value pairs) to a C# method through an Ajax call.

if yes,

can you please give me some sample code on how to refer to those key values in C# method?

Thanks in advaance

Sanjay

Using AJAX, you are making a call to the server. Your key value pair in Javascript is serialized in to string with some dilimeter when sent to the server right?

I guess, you just need to parse the string on the server!


thanks for the reply

the key value pair is not serialized into a string. it is a javascript object [like myObj[id] = 1; myObj[name] = 'test'....]

and i'm using Ajax to make a call to C# method [which does some sql] and

i need to pass the javascript object [myObj] to C# method and parse the object and use the values in sql

can you please give me some simple sample code for this

thank you

Sanjay


Hi sanjayk,

It is possible. Here is a sample shows how to pass a javascript object to a C# method through a button click event. For using Ajax call , you should do very little change.

ASPX:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="JSON.aspx.cs" Inherits="ClientScript_JSON" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>JSON Test</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> Display client serialize result:<asp:TextBox ID="TextBox1" runat="server" Text="5555" Style=""></asp:TextBox><br /> <br /> <asp:Label ID="Label1" runat="server" Text="Show FirstName here"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> </form> <script type="text/javascript" language="javascript"> function pageLoad(){ var myObj = new Object(); myObj.FirstName = "Jonathan"; myObj.LastName = "Shen"; myObj.Title ="MSTF"; var serialiedObj = Sys.Serialization.JavaScriptSerializer.serialize(myObj); $get("<%=TextBox1.ClientID%>").value = serialiedObj; } </script></body></html>

C# Code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Script.Serialization;

public partial class ClientScript_JSON : System.Web.UI.Page
{
JavaScriptSerializer serializer;

protected void Page_Load(object sender, EventArgs e)
{
serializer = new JavaScriptSerializer();
}
protected void Button1_Click(object sender, EventArgs e)
{
string jsonstring = Page.Request.Params["TextBox1"].ToString();
Dictionary<string, string> temp = serializer.Deserialize<Dictionary<string,string>>(jsonstring);
this.Label1.Text ="FirstName: "+temp["FirstName"].ToString();
}
}

For more details , please visit this url: http://ajax.asp.net/docs/ViewSample.aspx?sref=System.Web.Script.Serialization/cs/App_Code/ListItemCollectionConverter.cs

Hope it helps. If i misunderstood you, please let me know.


Hi Jonathan,

Thank you for your reply, i figured it out by passing Complex DataTypes to C# methods.

Sanjay