Friday, February 15, 2013

Tuesday, March 13, 2012

Triggering FancyBox from ASP.Net Codebehind

Sometimes we need fancybox to open on particular condition. I came up with a solution.
we have a Textbox, a hidden link all in UpdatePanel and necessary jQuey scripts. Here is code

protected void txtItemCode_TextChanged(object sender, EventArgs e)
        { 
                if (txtItemCode.Text.Trim() != "")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "showAl", "jQuery(document).ready(function() {$(\"#ctl00_ContentPlaceHolder1_hidden_link\").trigger('click');});", true);
                }
        } 


 protected void Page_Load(object sender, EventArgs e)
  {

     hidden_link.Attributes["href"] = "some_file.pdf";
}
This is working inside a frame that is calling another iframe with a button inside in a update panel.



Comments are appreciated... 

Friday, June 24, 2011

Convict an anodyne with passion

Convict an anodyne with passion

Using Global Timer


Using Timer Control for a Periodic task causes many problems.
Use Master Page

using System;
using System.Data;
using System.Web.UI.WebControls;
using System.Threading;
using System.Web;
namespace GlobalTimer
{
    public partial class My_Master : System.Web.UI.MasterPage
    {
        private static Timer threadingTimer;
        public static string sessionId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserId"] == null)
            {
                Response.Redirect("Default.aspx");
                return;
            }

            if (!IsPostBack)
            {
                sessionId = Session["UserId"].ToString();
                StartTimer();
            }
        }

        public static void StartTimer()
        {
            if (null == threadingTimer)
            {
                threadingTimer = new Timer(new TimerCallback(CheckData), HttpContext.Current, 0, 30000);
              
            }
        }

        private static void CheckData(object sender)
        {
            ParameterCollection pc = new ParameterCollection();
            string s = "Update USER_SESSIONS set TEMP_LOGOUT_DATE =@TEMP_LOGOUT_DATE where SESSION_ID=@SESSION_ID";

            pc.Add("@TEMP_LOGOUT_DATE", DateTime.Now.ToString());
            pc.Add("@SESSION_ID", sessionId);

            try
            {
                DA.SelWithParam(s, pc, CommandType.Text);
            }
            catch (Exception ex)
            {
                
            }
        }
    }
}