0

I'm building an web application. I have a Sample.aspx file which I have asp controllers, asp grid view and etc. I want to add to this design but when I add it I can't get it to the code behind.

eg: String val = date.value;

When I do this in the code behind it gives an error saying "date does no exist in current context".

I tried deleting designer.aspx, adding "runat = server" but still couldn't find a proper solution. Can some one please help me with this?

Edit:

This is my html controller where I add to the asp form. I need to get the date from user.

 <input type="date" id="date" runat="server" value=""/>

I use this on a jquery popup so if I use a asp:calendar, when a date is clicked jquery popup will be closed on the post back.

This is the asp back end code where I try to get the error saying....

Error 7 The name 'date' does not exist in the current context E:\IncidentManagement\WebUI\IncidentMain\IncidentMaster.aspx.cs 77 69 WebUI

incidentTXNMaster.IncidentDate = Convert.ToDateTime(date.value);
3
  • 1
    Put your example code here... Commented May 3, 2017 at 11:51
  • What is date? The error is indicating that it has no idea what the variable date is. Commented May 3, 2017 at 11:53
  • Example added guys :) Commented May 4, 2017 at 3:34

2 Answers 2

0

The problem can be seen from the error message. date is being treated as a variable which has not been declared or initialised. Perhaps what you meant was

string val = DateTime.Now.ToString();
Sign up to request clarification or add additional context in comments.

3 Comments

This should be question... Since you are not sure if that is what the OP wants
The question is implied by "perhaps what you meant was"
Yes that's what I mean. You are asking a question.
0

doesn't exist in current context means that you are trying to use something that not initially declared.

so in your case, you are trying to use date but you have not declared it yet.

change this

<input type="date" id="date" runat="server" value=""/>

to

<input type="date" id="txtdate" name="date" runat="server" value=""/>

and then get value

string val = Request.Form["date"];

or using

string val = txtdate.Value;

1 Comment

It's not the solution for my problem. Thanks anyways :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.