Page.FindControl(string id)

 

Hi, if you have searched for the problem, Page.FindControl(string id) raises a NullException in ASP.NET then you came to the right place.

The answer is simple

try the following…

Control c = this.Page.Master.FindControl(“ContentPlaceHolderID”);

c.FindControl(“The ID of the control you search for”);

 

Read the below link for the detailed information

http://forums.asp.net/t/1000865.aspx/1

Advertisement

Calendar in ASP.NET

We all know that .NET provides us rich set tools for us. Calendar control is one of them. We can simply use the calendar control for date input. But it is more powerful and we can simply create a complete application using calendar control which shows the tasks that have been scheduled.

To use the calendar control in a such way we should have to know about, how the calendar control is rendered in the HTML. Calendar control is rendered in as a table in HTML and every day is rendered in the order.

And calendar control provides a DayRender event as well. That’s enough for us to create the application.

Simply drag drop the calendar control inside your ASP.NET page. Make it big enough to fit to the screen.

And put the code behind as described here. I hardcoded the tasks in a HashTable but if you want, you can keep them in a data source.

 

image

 

In the Page_Load we load some data into the HashTable. This scenario may vary based on where you keep your data source. (As I mentioned earlier here it is simply hard coded).

DayRender method is triggered for each day that is rendered for the month. First in the if condition we check whether the rendered date is in the HashTable. Here we are providing the key and check whether value of the key is null or not. If it is not null then the key is available in the HashTable so a task has been assigned on that day.

Then we proceed inside the if condition.

We create a Literal control and make gives the text as <br/> (I don’t need to explain this as we all know why ?) And I add the Literal Control to the specific cell of the calendar control. (because as I explained earlier calendar control is rendered as a table in HTML)

Then I add a Label and feed the task of that particular day. Here DayRenderEventArgs object is very useful in getting the rendered day.

image

The above is simple and yet powerful. 🙂

Starting a process from a Windows Service

If you have some knowledge about Windows services and their functionalities then go ahead. Otherwise you may not understand some of the points mentioned here.

Are you suffering from starting a process from your windows service ? I have a cunning solution for that. Normally we cannot start any process either on our local machine or from a remote machine through a windows service.

We can start the process by enabling the Desktop Interactive of the service, but the UAC system of Vista and Windows 7 is a problem, that every time we start the process from a service it asks whether to allow the desktop interactivity. We can’t ask our clients to stop the UAC system. So what is the solution ?

Now I think you have some idea why can’t we start a process from service. But you might have a question in your mind why we need a process for a service ? There can be several answers

  • We need to perform a CPU intensive operation
  • COM interoperability is clashing with some threading components of the service
  • Some actions can be performed more efficiently by a separate process rather than a service

I figured out this solution as I suffered from the bolded point. Here the method I have used.

Create an ASPX webpage (it should be hosted in a later version of IIS 4.0)

In the Page_Load method start the process.

Then Create the Windows Service to access the the web page. (Access it through normal WebRequest and WebResponse). Cool !

The real cool thing is you can almost start all the processes by using this method from a windows service. Even processes with arguments and Verbs.’

Here’s the code for the webpage

protected void Page_Load(object sender, EventArgs e)
{

Process p = new Process();

p.StartInfo.FileName = "path to your process (your .exe file)"

p.StartInfo.UseShellExecute = false;

p.StartInfo.CreateNoWindow = true;

p.Start();

p.WaitForExit();

p.Dispose();

}

 

In the service within the OnStart() put the following code

try

{

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("ASPX page path");

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

}

catch (Exception ex)

{

}