7

I want that when I click on a other became visible. I'm do it using jQuery, but I'm not strong in it. I wrote script:

    <script type="text/javascript">
        $(document).ready(function () {
            $('.visiblePanel').on('click', function () {
                $('.invisiblePanel').toggle();
            });
        });
    </script>

The layout I have done through С#:

Panel visiblePanel = new Panel();
visiblePanel.Style.Add("background-color", "red");
visiblePanel.CssClass = "visiblePanel";
Panel invisiblePanel = new Panel();
invisiblePanel.CssClass = "invisiblePanel";

Of course, it didn't work. But also a get an error: enter image description here

Without script everything is fine. I tried to disable Just My Code and got that:

enter image description here Realy, I googled what to do, but without success. Could you help me?

P.S. On jsfiddle.net my script in working. http://jsfiddle.net/ZMxg8/

P.P.S: The problem isn't in script! What happened with VS?? What means "The call stack contains only external code"???

Sashko Chehotsky
  • 398
  • 2
  • 5
  • 17
  • 2
    jQuery is running **in the browser**. You have to debug with the script engine. I see that Chrome is launched. Please try again with Internet explorer, and check if you can step your javascript code. – Steve B Jul 24 '13 at 12:11

3 Answers3

3

Your code dynamically generates Panel but does not include them in the Control tree.

Update your code like this:

Panel visiblePanel = new Panel();
visiblePanel.Style.Add("background-color", "red");
visiblePanel.CssClass = "visiblePanel";
this.Controls.Add(visiblePanel);

Panel invisiblePanel = new Panel();
invisiblePanel.CssClass = "invisiblePanel";    
this.Controls.Add(visiblePanel);

This should solve the issue.

However, I suggest you to declare this Panels in the aspx markup. This will be easier to maintain.

Steve B
  • 36,818
  • 21
  • 101
  • 174
  • I've include those panel, but I just have not showed this part of the code here=) I have to declare panels dynamically, because their count is not a static – Sashko Chehotsky Jul 24 '13 at 12:37
1

I've found the solution. Steve B was right. Error "The call stack contains only external code" informed me that the debugger can't debug JavaScript code. And "mscorlib.pdb not loaded" was because when I tried to fix first error, I disabled something in options.=) Thank everybody for helping.

Sashko Chehotsky
  • 398
  • 2
  • 5
  • 17
0

Try this code:

 $(document).ready(function () {
        $('.visiblePanel').click(function () {
            $('.invisiblePanel').toggle();
        });
    });

C# Code

        Panel visiblePanel = new Panel();
        visiblePanel.Style.Add("background-color", "red");
        visiblePanel.CssClass = "visiblePanel";
        visiblePanel.Width = 10;
        visiblePanel.Height = 10;
        this.Controls.Add(visiblePanel);
        Panel invisiblePanel = new Panel();
        invisiblePanel.Width = 10;
        invisiblePanel.Height = 10;
        invisiblePanel.CssClass = "invisiblePanel";
        invisiblePanel.Style.Add("background-color", "black");            
        this.Controls.Add(invisiblePanel);
Steve B
  • 36,818
  • 21
  • 101
  • 174
Nitin Chaurasia
  • 253
  • 1
  • 5