| | |
Problem with asp.net calender control
Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Hi all,
I am new to asp.net programming and i am using asp.net calender control
the code tht i am using is
I am using the following code at calender selection changed event
I am getting the problem at Calender2.visible= true
as an exception like use new keyword at Calender2 but i have declared tht control earlier
any help is greatly appreciated.
thanks in advance.
I am new to asp.net programming and i am using asp.net calender control
the code tht i am using is
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btn_dob_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_dob.Click Try If (txt_dob.Text.Trim() IsNot DBNull.Value) Then Calender2.SelectedDate = Convert.ToDateTime(txt_dob.Text) End If Catch ex As Exception End Try Calender2.Visible = True End Sub
I am using the following code at calender selection changed event
ASP.NET Syntax (Toggle Plain Text)
txt_dob.Text = Calender2.SelectedDate.ToString() Calender2.Visible = False
as an exception like use new keyword at Calender2 but i have declared tht control earlier
any help is greatly appreciated.
thanks in advance.
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 1
As long as you have the calendar control in place you shouldn't need to declare it. Daft question, are you using the same spelling; reason for asking is that you have called it calender2, but the correct spelling would be calendar2. A common mistake is to allow Visual Web Developer (or whatever tool you are using) assign a name, and then you mis-spell it (I daren't count the hours I have spent looking for an error only to find its a typo!)
This code works (obviously don't know whether it is at all what you are wanting to do, but does demonstrate a working framework):
One other thing: I notice that you are using . This will also put the time in. Using would avoid this.
One final hint: you may have done this elsewhere, but you have not put an error trap for a value that isn't a valid date. Try :
This code works (obviously don't know whether it is at all what you are wanting to do, but does demonstrate a working framework):
ASP.NET Syntax (Toggle Plain Text)
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub btn_dob_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_dob.Click Try If (txt_dob.Text.Trim() IsNot DBNull.Value) Then Calender2.SelectedDate = Convert.ToDateTime(txt_dob.Text) End If Catch ex As Exception End Try Calender2.Visible = True End Sub Protected Sub calendar_changed(ByVal sender As Object, ByVal e As System.EventArgs) txt_dob.Text = DateTime.Parse(Calender2.SelectedDate).ToString("dd/MM/yy") Calender2.Visible = False End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txt_dob" runat="server"></asp:TextBox> <asp:Button ID="btn_dob" runat="server" Text="Button" OnClick="btn_dob_click" /> <asp:Calendar ID="Calender2" runat="server" OnSelectionChanged="calendar_changed"></asp:Calendar> </div> </form> </body> </html>
One other thing: I notice that you are using
ASP.NET Syntax (Toggle Plain Text)
Calender2.SelectedDate.ToString()
ASP.NET Syntax (Toggle Plain Text)
datetime.parse(Calendar2.selecteddate).ToString("dd/MM/yy")
One final hint: you may have done this elsewhere, but you have not put an error trap for a value that isn't a valid date. Try :
ASP.NET Syntax (Toggle Plain Text)
IsDate(txt_dob.text)
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Hi JD,
I am very thankful to you since u have resolved my doubt of how to omit the time from the captured value of date time picker..
Thanks alot once again...
Also i have a doubt regarding saving the form values into a database on a button click event but i was unable to do tht cud u please help me out with this query?
its very urgent bcos if iam unable to complete this by today i have a problem with my job...
So please help me out no ..
Thanks in advance...
Karthik..
I am very thankful to you since u have resolved my doubt of how to omit the time from the captured value of date time picker..
Thanks alot once again...
Also i have a doubt regarding saving the form values into a database on a button click event but i was unable to do tht cud u please help me out with this query?
its very urgent bcos if iam unable to complete this by today i have a problem with my job...
So please help me out no ..
Thanks in advance...
Karthik..
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 1
At the top of your aspx web page you need to declare the data controls you are using and this depends on the database, to some extent, ie MS SQL, MySQL or Access.
As an example, to save to Access you would add:
Create the function to respond to the button click and declare variables. One way to create a data connection would be:
if you are using an SQL database the commands are slightly different but gives you an idea of the structure to get you started. A google search will reveal loads of sites that offer tutorials in data integration with asp.net.
However, if you are using an sql server, asp.net should be able to do most of the coding for you. I have found using the automated data functions in asp.net unreliable to access Access.
As an example, to save to Access you would add:
ASP.NET Syntax (Toggle Plain Text)
<%@import Namespace="system.data" %> <%@import Namespace="system.data.oledb" %>
Create the function to respond to the button click and declare variables. One way to create a data connection would be:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'set up variables
'Open Data Connection
Dim connection As OleDbConnection
Dim command As OleDb.OleDbCommand
Dim query As String
connection = New OleDb.OleDbConnection("provider=microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("insert database name"))
connection.Open()
' create SQL query
query = "INSERT INTO table_name (field_name1, field_name2 etc) VALUES([I]value1[I], value2 etc etc)"
command = New OleDbCommand(query, connection)
Try
command.ExecuteNonQuery()
Catch ex As Exception
errorchk2 = True
errorlabel.Text = ex.Message + " " + query
End Try
'Close Data Connection
connection.Close()
connection = Nothingif you are using an SQL database the commands are slightly different but gives you an idea of the structure to get you started. A google search will reveal loads of sites that offer tutorials in data integration with asp.net.
However, if you are using an sql server, asp.net should be able to do most of the coding for you. I have found using the automated data functions in asp.net unreliable to access Access.
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click myConnection = New SqlConnection("Data Source=.\Sqlexpress;Initial Catalog=HRDATA;Integrated Security=True") myConnection.Open() myCommand = New SqlCommand("Insert into Employee Data values(ddl_id.SelectedItem ,'" & txt_name.Text & "','" & txt_emerno.Text & "','" & txt_contnum.Text & "','" & txt_email.Text & "','" & txt_persemail.Text & "'),myConnection") 'myCommand = New SqlCommand("Insert into Employee values('"& txt_name.Text & "')","myConnection") ra = myCommand.ExecuteNonQuery() 'MsgBox.Show("New Row Inserted" & ra) myConnection.Close() End Sub
Here is my code for submit button but i am getting the error as
ExecuteNonQuery: Connection property has not been initialized.
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.
can anyone please help me i have also declared the variables tht i have used in this code
Thanks In advance..
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
ASP.NET Syntax (Toggle Plain Text)
Protected Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click myConnection = New SqlConnection("Data Source=.\Sqlexpress;Initial Catalog=HRDATA;Integrated Security=True") myConnection.Open() myCommand = New SqlCommand("Insert into Employee Data values(ddl_id.SelectedItem ,'" & txt_name.Text & "','" & txt_emerno.Text & "','" & txt_contnum.Text & "','" & txt_email.Text & "','" & txt_persemail.Text & "'),myConnection") 'myCommand = New SqlCommand("Insert into Employee values('"& txt_name.Text & "')","myConnection") ra = myCommand.ExecuteNonQuery() 'MsgBox.Show("New Row Inserted" & ra) myConnection.Close() End Sub
Here is my code for submit button but i am getting the error as
ExecuteNonQuery: Connection property has not been initialized.
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.
can anyone please help me i have also declared the variables tht i have used in this code
Thanks In advance..
•
•
Join Date: Dec 2008
Posts: 5
Reputation:
Solved Threads: 1
Have you declared your variables because can't see the declarations in the code you have given
I don't think strictly necessary I find very helpful for debugging by adding the fields you are inserting into in the query string (eg INSERT INTO employeedata (firstname,lastname) VALUES (value1, value2) )
Again for simplicity of debugging and to allow easy cutting and pasting of code, I prefer to create a separate string for the querystring rather than include the whole string in the command. I simply call it query. Eg query="INSERT INTO employeedata (firstname,lastname) VALUES (value1, value2)"
Most obvious problem to me though is the command itself and your use of "
You have written:
Note the double apostrophe around myconnection. Should be
Similarly, the other version would be:
HOpe that helps
I don't think strictly necessary I find very helpful for debugging by adding the fields you are inserting into in the query string (eg INSERT INTO employeedata (firstname,lastname) VALUES (value1, value2) )
Again for simplicity of debugging and to allow easy cutting and pasting of code, I prefer to create a separate string for the querystring rather than include the whole string in the command. I simply call it query. Eg query="INSERT INTO employeedata (firstname,lastname) VALUES (value1, value2)"
Most obvious problem to me though is the command itself and your use of "
You have written:
myCommand = New SqlCommand("Insert into Employee values('"& txt_name.Text & "')", "myConnection" )Note the double apostrophe around myconnection. Should be
myCommand = New SqlCommand("Insert into Employee values('"& txt_name.Text & "')", myConnection )Similarly, the other version would be:
ASP.NET Syntax (Toggle Plain Text)
myCommand = New SqlCommand("Insert into Employee Data values(ddl_id.SelectedItem ,'" & txt_name.Text & "','" & txt_emerno.Text & "','" & txt_contnum.Text & "','" & txt_email.Text & "','" & txt_persemail.Text & "')",myConnection)
HOpe that helps
Last edited by jdharness; Dec 19th, 2008 at 2:03 pm. Reason: Missing [ before COLOR
•
•
Join Date: Dec 2008
Posts: 37
Reputation:
Solved Threads: 0
Hi Jd,
I have a new requirement for displaying the calendar control as 3 comboboxes for date, month and year so that if the user selects the date then the complete date is to be captured like we see in lots of websites.
How can we do that any suggestion or any tutorial link is greatly appreciated...
Looking forward for your reply thanks in advance,
Karthik.
I have a new requirement for displaying the calendar control as 3 comboboxes for date, month and year so that if the user selects the date then the complete date is to be captured like we see in lots of websites.
How can we do that any suggestion or any tutorial link is greatly appreciated...
Looking forward for your reply thanks in advance,
Karthik.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Dynamic checkbox checked status
- Next Thread: Ebooks
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax asp asp.net bc30451 beginner bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child class click commonfunctions compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datagridviewcheckbox datalist deadlock deployment development dgv dropdownmenu dynamic edit embeddingactivexcontrol expose feedback findcontrol flash flv form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery list menu mono mssql multistepregistration nameisnotdeclared novell objects order problem ratings rotatepage save search security serializesmo.table silverlight smartcard sql sqlserver2005 ssl suse textbox tracking treeview typeof unauthorized validation vb.net video virtualdirectory vista visual-studio visualstudio vs2008 web webarchitecture webdevelopemnt webdevelopment wizard xml youareanotmemberofthedebuggerusers





