how to clear error timer - asp.net

i have designing in my web page. i have use timer control in asp.net .the error are occur
how to clear error how to run the timer
My code
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
public interface IScheduledItem
{
void AddEventsInInterval(DateTime Begin,
DateTime End, ArrayList List);
DateTime NextRunTime(DateTime time);
}
the error
he type or namespace name 'ArrayList' could not be found

Add a reference to System.Collections to your project, and a using statement for System.Collections.

You need to reference the correct namespace like this:
using System.Collections.ArrayList;
Add this to the top of you file.

Related

Mini-Profiler crashes on dbo.__MigrationHistory with EF-DB First

I'm having some performance issues with my MVC3-Application. That's why I decided to implement mini-profiler.
I'm using MVC3 with EF (and Razor Views). Because I'm using the DB-first approach, there is no dbo.__MigrationHistory. So how do I tell Mini-Profiler to stop looking for it?
This is what I did:
Global.asax.cs:
protected void Application_Start()
{
...
MiniProfilerEF.Initialize();
}
void Application_BeginRequest(object sender, EventArgs e)
{
...
MiniProfiler.Start();
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
I tried the answer in this Question, but I'm unable to use 'Database' in my DBContext (DAL).
Try this:
System.Data.Entity.Database.SetInitializer<CMDBContext>(null);
It looks like you have an existing property called Database like
public new string Database { get; set; }
in yourCMDBContext. Then when you refer to Database, you refer to that property. Since it is a property of the object, you cannot access it from static method/constructor.

Application object cannot be used in ASP.NET web page

How to use Application object in the web page?
I thought it should be something like Session object.
But when I use Application, it shows the Reference like
System.Net.Mime.MediaTypeNames.Application
Obviously, it's not the one I'm looking for.
Has it been discarded in .NET 4?
If yes, what should I use to replace the Application object.
Are you referring to this one
Page.Application Property
Gets the HttpApplicationState object for the current Web request.
<%
this.Application["test"] = "some value";
%>
inside a WebForm should work. And in the code behind it's the same story:
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Application["test"] = "some value";
}
}
The Application (HttpApplicationState) property is very much there.
Seems you have some references that are causing the confusion.
In your CS code on a Page you should be able to use it
this.Application["key"] = myObject;
It should work if you try to access it from an ASP.NET page. Application is a property of Page that returns the HttpApplicationState.
protected void Page_Load(object sender, EventArgs e)
{
if(Page.Application["Foo"] != null)
{
// ...
}
}
If you want to access it from a static context, you can use HttpContext.Current:
if (HttpContext.Current.Application["Foo"] != null){ }

Define same method in one partial class in two physical files. which will be given priority and why?

I am through a code (written by someone else). Here, what he has done is.
This is a website. I am having a problem understanding how partial classes are working in below case:
There are two pages:
1. A.aspx (which has CodeFile A.aspx.cs and it Inherits class B)
2. B.aspx (which has CodeFile B.aspx.cs and it also Inhertis class B)
Now following is the code structure of both of these files:
Code for File A.aspx.cs
public partial class B
{
protected void Page_PreRender(object sender, EventArgs e)
{
//Some Code Here
}
}
Code for File B.aspx.cs
public partial class B
{
protected void Page_PreRender(object sender, EventArgs e)
{
//Some Code Here (but this code is different than that defined in A.aspx.cs)
}
}
In above case, when we load page A.aspx, which code would be given priority?
There will be a compile time error when you try to compile this code because you can't define twice the same method
In your case it will raise an error mentioning you already have defined a method with the same name.

page event when using page methods?

I have the following that I'm using in every page:
public partial class Pages_MyPage : System.Web.UI.Page
{
ViewUserPreferencesModel TheUserPreferences;
Protected void Page_Load(object sender, EventArgs e)
{
TheUserPreferences = (ViewUserPreferencesModel)Session["SessionUserPreferences"];
And then I use a Page Method like this:
[WebMethod]
public static string GetAppointements(string DateInput)
{
ViewUserPreferencesModel TheUserPreferences = (ViewUserPreferencesModel)HttpContext.Current.Session["SessionUserPreferences"];
My question is this: Do I need to include the statement that loads user preferences when I run the page method or are the statements in the Page_Load event triggered when the page method is called, and if they are, will the variable be populated?
Thanks.
No, Page Methods do not follow the ASP.NET page lifecycle. However, even if they did, your TheUserPreferences variable won't be accessible in the static context.

Can't i set Session in a class file?

Why session is null in this even if i set:
public class HelperClass
{
public AtuhenticatedUser f_IsAuthenticated(bool _bRedirect)
{
HttpContext.Current.Session["yk"] = DAO.context.GetById<AtuhenticatedUser>(1);
if (HttpContext.Current.Session["yk"] == null)
{
if (_bRedirect)
{
HttpContext.Current.Response.Redirect(ConfigurationManager.AppSettings["loginPage"] + "?msg=You have to login.");
}
return null;
}
return (AtuhenticatedUser)HttpContext.Current.Session["yk"];
}
}
Usually session is not available on application authenticate request.
Session will be available after OnAcquireRequestState call.
Here is application events call sequence
Also, note that session will be available, only if target HttpHandler implements IRequiresSessionState or IReadOnlySessionState, and AuhenticateRequest is usually called for resources like .js or .jpg.
Just throwing this out there. The proper way to reference it is:
System.Web.HttpContext.Current.Session
Or if you've referenced this assembly HttpContext.Current.Session should be good to go.
When i call the method with this code i'm getting error:
public partial class AddNews : System.Web.UI.Page
{
private AtuhenticatedUser yk = (new HelperClass()).f_IsAuthenticated(true);
protected void Page_Load(object sender, EventArgs e)
{
//
}
But when i call the method in Page_Load function it is working
public partial class AddNews : System.Web.UI.Page
{
private AtuhenticatedUser yk =new AtuhenticatedUser();
protected void Page_Load(object sender, EventArgs e)
{
yk = (new HelperClass()).f_IsAuthenticated(true);
}
I think Valera Kolupaev is right ;)

Resources