Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Saturday, March 24, 2012

ASP.NET 2 - AJAX control toolkit autocomplete

hi

how can i do to have a session variable ( like for example session("name") ) to web site ( asp.net 2) in a class of control toolkit autocomplete.

with the use of this instructions in the class vb autocomplete :

Dim session As System.Web.SessionState.HttpSessionState

session = System.Web.HttpContext.Current.Session

the 'session' variable is nothing

thanks to attention

Hi Robby,

My understanding of your issue is that use session your WebService which is associated with a AutuCompleteExtender. If I have misunderstood, please feel free to let me know.

Based on this knowledge, here is a sample which is written by Jeffrey Zhao. I found it on MS WebCast. This sample is not use AutuCompleteExtender but they are similar. You can do some changes on your source code.

<%@. WebService Language="C#" Class="EnableSessionService" %>using System;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;using System.Web.Script.Services;using System.Web.SessionState;[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][ScriptService]public class EnableSessionService : System.Web.Services.WebService{ [WebMethod(true)] public int AddOne(){HttpSessionState session = HttpContext.Current.Session;object objValue = session["value"];int value = objValue == null ? 0 : (int)objValue;value++;session["value"] = value;return value; } }
Aspx page:
 
<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Enable Session</title></head><body> <form id="form1" runat="server"><asp:ScriptManager runat="server" ID="ScriptManager1" ScriptMode="Debug"><Services><asp:ServiceReference Path="Services/EnableSessionService.asmx" InlineScript="true" /></Services></asp:ScriptManager> <input type="button" value="Add One" onclick="addOne()" /><script language="javascript" type="text/javascript">function addOne(){EnableSessionService.AddOne(onSucceeded);}function onSucceeded(result){alert(result);}</script> </form></body></html>

Please pay attention to the "Bold" part. Hope this help.

Best regards,

Joanthan


Hi Joanthan

thanks to your advice, it's that i had necessity.

in my code i haven't put TRUE in[WebMethod(true)]

now is working

thanks

Wednesday, March 21, 2012

array of class object to web service

Hi

I'm able to work with class objects on the client and i want to send the array of class objects to the web service as parameter. Somehow i'm not able to get it work.. What should be the parameter declaration on the web service. can someone post the sample for this?

Thank You

Subba

this should work. Can past your code. i will take a look


Hi Raghu, here is my code snippets. Let me know if you need any more information.

Question is my class object and added the addtribute<GenerateScriptType(GetType(Question))>on the web service.

<WebMethod()> _

PublicFunction BuildQuestions(ByVal questionsTobeBuiltAs List(Of Question))AsString

Dim queryStringAsString =String.Empty

For Each item As Question In questionsTobeBuilt

queryString = queryString & item.Content

Next

ReturnqueryString

EndFunction

on the client i'm adding the data in this way:

this._questions = new Object();

this._questions[data.Id] = {Question: data};

and my webservice call from client:

ASPNETFuturesDragDrop.QuestionareService.BuildQuestions(questonsToBeSubmitted, onBuilded);

//display the server-side response to the customer

function onBuilded(result) {

//Sys.Preview.UI.Window.messageBox(result,Sys.Preview.UI.MessageBoxStyle.OK);

OutputMsg.innerHTML=result;

}


go through this forum, they discuss the same problem you are having. It is by design. Change your web method that takes array of your class instead of Generic List.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=90536&SiteID=1


Thanks for the link. i even tried with array of objects, Question() as parameter for the web service. that gives me an error 'System.MissingMethodException -- No parameterless constructor defined for type Question[]'. I donno where do i need to declared the constructor for an arrya of objects..


Mark Your WebService/WebMethod with the GenerateScriptType Atttribute with the Server Side Class then in the client Create a Array Like the following:

var q1 = new Question();
var q2 = new Question();
var q3 = new Question();
var q4 = new Question();

//Code to set the properties of the above questions

var questions = new Array();

questions.push(q1):
questions.push(q2):
questions.push(q3):
questions.push(q4):

//Then Call the WS with the array.

WS.SomeMethod(questions, successHandler);