2

I have a strange error. I have a page which loads values according to the country value stored in the session. it works fine for all other countries. only for particular country it is returning this error.

protected void populateDDMonth()
{
    int numberOfMonths;
    string monthName;
    string completeCalendarFile = Path.Combine(Request.PhysicalApplicationPath + "admin\\text-files\\", calendarFile);
    TextReader tr = new StreamReader(completeCalendarFile);
    date_classa = tr.ReadLine(); //Get classa end date string
    date_classb = tr.ReadLine(); //Get classb end date string
    DateTime dateConvert_classa = DateTime.Parse(date_classa); 
    DateTime dateConvert_classb = DateTime.Parse(date_classb);
    tr.Close();
    DataTable MonthTable = new DataTable();
    MonthTable.Columns.Add("Month", typeof(string));
    MonthTable.Columns.Add("Date", typeof(string));
    DateTime endMonth = DateTime.Today;
    DDMonth.Items.Clear(); //Clear dropdown in order to re-populate
    string classValue = DDClassType.SelectedValue.ToString();

    if (classValue == "10" || classValue == "12" || classValue == "15")
    {
        endMonth = dateConvert_classa;
    }
    else if (classValue == "9" || classValue == "13" || classValue == "16")
    {
        endMonth = dateConvert_classb;
    }
    if (endMonth.Year > DateTime.Today.Year)
    {
        numberOfMonths = (endMonth.Month + 12) - DateTime.Today.Month;
    }
    else
    {
        numberOfMonths = endMonth.Month - DateTime.Today.Month;
    }
    for (int i = 0; i < numberOfMonths + 1; i++)
    {
        monthName = DateTime.Now.AddMonths(i).ToString("MMM"); //Display month as 3 letter string
        DataRow MonthRow = MonthTable.NewRow();
        MonthRow[0] = monthName.ToString() + " " + DateTime.Now.AddMonths(i).Year.ToString();
        MonthRow[1] = DateTime.Now.AddMonths(i).ToString();
        DDMonth.Items.Add(new ListItem(monthName.ToString() + " " + DateTime.Now.AddMonths(i).Year.ToString(),
        DateTime.Now.AddMonths(i).ToString()));
    }
    if (Session["selectedMonth"] != null)
    {
        DDMonth.SelectedValue = Session["selectedMonth"].ToString();
    }

    if (!Page.IsPostBack)
    {

        DateTime startingDate = DateTime.Parse(DDMonth.SelectedValue.ToString());
        LbCalendarCurrentMonth.Text = startingDate.ToString("MMMM");

    }
}
3
  • This question is useless without code Commented Feb 7, 2011 at 15:04
  • don't post it all here. Search for the "catch" blocks and post them here, one of them is relevant. If you can debug it's great, find the exact place and post only that code. Commented Feb 7, 2011 at 15:28
  • DateTime startingDate = DateTime.Parse(DDMonth.SelectedValue.ToString()); LbCalendarCurrentMonth.Text = startingDate.ToString("MMMM"); Commented Feb 7, 2011 at 15:42

2 Answers 2

1

This is a common problem with int casts and conversions within the International cultures:

http://support.microsoft.com/kb/942460

Sign up to request clarification or add additional context in comments.

10 Comments

@sampath - Then why didn't you label the question JavaScript? You labeled it asp.net, doesn't it seem reasonable that you will get asp.net troubleshooting and responses?
@Joel I believe the error is from the codebehind file, but popping up as a javascript error. I checked for casting errors but everything seems fine. it works for all other inputs
@sampath - Everything may seem fine, but as you can see in the article I posted, valid inputs do not parse as expected. You may want to look at any casts you have in the code-behind and place them into Try/Catch blocks to specifically catch them and find out what inputs/resources are causing the exception. The javascript output is just one of the methods that asp.net uses to display exceptions, especially in AJAX-enabled pages.
@sampath - what is the problem? Just run debug and You will see where the error occures :/
@Joel Yes I did put them in a try/catch block but i am getting the correct values on the debugger, when i pass through the exception it gives the javascript error
|
0

Whatever value is selected (if any) in DDMonth drop down, is not a valid date.

So the following code should work without error:

DateTime startingDate;
if (DateTime.TryParse(DDMonth.SelectedValue.ToString(), out startingDate)
{
   LbCalendarCurrentMonth.Text = startingDate.ToString("MMMM");
}

Comments

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.