Salut à tous,
Je suis en train de développer une application web et je rencontre un problème pour modifier les valeurs de certains éléments de ma Master Page, à savoir: un label et un lien.
J'ai tout d'abord écrit le code suivant:
J'ai rencontré cette erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 if ((bool)Session["in_out"] == true) { ((Label)Page.Master.FindControl("lb_login_info")).Text = string.Concat("You are connected into ", Session["user"].ToString()); ((HyperLink)Page.Master.FindControl("link_login_logout")).Text = "[ Log out ]"; ((HyperLink)Page.Master.FindControl("link_login_logout")).NavigateUrl = "/Account/Login.aspx"; } else { ((Label)Page.Master.FindControl("lb_login_info")).Text = ""; ((HyperLink)Page.Master.FindControl("link_login_logout")).Text = "[ Login ]"; ((HyperLink)Page.Master.FindControl("link_login_logout")).NavigateUrl = "/Account/Login.aspx"; }
J'ai alors modifié en:Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 46: if ((bool)Session["in_out"] == true)
Line 47: {
Line 48: ((Label)Page.Master.FindControl("lb_login_info")).Text = string.Concat("You are connected into ", Session["user"].ToString());
Line 49: ((HyperLink)Page.Master.FindControl("link_login_logout")).Text = "[ Log out ]";
Line 50: ((HyperLink)Page.Master.FindControl("link_login_logout")).NavigateUrl = "/Account/Login.aspx";
Source File: C:\Users\m.pilard\Documents\Visual Studio 2010\Projects\Database Web Administrator\Database Web Administrator\Default.aspx.cs Line: 48
Et j'ai rencontré cette erreur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 Label lb_login_info = new Label(); HyperLink link_login_logout = new HyperLink(); lb_login_info = (Label)Page.Master.FindControl("lb_login_info"); link_login_logout = (HyperLink)Page.Master.FindControl("link_login_logout"); if ((bool)Session["in_out"] == true) { lb_login_info.Text = string.Concat("You are connected into ", Session["user"].ToString()); link_login_logout.Text = "[ Log out ]"; link_login_logout.NavigateUrl = "/Account/Login.aspx"; } else { lb_login_info.Text = ""; link_login_logout.Text = "[ Login ]"; link_login_logout.NavigateUrl = "/Account/Login.aspx"; }
Quelqu'un saurait d'où viens mon problème?Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 51: if ((bool)Session["in_out"] == true)
Line 52: {
Line 53: lb_login_info.Text = string.Concat("You are connected into ", "test");
Line 54: link_login_logout.Text = "[ Log out ]";
Line 55: link_login_logout.NavigateUrl = "/Account/Login.aspx";
Source File: C:\Users\m.pilard\Documents\Visual Studio 2010\Projects\Database Web Administrator\Database Web Administrator\Default.aspx.cs Line: 53
Merci d'avance.
Partager