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...