views:

158

answers:

4

I am trying to implement JQuery in my web page but i am not been able to implement it successfully.

I have a master page

where i added one script for menu bar that is already using jquery hosted by Google

This is coded in master page itself

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"&gt;&lt;/script&gt;

Now i want to implement a Jquery to set the css visibility property to true or false. into my content page of same master page.

    <script type="text/javascript">
            $(document).ready(function(){  
                $("#lnkAddMore").click(function(){
                 alert();
                  }
                  );
            });
        </script>

This html control is under my UpdatePanel. I dont know why it is not working ? I am using this control under UpdatePanel.

<input type="button" id="lnkAddMore" value="Add More" />

I tried to use it outside my update panel it is running successfully but not in UpdatePanel

I think there is a problem using it with an UpdatePanel

HERE IS MY PAGE SOURCE

   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"&gt;&lt;/script&gt; 


    <link href="../../Css/Domain.css" rel="stylesheet" type="text/css" /> 
    <script type="text/javascript"> 
        $(document).ready(function(){  
            $("#lnkAddMore").click(function(){alert();$('#h').hide(100);});
            $('#h').show(100);
        });
    </script> 


       <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div id="divDomain" runat="server">
<asp:gridview/>
                <div style="text-align:right;">
                    <input type="button" id="lnkAddMore" value="Add More" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
+4  A: 

Do you really have nested <script> tags or was it a typo?

<script type="text/javascript">

<script type="text/javascript">

If that's not a typo, then that's probably the issue.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"&gt;&lt;/script&gt;
<script type="text/javascript">
    $(document).ready(function() {  
        $('#ddmenu > li').bind('mouseover', ddmenu_open)
        $('#ddmenu > li').bind('mouseout',  ddmenu_timer)
    });

    $(document).bind('click', ddmenu_close); // do you really want to close on any click?
</script>
hunter
I used it like this <script></script> <script></script>
Shantanu Gupta
In your code above you have a <script> tag inside of another <script> tag, which will cause your js to throw an exception and your click event will not be bound
hunter
I m not using script within script. Plz check above code
Shantanu Gupta
I see that you've updated it. Reviewing...
hunter
A: 

When you're loading code in under an UpdatePanel, try not wrapping it in $(document).ready();. Ready isn't fired on document for AJAX events.

Andrew Koester
I edited my page code to <script type="text/javascript"> $("#lnkAddMore").click(function(){alert();}); </script> . But still it is not working
Shantanu Gupta
+1  A: 

Check that the ID of your button isn't actually getting changed to something like

ctl00_ContentPlaceHolder1_lnkAddMore

since it's residing in a content placeholder for the master page.

If it is, you'd have to adjust your JQuery.

LesterDove
@Lester No its name is not changing. I have taken button as an HTML control
Shantanu Gupta
Just to be sure: I edited my comment to say "ID" not "name".
LesterDove
is it there some other way to call JQuery when using with UpdatePanel
Shantanu Gupta
This is being displayed in source. ID is same there <div style="text-align:right;"> <input type="button" id="lnkAddMore" value="Add More" /> </div>
Shantanu Gupta
+1  A: 

I have used two approaches with jQuery and UpdatePanels.

The first is this: http://stackoverflow.com/questions/256195/jquery-document-ready-and-updatepanels/256253#256253

The other approach I found on Rick Strahl's blog (http://www.west-wind.com/Weblog/posts/154797.aspx) Which is to do something like this in the code behind:

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alertScript", 
    @" $(document).ready(function(){  
            $("#lnkAddMore").click(function(){
             alert();
              }
              );
        });", true);

Check this out for another example: http://stackoverflow.com/questions/844004/problem-with-scriptmanager-registerclientscriptblock-and-jquery-in-internet-explo/844714#844714

Also have a look at jQuery's live() event subscriber.

Daniel Lee