I have a search feature (written by my predecessor) which takes date range, id, available programs as input and displays the results in a gridview. The feature works fine most of the time (I have tested it) but for one of the users of my application it gave this error message. I am not able to reproduce this error by myself in order to fix it. Don't know what's wrong!
Can you guys help?
Exception of type 'System.Web.HttpUnhandledException' was thrown.
System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.Convert.ToDateTime(String value)
at APP_ViewFollowupWorkload.GetFilterString() in d:\SharedServices\APP\ViewFollowupWorkload.aspx.cs:line 1415
at APP_ViewFollowupWorkload.Page_Load(Object sender, EventArgs e) in d:\SharedServices\APP\ViewFollowupWorkload.aspx.cs:line 268
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.app_viewfollowupworkload_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\bad754dd\a11f74ff\App_Web_viewfollowupworkload.aspx.ae7ca9bd.uwyek3vs.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Here is the .cs file code where the error generating:
if (txtDateTo.ToString() != string.Empty)
{
if (txtDateTo.ToString().Length > 2)
strFilter = strFilter + " AND submission_date <= ''" + Convert.ToString(Convert.ToDateTime(txtDateTo.ToString()) + new TimeSpan(1, 0, 0, 0)) + "''";
}
The error indicates that the passes in value of txtDateTo is not a valid DateTime - say 32/11/2011.
You can change the code to something that will not throw an exception by using one of the DateTime.TryParse overloads. This will not parse invalid values, but will avoid an exception being thrown - you still need to determine what to do in such a case.
Try to use ParseExact instead - here (MSDN)
.
Maybe they use some unusual date time format. Ask your user which value in textbox is used to convert to datetime.
Related
I got stuck in this error...
<a id="25" class="abc" href="example.aspx" onclick="return myfunction(this);">
and my function code take id of this link and save it to session variable..
function myfunction(a)
{
var myid = a.id;
'<%Session["x"] ="' + myid +'";%>';
return;
}
so, after that it will redirect example.aspx and throwimg code for example.aspx.cs file is:
static int j = 0;
if(Session["x"]!=null)
{
j = int.Parse(Session["x"].ToString());
}
this line throwing error:
FormatException: Format of input string is not correct..
stack:
[FormatException: Format of input string is not correct..]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7476983
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
System.Int32.Parse(String s) +23
example.Page_Load(Object sender, EventArgs e) in example.aspx.cs:103
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
The problem in your code is essentially that '<% ... %>' is used only when server(i.e. .cs ) sends data to clientside ( i.e. .html, .js).
To pass data from client side to server, you need to use other alternatives like Query Strings or html <form> tag.
I am getting the below exception in a UserControl, Page Load. I have tried searching for this on Google, but have not found much information. Please let me know if anybody could help me with the same .
The situation is, there is one ascx.cs file for various usercontrols in different languages.
The application is running properly , but this exception is getting thrown for sometimes.
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at SmartSoft.SmartLiveWeb.UserControls.Common.PayoutForms.BoundAccountsOfMember()
at SmartSoft.SmartLiveWeb.UserControls.Common.PayoutForms.Page_Load(Object sender, EventArgs e)
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Is authenticated: True
Authentication Type: Forms
Thread account name: IIS APPPOOL\SLC Website
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
/*
if (Request.QueryString.Count > 0 && Request.QueryString["MId"] != null)
this.MId = int.Parse(Request.QueryString.Get("MId"));
*/
HideAllForms();
AddValidationAttributesToControls();
**BoundAccountsOfMember();**
BoundWithdrawMethods();
/*
* if (IsNetentConfirmationRequired())
LoadNetentConfirmationForm();
*
*/
CurrentPayoutMethod = (PayoutMethodEnum)Convert.ToInt16(SessionController.GetSessionData<object>("PayoutMethod"));
}
PlaceHolder phWithdraw = this.FindControl("phWithdraw") as PlaceHolder;
Panel pnlKYC = this.FindControl("pnlKYC") as Panel;
if (SessionController.CurrentMember != null && SessionController.CurrentMember.Approved == 10)
{
phWithdraw.Visible = false;
pnlKYC.Visible = true;
}
else
{
phWithdraw.Visible = true;
pnlKYC.Visible = false;
}
}
Please find the BoundAccountsofMember method code behind .
private void BoundAccountsOfMember()
{
Dictionary<Int16, AccountType> accountTypes = SessionController.CurrentMember.GetAccountTypes();
ddlWithdrawFrom.Items.Clear();
foreach (AccountType accountType in accountTypes.Values)
{
ddlWithdrawFrom.Items.Add(new ListItem(accountType.AccountName, accountType.AccountId.ToString()));
}
ListItem li = ddlWithdrawFrom.Items.FindByValue(SessionController.DefaultAccountId.ToString());
if (li != null)
{
ddlWithdrawFrom.SelectedIndex = -1;
li.Selected = true;
}
}
The above exception is being thrown from Page_Load event.
Regards
Srividhya
I could guess that you have a problem with a session here. You're checking SessionController.CurrentMember != null in Page_Load, but not in your BoundAccountsOfMember.
I believe that is a problem here if you're saying it happens time to time. You probably should work on session renewal/invalidation in your modules to make sure your code will not run without a valid session.
I'm trying to implement a functionality whereby if I click a button it adds a new unit to a module (basically a new page), but am getting error on the below line:
UnitID = Request["UnitID"] != null ? Convert.ToInt32(Request["UnitID"]) : 0;
And the stacktrace is
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7470855
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
System.Convert.ToInt32(String value) +63
Data_Project.Page_Load(Object sender, EventArgs e) in
C:\Projects\Projects.aspx.cs:69
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
Can you please tell me what the error is?
Many advance thanks.
It is because you have something in Request["UnitID"] which is not a number
Maybe you will want to try
int UnitID = 0;
if(string.IsNullOrEmpty(Request["UnitID"]))
{
UnitID = 0;
}
else
{
if(!Int32.TryParse(Request["UnitID"], out UnitID))
{
UnitID = 0;
}
}
Hope this helps.
The error "Input String not in a correct format" means that Request["UnitID"] can't be converted to an integer.
Try This:
UnitID = !string.IsNullOrEmpty(Request["UnitID"]) ? Convert.ToInt32(Request["UnitID"]) : 0;
Or this:
if(!int.TryParse(Request["UnitID"]+"", out UnitID)
{
UnitID = 0;
}
I have built a dataset named Transaction_Time.
I called it on Page_Load
Transaction_Time tranTme = new Transaction_Time();
put it in the session.
Session["Transaction"] = tranTme;
Then I call that session and cast to dataset.
DataSet dstTranTime = (DataSet)Session["Transaction"];
I got the following error.
Unable to cast object of type 'Transaction_Time' to type 'System.Data.DataSet'.
[InvalidCastException: Unable to cast object of type 'Transaction_Time' to type 'System.Data.DataSet'.]
Transaction_Time.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\William29_11_2010\Transaction_Time.aspx.cs:47
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
It is OK for some other pages. But for some page, it doesn't.
Is it something wrong that I do or.. ???
You put in typeof(Transaction_Time) and try to get out typeof(DataSet). this will fail until
Transaction_Time is not derived from DataSet. Try to read Transaction_Time instead of DataSet.
Transaction_Time tranTme = new Transaction_Time();
....
Session["Transaction"] = tranTme;
....
Transaction_Time dstTranTime = Session["Transaction"] as Transaction_Time;
if (dstTranTime == null)
System.Dignostics.Trace.WriteLine("Ups! Expecting Transaction_Time, but got {0}", Session["Transaction"] );
It looks like you may have two classes called Transaction_Time. If you have created a class called Transaction_Time and derived it from DataSet AND you have a class called Transaction_Time that is derived from, say, Page. Then the compiler may be confused about which you mean and you may occasionally be storing the page Transaction_Time rather than the DataSet Transaction_Time.
Be explicit when creating the Transaction_Time class and use the fully qualified name OR rename one of your classes so that the name is not ambiguous. That should solve your problem (assuming my assumptions are correct).
I've got a weird problem with a NullReferenceException on a high traffic website my company hosts. The exceptions are logged with full stack-traces but I am unable to reproduce it.
The exception occurs a couple of times a day, for different users, and it's a NullReferenceException thrown in the code block below:
protected void Page_Load(object sender, EventArgs e)
{
...
if (!Page.IsPostBack)
{
...
this.ViewState[StaticClass.StaticStringProperty] = StaticClass.StaticIntProperty; // this is the line the exception occurs on
...
}
}
The only place I can figure that a NullReferenceException would be thrown is if ViewState is NULL, but I've never known that and can't find any reason why this would be the case in a Page_Load that isn't a postback.
StaticStringProperty and StaticIntProperty are both initialised, static properties of StaticClass.
StaticStringProperty is defined as:
public const string StaticStringProperty = "IdFromClient";
Does anyone know how this could happen, or any other reason why a NullReferenceException would be thrown on the above line?
EDIT
As requested, the full stack-trace for the error is as follows. Line 54 is the line I've highlighted above.
at MyCompany.MyApplication.Appliance.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\shellama\My Documents\MyApplication\Appliance.aspx.cs:line 54
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at MyCompany.MyApplication.PageBase.OnLoad(EventArgs e) in C:\Documents and Settings\shellama\My Documents\MyApplication\App_Code\PageBase.cs:line 58
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The only thing I can say about it (I had a similar situation recently) is that StaticClass.StaticStringProperty is NULL. But then again, you must have paid attention to this. I can't think of something else.