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

No comments:

Post a Comment