CS1501: No overload for method 'ToShortDateString' takes '1' arguments

Hello,

 I'm quite new in ASP.NET. I'm developing a website for my company where people can request a reservation. Therefor I made a form where there is a Calendar where they can pick a date for their reservation-request. I'd like to make all the dates 'till "today+1" unselectable. I didn't found a way to do this so I use a CompareValidator to check whether the day they selected is "greater than today". Unfortunately I get this errormessage "CS1501: No overload for method 'ToShortDateString' takes '1' arguments" while it is a solution I found on the web. Can someone please help me. Thanks.

This is my coding:

<

script language="C#" runat="server">

void Restaurant_Reservation_SqlDataSource_OnInserted(Object sender,

SqlDataSourceStatusEventArgs

e)

{

System.Data.Common.

DbCommand command = e.Command;

Restaurant_Reservation_FormView.DataBind();

}

protected void Calendar1_SelectionChanged(object sender, EventArgs e)

{

TextBox ReservationDateTextBox = (TextBox)Restaurant_Reservation_FormView.FindControl("ReservationDateTextbox");

Calendar Calendar1 = (Calendar)((Control)sender).FindControl("Calendar1");

ReservationDateTextBox.Text = Calendar1.SelectedDate.ToShortDateString();

CompareValidator DateCompare = (CompareValidator)((Control)sender).FindControl("DateCompare");

DateCompare.ControlToCompare =

DateTime.Now.ToShortDateString(("MM\\/dd\\/yyyy")); ==> compiler gives me an error on this line.

DateCompare.Operator =

ValidationCompareOperator.GreaterThan;

DateCompare.Type =

ValidationDataType.Date;

}

</

script>

<tr><td align="left" valign="top"><b>Reservation Date:</b></td>

<td><asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" Width="200px" SelectedDate = '<%# Bind("ReservationDate") %>' OnSelectionChanged="Calendar1_SelectionChanged" ></asp:Calendar>

</td><td>

<asp:CompareValidator id="DateCompare" runat="server" ErrorMessage="Wrong Date" ControlToValidate="Calendar1" Operator="GreaterThanEqual" ></asp:CompareValidator>

<tr><td ></td>

<td><asp:TextBox ID="ReservationDateTextBox"  RunAt="Server" ReadOnly="true" /></td></tr>

 


Eden
0
Edensriver
2/6/2007 8:32:29 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

9 Replies
2490 Views

Similar Articles

[PageSpeed] 4

Hi,

the method ToShortDateString doesn't provide overrides that take arguments. You can however do it like this:

DateTime.Now.ToString("MM/dd/yyyy");

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
2/6/2007 8:57:31 AM
This is not the way to use Asp.net validators. Also your are using Server Side code to validate the date you do not at all need the validators. So far what i understand that You want to ensure the date in the calendar is selected is greater than the current date. In that case you can use the following code:
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
if (Calendar1.SelectedDate < DateTime.Today)
{
Label1.Text = "Wrong Date"; // I assume you have replace the validator with a Label named Label1
}
else
{
ReservationDateTextBox.Text = Calendar1.SelectedDate.ToShortDateString();
}
}


Long Live .NET
Kazi Manzur Rashid (Amit)
_________________________
Web: http //dotnetshoutout.com
Blog: http://weblogs.asp.net/rashid
Twitter: http://twitter.com/manzurrashid
0
KaziManzurRashid
2/6/2007 9:19:18 AM

It doesnt make sense to write all that code to check if a selected date is greater than today. The SelectionChanged event of Calendar control will cause a postback so you can handle your validation in that event or the event in which you actually process the job.

protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
  if (Calendar1.SelectedDate > DateTime.Today)
  {
     Response.Write( "Invalid date selected");
  }
}

