Thursday, April 24, 2014

Creating Batch file to Start and Stop the Window services

Windows  services are a very important part of windows environment. We can easily change the windows environment by stopping or starting the services, for example boost the system performance by stopping the multiple services during game playing.

Warning: Manipulating windows services can have some unwanted effects on your system. You should create a system restore point before experimenting.

We can easily changed the service state by creating batch file(.bat) having batch commands for start or stop the service. The important commands are the following-

  •  Net Stop- For stopping the service.
  • Net Start- For Starting the service.
Note:-The batch file will need to be run as administrator.

For Example, I have taken the "Print Spooler" service to start through the batch file. Service name of "Print Spooler" service is "Spooler".

Tuesday, December 31, 2013

Friday, December 13, 2013

How To- Load ASP.Net User Control Dynamically Using jQuery and Ajax

Here in this post, I am going to explain how to dynamically load the Asp.Net user control using jQuery and Ajax. For loading the user control we will use the Web Method on server side and call that web method through Ajax call using jQuery.

You can also find my other articles related to C#ASP.Net jQuery, Java Script and SQL Server.

So, lets start the example. In this example I have used one aspx page name Demo.aspx and one user control to load on the aspx page DemoUserControl.ascx.
ASPX Page

<div style="width:350px">
        <table width="100%">
            <tr>
                <td>
                    <asp:Label ID="lblName" runat="server" Font-Bold="true" Text="Name"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblAge" runat="server" Font-Bold="true" Text="Age"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:Button ID="btnLoadUserControl" runat="server" Text="LoadControl" />
                </td>
            </tr>
        </table>
    </div>
    <fieldset style="width:350px">
        <legend>User Control Content</legend>
        <div id="userControlContent">
        </div>
    </fieldset>

In the above aspx page, there are two TextBoxes for capturing the input and one Button to load the user control and show the enterd value.

Thursday, August 29, 2013

C#: Difference between “throw” and “throw ex” in C# .Net Exception

In day to day development, we all are very familiar with Exception  handling. We pretty much all know that we should wrap the code which may cause for any error in try/catch block and do something about error like give a error message to end user. Here I am not going to explain about Exception handling in C#. Instead I am going to talk about a particular aspect of Exception  handling, which is "throw" vs "throw ex".

You can also find my other articles related to C#ASP.Net jQuery, Java Script and SQL Server. I am writing this post because I was asked this question recently in a interview and unfortunately I didn't  know the answer. So I am posting this for those guys who uses "throw" and "throw ex" frequently but don't know the differences (not all,some knows).

Difference between “throw” and “throw ex”

Take a look on the below code snippest-
throw ex throw

try
{
   //Code which fails and raise the error
}
catch (Exception ex)
{
   throw ex;
}

try
{
   //Code which fails and raise the error
}
catch (Exception ex)
{
   throw;
}

^ Scroll to Top