Sunday, August 18, 2013

Modal Popup - Ajax toolkit


<ajaxToolkit:ModalPopupExtender ID="MPE" runat="server"
    TargetControlID="LinkButton1"
    PopupControlID="Panel1"
    BackgroundCssClass="modalBackground"
    DropShadow="true"
    OkControlID="OkButton"
    OnOkScript="onOk()"
    CancelControlID="CancelButton"
    PopupDragHandleControlID="Panel3" />

Generate unique key using c#

 private string GetUniqueKey()
  {
  int maxSize  = 8 ;
  int minSize = 5 ;
  char[] chars = new char[62];
  string a;
  a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
  chars = a.ToCharArray();
  int size  = maxSize ;
  byte[] data = new byte[1];
  RNGCryptoServiceProvider  crypto = new RNGCryptoServiceProvider();
  crypto.GetNonZeroBytes(data) ;
  size =  maxSize ;
  data = new byte[size];
  crypto.GetNonZeroBytes(data);
  StringBuilder result = new StringBuilder(size) ;
  foreach(byte b in data )
  { result.Append(chars1)>); }
   return result.ToString();
  }

Function for autocompletion

<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
                            ServiceMethod="GetCompletionList" ServicePath="" TargetControlID="TextBox1"
                            EnableCaching="true" CompletionInterval="1000" CompletionSetCount="12"
                            MinimumPrefixLength="1">
                        </cc1:AutoCompleteExtender>





#region AutoComplete

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
    //[System.Web.Script.Services.ScriptService]
    public static string[] GetCompletionList(string prefixText, int count)
    {
        ClsBusinessLogicSocialNetwork objQryEx = new ClsBusinessLogicSocialNetwork();
        ArrayList arNull = new ArrayList();
        if (count == 1)
        {
            count = 10;
        }
        DataTable dt = objQryEx.SelectData("tbl_profile", "profile_name","profile_name like '"+prefixText +"%'");
        string[] items = new string[dt.Rows.Count];
        if (dt != null)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strName = dt.Rows[i]["profile_name"].ToString();
                items[i] = strName;
            }
            return items;
        }
        else
        {
            items[0] = prefixText;
            return items;
        }
    }
    #endregion

File Download

string name=Filename.Text
string ext=Path.GetExtension(name);
Response.AppendHeader("content-disposition","attachment;filename="+name+"");
Response.TransmitFile(Server.MapPath("s/"+name));
Response.End();