2

I have a jQuery function:

<script src="Scripts/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            alert("1");
            function hideInfo() {
                alert("2");
                $("#h3memberInfo").fadeOut("slow");
            };
        });

    </script>

I am trying to call above function from c# as below.

 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert", "hideInfo();", true);

On page load I get alert("1") but alert("2") is never triggered.

What wrong am I doing?

17
  • you are not calling the function anywhere.... although you don't have access to the function outside the scope..... to make it accessible define it in global context or handle click event using jQuery Commented Nov 5, 2016 at 7:10
  • when is the c# code get executed? Commented Nov 5, 2016 at 7:10
  • Same way I am able to call javascript function. What additional I have to do.! Commented Nov 5, 2016 at 7:10
  • @Tal87 - on one of the button click. Commented Nov 5, 2016 at 7:11
  • 1
    @DKR, please try my modified code below Commented Nov 5, 2016 at 7:21

1 Answer 1

6

As your function hideInfo() is wrapped inside the $(document).ready block, its not available in the global scope as you try from the code behind.

You can modify your code as below,

<script src="Scripts/jquery-3.1.1.min.js"></script>
    <script type="text/javascript">

        function hideInfo() {    
           $(document).ready(function () {
                alert("1");
                $("#h3memberInfo").fadeOut("slow");                
           });
        }

    </script>
Sign up to request clarification or add additional context in comments.

7 Comments

function is called. but 2nd line of funtion to fadeout label is not working.
Is this the id #h3memberInfo correct? Can you check this in the html view source? If it's a ASP.Net control id will be changed in the view source.
on browser, id is childcontainer_h3memberinfo. how do I access clientID in jquery?
Yes, change the line to $('#childcontainer_h3memberinfo') or give a unique css class name and use jquery selector with the class name to the control like, $('.uniqueClass').
would this ID change in future?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.