How to excess value in .Aspx page in ASP.NetPriyanka Singh6yAsked Feb 6, 2020, 12:06 AM ESTSolvedShareLinkedInXCopy linkSaveI have code in .cs pagevar startDate = new DateTime(now.Year, now.Month, 1); ar endDate = startDate.AddMonths(1).AddDays(-1); How to excess these two values in .aspx page.As I am using <%=startDate %> But it gives an error that name does not exist in the current context. What to do??
How to excess value in .Aspx page in ASP.NetPriyanka Singh6yAsked Feb 6, 2020, 12:06 AM ESTSolvedShareLinkedInXCopy linkSaveI have code in .cs pagevar startDate = new DateTime(now.Year, now.Month, 1); ar endDate = startDate.AddMonths(1).AddDays(-1); How to excess these two values in .aspx page.As I am using <%=startDate %> But it gives an error that name does not exist in the current context. What to do??
Joginder BangerRank #360 · 7K reputation6y agoPosted Feb 6, 2020, 1:18 AM EST✓ Accepted answer+1 <%= dateTime %> <%= Endtime %> CS side code public partial class _Default : Page { protected DateTime dateTime; protected DateTime Endtime; protected void Page_Load(object sender, EventArgs e) { dateTime = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 1); Endtime = dateTime.AddMonths(1).AddDays(-1); } } You have getting error because your veriable is private. +1GUGuest UserRank #816 · 2.8K reputation6y agoPosted Feb 6, 2020, 12:29 AM EST+1I guess you are using local variables. You need to use class variables instead.+1Priyanka SinghRank #1,215 · 1.5K reputation6y agoPosted Feb 6, 2020, 5:46 PM EST+1Hello Joginder BangerThanks for your help!!It works for me.+1Priyanka SinghRank #1,215 · 1.5K reputation6y agoPosted Feb 6, 2020, 12:41 AM EST0how I make these two variable as class variable.0Vrushali GhodkeRank #1,495 · 1.1K reputation6y agoPosted Feb 6, 2020, 12:54 AM EST-1Hi Priyanka,var startDate = new DateTime(now.Year, now.Month, 1); ar endDate = startDate.AddMonths(1).AddDays(-1); did you try to bind these values with the label? Like below exampleDateTime startDate = new DateTime(now.Year, now.Month, 1); DateTime endDate = startDate.AddMonths(1).AddDays(-1); label1.Text = Convert.ToString(startDate); label2.Text = Convert.ToString(endDate); -1Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
GUGuest UserRank #816 · 2.8K reputation6y agoPosted Feb 6, 2020, 12:29 AM EST+1I guess you are using local variables. You need to use class variables instead.+1
Priyanka SinghRank #1,215 · 1.5K reputation6y agoPosted Feb 6, 2020, 5:46 PM EST+1Hello Joginder BangerThanks for your help!!It works for me.+1
Priyanka SinghRank #1,215 · 1.5K reputation6y agoPosted Feb 6, 2020, 12:41 AM EST0how I make these two variable as class variable.0
Vrushali GhodkeRank #1,495 · 1.1K reputation6y agoPosted Feb 6, 2020, 12:54 AM EST-1Hi Priyanka,var startDate = new DateTime(now.Year, now.Month, 1); ar endDate = startDate.AddMonths(1).AddDays(-1); did you try to bind these values with the label? Like below exampleDateTime startDate = new DateTime(now.Year, now.Month, 1); DateTime endDate = startDate.AddMonths(1).AddDays(-1); label1.Text = Convert.ToString(startDate); label2.Text = Convert.ToString(endDate); -1
Joginder BangerRank #360 · 7K reputationPosted Feb 6, 2020, 1:18 AM EST
Guest UserRank #816 · 2.8K reputationPosted Feb 6, 2020, 12:29 AM EST
Priyanka SinghRank #1,215 · 1.5K reputationPosted Feb 6, 2020, 5:46 PM EST
Joginder Banger
Priyanka SinghRank #1,215 · 1.5K reputationPosted Feb 6, 2020, 12:41 AM EST
Vrushali GhodkeRank #1,495 · 1.1K reputationPosted Feb 6, 2020, 12:54 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts