Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Monday, March 26, 2012

Asp.net Ajax Accordion SelectedIndex Event

Hello. Im trying to catch the selected index property of an accordion control and then store it into a session variable that I can then load later on in my application. Anyone have any suggestions on how to make this happen...Thanks in advance.

Here you go. On postback, just grab the value of the textbox and assign it to a session variable. Some of the javascript is for dealing with finding form objects when using a master file.

/*** Code Behind ***/
for (int i = 0; i < YourAccordionName.Panes.Count; i++)
{
YourAccordionName.Panes[i].HeaderContainer.Attributes.Add("onclick", "AssignIndex(" + i.ToString() + ")");
}

/*** Source View ***/
<asp:TextBox
ID="txtAccordionSelectedIndex"
runat="server"
style="background-color:#FFFFFF; color:#FFFFFF; border:solid 0px #FFFFFF"
Text="-1" />

<script language="JavaScript">
<!--
function AssignIndex(val)
{
document.forms[0].<%= txtAccordionSelectedIndex.UniqueID%>.value = val;
}
//-->
</script>

Hope that helps.

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