Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone

How do I execute javascript from code behind where the button inside an updatepanel

I want to open a div inside a fancybox and I am opening it from code behind
and It is working
but I want to put the button inside an updatepanel
but after that the javascript is not triggering
maybe because I am putting it inside document.ready
what else we can put the trigger in to work

html
ASP.NET
<a id="various"  runat="server" href="#inline" style="visibility: hidden"></a>
                <asp:Literal ID="fancyLtr" runat="server"></asp:Literal>
                <asp:UpdatePanel ID="UpdatePanel6" runat="server">
                    <ContentTemplate>
                        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
                    </ContentTemplate>
                </asp:UpdatePanel>



javascript
JavaScript
$(document).ready(function () {
 $("#ContentPlaceHolder1_various").fancybox();
});



code behind
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        various.Attributes["href"] = "#inline";
        fancyLtr.Text = "<script>jQuery(document).ready(function() {$(\"#ContentPlaceHolder1_various\").trigger('click');});</script>";
    }



Thanks in advanced
Posted
Updated 11-Jul-14 5:12am
v2
Comments
Only write the trigger code. No need to put it inside the document ready.

1 solution

You can do it with using ClientScript.RegisterClientScriptBlock
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900