Thursday 20 February 2014

If any design issues in internet explorer because of version level , add the below code in Web.config

      <system.webServer>
    <httpProtocol>
      <customHeaders>
        <clear/>
   <!--This setting will make document mode to highest mode available we need have mode 8 and above-->
       <add name="X-UA-Compatible" value="IE=Edge"/>
      </customHeaders>
    </httpProtocol>
  </system.webServer>


Simple things effects a lot ... happy coding.........

Tuesday 18 February 2014

Example for delegate in C# - here i will show how to call the child page button click on clicking the button which is inside user control of the parent page

In User Control lets name like horizantalmenu.ascx, i will define the event handler and i will use it in the particular button click event



 public event EventHandler ButtonClickDemo;   // define it globally

protected void Page_Load(object sender, EventArgs e)
 {
   
 }


protected void Button_Click(object sender, ImageClickEventArgs e)
    {
        ButtonClickDemo(sender, e);    // m using the event here
    }


--------------------------------------------------------------------------------------------------

In all the successive pages where you are calling  horizantalmenu.ascx in your page ,

trigger that event in the page load of your page

protected void Page_Load(object sender, EventArgs e)
    {
        HorizontalMenu.ButtonClickDemo += new EventHandler(GetMainQueryOnNotepad);
                                                                             // assigning with one function to call on button click
    }


 protected void GetMainQueryOnNotepad(object sender, EventArgs e)
    {
           /// you can do what ever you want to do in this function.
    }


Thursday 6 February 2014

Creating simple error log in Asp.net / C#

 public void ErrorLog(string sMessage)
    {
     
        string LogPath = ConfigurationManager.AppSettings["ErrorlagPath"].ToString();
        string filename = "ErrorLog_" + DateTime.Now.ToString("dd-MM-yyyy") + ".txt";
        string filepath = LogPath + filename;

        if (!Directory.Exists(LogPath))
            Directory.CreateDirectory(LogPath);
        string sFilePath = filepath;

        StreamWriter objSw = new StreamWriter(sFilePath, true);
        objSw.WriteLine("-------------------START-------------" + DateTime.Now + " -----------------");
        objSw.WriteLine(sMessage);
        objSw.WriteLine("-------------------END-------------" + DateTime.Now + " -----------------");
        objSw.Close();
    }