Saturday, June 23, 2012

On Enter Button click redirect with querystring as textbox value


put your text box and button in panel with default button

<asp:Panel  DefaultButton="Button1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </asp:Panel >





OR





<script>

     function button_click(objTextBox, objBtnID) {
         if (window.event.keyCode == 13) {
             if (objTextBox.value != "") {
                 document.getElementById(objBtnID).focus();
                 document.getElementById(objBtnID).click();
             }
            
         }
      }
    </script>



<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />




Page load:-
this.TextBox1.Attributes.Add("onkeypress", "button_click(this,'" + this.Button1.ClientID + "')");


protected void Button1_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(TextBox1.Text))
        {
            Response.Redirect("Default2.aspx?text=" + TextBox1.Text);
        }
    }

Wednesday, June 20, 2012

Logging error to text file c#.Net

1. Add new static "ErrorLoging" class to solution and paste the below code in cs file.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Diagnostics;

/// <summary>
/// class contain methode for logging WriteToErrorLogFile_Trace(string)
/// </summary>
public  static class ErrorLoging
{
    /// <summary>
    /// log error to path metion in web.config file for key "ErrorFolderPath".
    /// new file will be created for each day
    /// </summary>
    /// <param name="msg">error msg to log.</param>
    /// <param name="ex">exception object, Pass null to just log some msg.</param>
    public static void WriteToErrorLogFile_Trace(string msg,Exception ex)
    {
        try
        {
            if (!System.IO.Directory.Exists(System.Configuration.ConfigurationManager.AppSettings["ErrorFolderPath"] + "\\Errors\\"))
            {
                System.IO.Directory.CreateDirectory(System.Configuration.ConfigurationManager.AppSettings["ErrorFolderPath"] + "\\Errors\\");
            }
            //if (!System.IO.File.Exists(Application.StartupPath + "\\Errors\\" + DateTime.Today.Date.ToString().Replace('/', ' ').Replace(':', ' ')+".txt"))
            //{
            //    System.IO.File.Create(Application.StartupPath + "\\Errors\\" + DateTime.Today.Date.ToString().Replace('/', ' ').Replace(':', ' ') + ".txt");
            //}



            FileStream fs1 = new FileStream(System.Configuration.ConfigurationManager.AppSettings["ErrorFolderPath"] + "\\Errors\\" + DateTime.Today.Year.ToString() + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd") + ".txt", FileMode.Append, FileAccess.Write);
            StreamWriter s1 = new StreamWriter(fs1);


SharePoint document metadata not updating

I faced a weird issue today, Metadata for document which has lookup column was not updating even after saving the item. There was no erro...