// if you want to validate in your button ....
protected void Button1_Click (object sender.....)
{
  if (!(Calendar1.SelectedDate > DateTime.Today))
  { // do your process here}
  else { Response.Write ("Invalid date selected"); }
}

If you want to disable the dates, check this link and two examples show to disable the dates http://www.mattkruse.com/javascript/calendarpopup/index.html

Thanks


Mark post(s) as "Answer" that helped you

Electronic Screw
Website||Blog||Dub@i.net
0
e_screw
2/6/2007 10:20:44 AM

Thanks for your reply Kris.

But now I get this errormessage: System.Web.HttpException: Control 'Calendar1' referenced by the ControlToValidate property of 'DateCompare' cannot be validated. :(


Eden
0
Edensriver
2/6/2007 10:48:16 AM
Remove the Validator from your page as you do not need it anymore.
Long Live .NET
Kazi Manzur Rashid (Amit)
_________________________
Web: http //dotnetshoutout.com
Blog: http://weblogs.asp.net/rashid
Twitter: http://twitter.com/manzurrashid
0
KaziManzurRashid
2/6/2007 10:55:46 AM

Hi,

 Thanks, the validation works fine. Is there any possibility to deselect dates anything up to today, in the asp:calendar form (without using javascripting)?


Eden
0
Edensriver
2/6/2007 11:15:27 AM

Hi,

you can override the OnDayRender event of the calendar and set the Cell's text of a date before the current day, to String.Empty.

Grz, Kris.


Read my blog. Handy Firefox plugins for web developers.


Workaround for non working Mark as answer buttons.
0
XIII
2/6/2007 11:30:26 AM

Thanks a lot to you all to help me out. Here the final code for the ones struggling with the same problem.

<script language="C#" runat="server">

// to put any day up to today "Not-selectable/Not visible"

  protected void Calendar1_Check(object sender, DayRenderEventArgs e)
  {
    Calendar Calendar1 = (Calendar)((Control)sender).FindControl("Calendar1");
    CalendarDay d = ((DayRenderEventArgs)e).Day;
    TableCell c = ((DayRenderEventArgs)e).Cell;
   
    if (d.Date < DateTime.Today)
    {
      c.Text = String.Empty;
    }
   
  }

  protected void Calendar1_SelectionChanged(object sender, EventArgs e)
  {
    TextBox ReservationDateTextBox = (TextBox)Restaurant_Reservation_FormView.FindControl("ReservationDateTextbox");
    Calendar Calendar1 = (Calendar)((Control)sender).FindControl("Calendar1");

// To validate the selected date and put a customized errormessage in a textbox-control
// Not needed if previous OnDayRender-event is used

    if (Calendar1.SelectedDate < DateTime.Today)
    {
      ReservationDateTextBox.Text = "Invalid date selected";
    }
    else
    {
      ReservationDateTextBox.Text = Calendar1.SelectedDate.ToShortDateString();
    }
  }
</script>

<table>
     <tr><td align="left" valign="top"><b>Reservation Date:</b></td>
         <td><asp:Calendar ID="Calendar1" runat="server"
                           BackColor="White" BorderColor="#999999"
                           CellPadding="4" DayNameFormat="Shortest"
                           Font-Names="Verdana" Font-Size="8pt"
                           ForeColor="Black"
                           Height="180px" Width="200px"
                           OnSelectionChanged="Calendar1_SelectionChanged"
                           OnDayRender = "Calendar1_Check"
                           >
             <SelectedDayStyle BackColor="#666666" Font-Bold="True"
                               ForeColor="White" />
             <TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />
             <SelectorStyle BackColor="#CCCCCC" />
             <WeekendDayStyle BackColor="#FFFFCC" />
             <OtherMonthDayStyle ForeColor="Gray" />
             <NextPrevStyle VerticalAlign="Bottom" />
             <DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True"
                             Font-Size="7pt" />
             <TitleStyle BackColor="#999999" BorderColor="Black"
                         Font-Bold="True" />
           </asp:Calendar>
         </td>
         <td>
</td></tr>
    <tr><td ></td>
         <td><asp:TextBox  ID="ReservationDateTextBox"
                           Text=""
                           RunAt="Server"
                           ReadOnly="true" /></td></tr>
</table>


Eden
0
Edensriver
2/6/2007 12:42:00 PM

Little update:

protected void Calendar1_Check(object sender, DayRenderEventArgs e)

{

CalendarDay d = ((DayRenderEventArgs)e).Day;

TableCell c = ((DayRenderEventArgs)e).Cell;

 

if (d.Date < DateTime.Today)

{ c.Enabled =

false; }

 

}


Eden
0
Edensriver
2/6/2007 12:49:32 PM
Reply:

Similar Artilces:

what does 'No overload for method 'Insert' takes '1' arguments' mean?
code that caused this error: line AddInBookSqlDataSource2.Insert(item);protected void inbookButton_Click(object sender, EventArgs e){ try{ AddInBookSqlDataSource1.Insert(); }catch (Exception ex){ uploadSPoneLabel.Text = "Saved Failed: SP One" + ex.Message; }foreach (ListItem item in authorsListBox5.Items){ try{ AddInBookSqlDataSource2.Insert(item); saveStatusLabel.Text = "Save Successful: SP Two"; }catch (Exception ex1){saveStatusLabel.Text = "Save Failed: SP Two" + ex1.Message; } } } any help appreciated Thanks in advance At a surface leve...

Web Service
[WebMethod]public DataSet GetDataSetForum2(){DataSet datasource = new DataSet();string database = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/topic.mdb;Persist Security Info=True";string queryStr = "Select * from Comment";OleDbConnection myConn = new OleDbConnection(database);OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(queryStr, myConn);myConn.Open();myDataAdapter.Fill(datasource, "Comment");myConn.Close();return datasource;} localhost.Topic topic = new localhost.Topic(); string topicId = Request.QueryString["TopicID"].To...

Compiler Error Message: CS1501: No overload for method 'ToString' takes '1' arguments
Compiler Error Message: CS1501: No overload for method 'ToString' takes '1' argumentsSource Error: Line 248: //{ Line 249: Line 250: int RollNo = Convert.ToInt32(str.ToString(str.Append(GridView1.Rows[i].Cells[1].Text))); Line 251: Line 252: DeleteStudent(RollNo); Source File: h:\Office Works\Projects\Sample Applications\GridViewVitCode.aspx.cs    Line: 250 Please solve this problem  This is the complete code  protected void Button2_Click(object sender, EventArgs e) {for (int i = 0; i <...

No overload for method 'FormatImagePath' takes '1' arguments
Hi, I am getting the error message above on the code below.  I did not write the code.  I am new to ASP.NET and I had to download Visual Studio 2005 to compile my C# files.  The website was written in a previous version and the error message appeared when I tried compiling after the conversion to ASP.NET 2.0. by Visual Studio.  I don't understand the error message and I am not entirely clear on what the code is doing.  Would anyone be able to help?    <table> <tr><td></td></tr> <tr><...

No overload for method 'FieldValue' takes '1' arguments
Very confused, the recordset returns a record, all is working, but it's just giving me an error?????? anybody knows how to solve this, Compiler Error Message: CS1501: No overload for method 'FieldValue' takes '1' arguments Source Error: Line 19: { Line 20: Line 21: Response.Redirect(ds_redirect.FieldValue("url")); Line 22: } Line 23: ---------------------------- When removing the fieldvalue I receive another error Compiler Error Message: CS0118: 'ASP.frame_redirect_url_aspx.ds_redirect' denotes a 'field' where a 'method' was expected...

No overload for method 'Forum' takes '1' arguments
I am getting this error - No overload for method 'Forum' takes '1' argumentsCan anyone help?I am using a web service created by myself Topic Page<asp:HyperLinkField DataNavigateUrlFormatString="~/topic.aspx?TopicID={0}" NavigateUrl="~/topic.aspx" Text="Comments" DataNavigateUrlFields="TopicID" />Comments Page localhost.Topic topic = new localhost.Topic(); string topicId = Request.QueryString["TopicID"].ToString(); datasource = topic.Forum("SELECT * FROM Comment WHERE TopicID =" +topicId); GridView1....

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

CS1501: No overload for method 'Insert' takes '5' arguments
 Hi,Can some one please help me im getting this error and i cant figuer out way its happening this is the full error i get... Compiler Error Message: CS1501: No overload for method 'Insert' takes '5' arguments Source Error: Line 27: DataSetTableAdapters.MemberInfoTableAdapter da = new DataSetTableAdapters.MemberInfoTableAdapter();Line 28: MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName);Line 29: ...

CS1501: No overload for method 'buildQuery' takes '0' arguments
I am getting the following message when i try to execute my code; "CS1501: No overload for method 'buildQuery' takes '0' arguments", where am i going wrong, my code is below;public static DataSet SQLExecute(string strSQL) { string strTableName;string strData; DataSet dsetResponse = new DataSet(); try {using (SqlConnection conn = new SqlConnection(DHOC.clsDHOC.GetConnString())) {SqlCommand cmd = new SqlCommand("SELECT '" + strData + "' FROM '" + strTableName + "' where '" + strData + "' = 'Column...

CS1501: No overload for method 'RegisterControl' takes '2' arguments
 hello. When I delpoyed my solution to a test server I got this error when trying to run the application. But its working on the development machines.  Normal 0 21 false false false ES-CO X-NONE X-NONE MicrosoftInternetExplorer4 ...

CS1501: No overload for method 'Substring' takes '3' arguments
I get the following error "CS1501: No overload for method 'Substring' takes '3' arguments" when i try to run my code, does anyone know a reason why?    Line 610:           // Concatenate Line 611:Line 612:           strSQL = strSQL + "(" + String.Substring(strPart1, 1, Strings.Len((strPart1)) - 1) + ") values (" + String.Substring(strPart2, 1, Strings.Len(strPart2) - 1) + ")";Line 613:Line 614:    ...

CS1501: No overload for method 'buildQuery' takes '4' arguments
Hi i get the error "No overload for method 'buildQuery' takes '4' arguments" when i click on the save button which is meant to execute the button, my code is as follows;clsOBJ objDHOC = new clsOBJ();Pmillio.clsOBJ.buildQuery("INSERT", "tblProperty", strData, strWhere); { string[,] strData = new string[11, 2];string[,] strWhere = new string[11, 3]; strData[0, 0] = "StatutoryDate";strData[0, 1] = Convert.ToDateTime(this.txtDate.Text.ToString().Trim()); strData[1, 0] = "DateApplied";strData[1, 1] = Convert.ToDateTime(...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

Error Message: No overload for method 'SqlParameter' takes '1' arguments
Dear All,   I have a problem while trying to update the content of my page to the database by the means of a stored procedure string OcompConnection = ConfigurationManager.ConnectionStrings["GenUserCode"].ConnectionString;  System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(OcompConnection); System.Data.SqlClient.SqlCommand ocmd = new System.Data.SqlClient.SqlCommand("Dealer_Insert", conn);ocmd.CommandType = CommandType.StoredProcedure; ocmd.Parameters.Add(new SqlParameter("@UserCode"), SqlDbType.NVarChar); oc...

Compilation Error: CS1501: No overload for method 'Photo' takes '3'arguments
Hi,I am in trying to have two different Categories of Photo Albums:e.g  1. Personal Album       2. Work AlbumAnd wish to have two seperate album pages (so one page with various 'Personal' albums and another page with just 'Work Albums'). I have created a field in the Albums table titled Category and made a few changes to some of the files. Problem is when I try to load up the website I get the following error:Compiler Error Message: CS1501: No overload for method 'Photo' takes '3' argumentsSource Error: Line 98: while (reader.Read())...

No overload for method 'Add' takes '3' arguments
For some reason, I don't know if maybe I'm just not using the right method for the adding of parameters, but I get this error during the build:No overload for method 'Add' takes '3' arguments            Should I be using Add here?  I did see using dbCommandWrapper.AddInParameter here but I do'nt think that's a valid method in Enterprise Library 2.0: http://aspalliance.com/688Part of my code:....some code beforeDatabase db = DatabaseFactory.CreateDatabase();             DbCommand dbCommandWrapper = db.GetStoredProcCommand("...

No overload for method 'uf_save_dw_as_excel' takes '2' arguments
I'm trying to save my DW using the Dw2xls Powerbuilder Library for converting DW to Excel, when is Generating PowerBuilder .NET assemblies failed. Isn't complain for this version 11.5? Anyone knows how to correct this problem? Thanks to all. are you trying the demo version? It comes with PBD file which cannot be included in a demo WEBFORM applicatiom, just ion a native one. However, the presentation XLS you'll get under PB native would be the same in a webform application. When you buy the product, you'll receive the PBL source of DW2XLS which the could be ...

No overload for method 'ReportParameter' takes '2' arguments
I am trying to render a report that runs on our remote SQL Reporting Server to the ReportViewer control in my C# asp.net page.  The reports will need to have various parameters past to it.  However, every example I see on how to do this looks something like this (this is from MSDN):ReportParameter p = new ReportParameter("ShowDescriptions", "test");this.ReportViewer1.ServerReport.SetParameters(new ReportParameter[] { p }); However, this will not build for me, I get the error:No overload for method 'ReportParameter' takes '2' argumentsIn fact, when I mouse over ReportParameter,...

No overload for method 'function' (SQLsearch) takes '0' arguments
Hello I want to run a search query when the user clicks the search button. However i get that the function takes 0 arguments but Im not sure what that actually means. I have a function called SQLsearch witch i call when the buttin is clicked. Thea reason that Im calling a function instead of writing the function inside the button click event is that i want to use the e.AffectedRows that SqlDataSourceEventArgs provides. What am I doing wrong here?1 protected void SQLsearch(object sender, SqlDataSourceStatusEventArgs e) 2 { 3 if (TBstreckkod.Text != null) 4 ...

Argument '1': cannot convert from 'object' to 'int'
 I am calling a function from a label control in my gridview.. <asp:Label ID="Label1" runat="server" Text='<%# ShowCategoriesForPID(Eval("pol_id")) %>'/> But i get following error when i compile -error CS1503: Argument '1': cannot convert from 'object' to 'int'  pol_id is an integer value and my function receives it as an integer argument.  I dont know whats wrong? The "Eval" function returns an object. To need to cast it's result: <asp:Label ID="Label1" runat="s...

"No overload for method 'getReader' takes '33' arguments"
I have following code which I thought ok but it's giving me "No overload for method 'getReader' takes '33' arguments" error, what's wrong with the code? Thanks in advance. conn = new Connection(); conn.sqlDataReader = conn.getReader("addCourseStructureMain", "CampusID", ddlCampus.SelectedItem.Value.Trim(), "SessionID", ddlSession.SelectedItem.Value.Trim(), "RevisionDate", txtRevisionDate.Text.Trim().Substring(3, 2) + "/" + txtRevisionDate.Text.Trim().Substring(0, 2) + txtRevisionDate.Text.Trim().Su...

MVC Extension class
I'm very close to finishing my first HtmlHelper extension method.  But I'm still getting this error in my View when it tries to render the tetxbox extension I created...I don't see why.  I have all the params and right number of params as far as I can see: <td>       <%=TextInputVaExtensions.TextArea("txtAddress", new { _text = "some value" }, 12, 58, 20, new { _class = "req" })%><br /></td> Here's the extension class I created: using System;using System.Collections.Ge...

XmlSchema.Read error No overload method for 'read' takes '2' arguments
In pb12dotnet build 6107 I am developing an application to parse XML using the .Net classes. I have been able to read in and process XML data. Now I am trying to load a schema (xsd file) into the .net XmlSchema object. When I try to read in the schema into the object I am getting an error on XmlSchema.Read: "No overload for method 'read' takes '2' arguments." The XmlSchema.Read() method, however, always takes 2 arguments. Any suggestions on what is wrong. I was suspicious my ValidationEventHandler parm might be causing a problem, but I have not been able to...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

Web resources about - CS1501: No overload for method 'ToShortDateString' takes '1' arguments - asp.net.web-forms

Resources last updated: 2/19/2016 4:50:03 PM