哪个事件对会话的变量有价值? [英] Which event takes value the session's variables?
本文介绍了哪个事件对会话的变量有价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在转发器控件的ItemDataBound事件中调用一个使用用户会话值的对象,但是我得到错误,似乎无法创建对象,并且当我在后续事件中使用同一个对象时在加载时,我没有问题,我需要知道何时开始会话的变量存在?
代码是如下:
I'm invoking in the ItemDataBound event of repeater control an object that uses the value of the user's session, but I get error, it seems that the object can not to be created and when I use this same object in subsequent events at load, I haven't problem, I need to know when to start the session's variables at exist?.
the code is the follow:
protected void repDias_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DateTime date = (DateTime)e.Item.DataItem;
Literal litDia = (Literal)e.Item.FindControl("litDia");
HtmlTableCell tdDia = (HtmlTableCell)e.Item.FindControl("tdDia");
int vencidos=0;
int mantenimientos = 0;
string usuarioid;
string clienteid;
if (Session["Usuarioid"] != null)
usuarioid = Session["Usuarioid"].ToString();
if (Session["clienteid"] != null)
clienteid = Session["clienteid"].ToString();
lstFechaMantenimiento.DataSource = _m.obtenerTodos("", "",usuarioid, "", clienteid);
lstFechaMantenimiento.DataTextField = "sigrev";
lstFechaMantenimiento.DataValueField = "id";
lstFechaMantenimiento.DataBind();
DateTime dt= new DateTime();
DateTime dthoy = new DateTime();
DateTime dtfecha = new DateTime();
dt=DateTime.Now;
string hoy = string.Format("{2}-{1}-{0}", dt.Year, dt.Month.ToString("D2"), dt.Day.ToString("D2"));
dthoy = Convert.ToDateTime(hoy);
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
tdDia.Attributes.Add("class", "weekend");
if (_actualMes == date.Month)
{
litDia.Text = string.Format("<a href=\"{0}?CalDate={3}-{2}-{1}\"{4}>{3}</a>", Request.Path, date.Year, date.Month.ToString("D2"), date.Day.ToString("D2"), (_specialDaySelected && date.Equals(_selectedDate)) ? " class=\"selected\"" : string.Empty);
fechamantenimiento = string.Format("{2}-{1}-{0}", date.Year, date.Month.ToString("D2"), date.Day.ToString("D2"));
dtfecha = Convert.ToDateTime(fechamantenimiento);
for (int i = 0; i < lstFechaMantenimiento.Items.Count; i++)
{
if (dthoy <= dtfecha)
{
if (fechamantenimiento == lstFechaMantenimiento.Items[i].Text)
{ mantenimientos = mantenimientos + 1; }
}
else
{
if (fechamantenimiento == lstFechaMantenimiento.Items[i].Text)
{ vencidos = vencidos + 1; }
}
}
if (mantenimientos > 0)
tdDia.Attributes.Add("class", "fechamantenimiento");
if (vencidos > 0)
tdDia.Attributes.Add("class", "vencido");
}
else
litDia.Text = string.Format("<span>{0}</span>", date.Day.ToString("D2"));
tdDia.ID = string.Empty;
}
}
请有人帮我。
提前。
Please, someone could help me.
thans in advance.
推荐答案
使用System.Web.HttpContext.Current.Session
类来读取会话变量。
例如var param = System.Web.HttpContext.Current.Session [loginParameters]。
Use theSystem.Web.HttpContext.Current.Session
class to read session variables.
For e.g.var param = System.Web.HttpContext.Current.Session["loginParameters"].
这篇关于哪个事件对会话的变量有价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文