Saturday, 31 March 2012

how to use RadConfirm as simple confirm

JS CODE:

<script type="text/javascript">
    window.blockConfirm = function (text, mozEvent, oWidth, oHeight, callerObj, oTitle) {
        var ev = mozEvent ? mozEvent : window.event;
        ev.cancelBubble = true;
        ev.returnValue = false;
        if (ev.stopPropagation) ev.stopPropagation();
        if (ev.preventDefault) ev.preventDefault
        var callerObj = ev.srcElement ? ev.srcElement : ev.target;
        if (callerObj) {
            var callBackFn = function (arg) {
                if (arg) {
                    callerObj["onclick"] = "";
                    if (callerObj.tagName == "A") {
                        try {
                            eval(callerObj.href)
                        }
                        catch (e) { }
                    }
                    else if (callerObj.click) {
                        callerObj.click();
                    }
                }
            }
            radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
        }
        return false;
    }
</script>

HOW TO USE:

<asp:Button ID="btnDelete" OnClientClick="return blockConfirm('<br/>Are you sure you want to delete this record?<br/>&nbsp;', event, 340, 150, '', 'Delete confirm')" Text="Delete" runat="server" />



Friday, 30 March 2012

using linq access radgrid's item or row


List<GridDataItem> Items = (from item in radAvailableNetworks.MasterTableView.Items.Cast<GridDataItem>()
where ((CheckBox)item.FindControl("chkSelect")) != null
&& ((CheckBox)item.FindControl("chkSelect")).Checked
select item).ToList();

compress viewstate asp.net

Method 1:

protected override void SavePageStateToPersistenceMedium(object pageViewState)
{
    if (bool.Parse(ConfigurationManager.AppSettings["ViewStateCompressionEnable"] ?? "false"))
    {
        Pair pair1;
        System.Web.UI.PageStatePersister pageStatePersister1 = this.PageStatePersister;
        Object ViewState;
        if (pageViewState is Pair)
        {
            pair1 = ((Pair)pageViewState);
            pageStatePersister1.ControlState = pair1.First;
            ViewState = pair1.Second;
        }
        else
        {
            ViewState = pageViewState;
        }
        LosFormatter mFormat = new LosFormatter();
        StringWriter mWriter = new StringWriter();
        mFormat.Serialize(mWriter, ViewState);
        String mViewStateStr = mWriter.ToString();
        byte[] pBytes = System.Convert.FromBase64String(mViewStateStr);
        pBytes = ViewStateCompressor.CompressViewState(pBytes);
        String vStateStr = System.Convert.ToBase64String(pBytes);
        pageStatePersister1.ViewState = vStateStr;
        pageStatePersister1.Save();
    }
    else
    {
        base.SavePageStateToPersistenceMedium(pageViewState);
    }
}

//// Deserialize view state
protected override object LoadPageStateFromPersistenceMedium()
{
    if (bool.Parse(ConfigurationManager.AppSettings["ViewStateCompressionEnable"] ?? "false"))
    {
        PageStatePersister pageStatePersister1 = this.PageStatePersister;
        pageStatePersister1.Load();
        String vState = pageStatePersister1.ViewState.ToString();
        byte[] pBytes = System.Convert.FromBase64String(vState);
        pBytes = ViewStateCompressor.DecompressViewState(pBytes);
        LosFormatter mFormat = new LosFormatter();
        Object ViewState = mFormat.Deserialize(System.Convert.ToBase64String(pBytes));
        return new Pair(pageStatePersister1.ControlState, ViewState);
    }
    else
    {
        return base.LoadPageStateFromPersistenceMedium();
    }
}
Method 2:

    public class ViewStateCompressor
    {
        public ViewStateCompressor() { }

        public static byte[] CompressViewState(byte[] uncompData)
        {
            using (MemoryStream mem = new MemoryStream())
            {
                CompressionMode mode = CompressionMode.Compress;
                // Use the newly created memory stream for the compressed data.
                using (GZipStream gzip = new GZipStream(mem, mode, true))
                {
                    //Writes compressed byte to the underlying
                    //stream from the specified byte array.
                    gzip.Write(uncompData, 0, uncompData.Length);
                    gzip.Close();
                }
                return mem.ToArray();
            }
        }

        public static byte[] DecompressViewState(byte[] compData)
        {
            GZipStream gzip;
            using (MemoryStream inputMem = new MemoryStream())
            {
                inputMem.Write(compData, 0, compData.Length);
                // Reset the memory stream position to begin decompression.
                inputMem.Position = 0;
                CompressionMode mode = CompressionMode.Decompress;
                gzip = new GZipStream(inputMem, mode, true);
                using (MemoryStream outputMem = new MemoryStream())
                {
                    // Read 1024 bytes at a time
                    byte[] buf = new byte[1024];
                    int byteRead = -1;
                    byteRead = gzip.Read(buf, 0, buf.Length);
                    while (byteRead > 0)
                    {
                        //write to memory stream
                        outputMem.Write(buf, 0, byteRead);
                        byteRead = gzip.Read(buf, 0, buf.Length);
                    }
                    gzip.Close();
                    return outputMem.ToArray();
                }
            }
        }
    }