Krasimir
Krasimir

Reputation: 259

Jquery do nothing on aspx content page

I have this in my child/ContentPage but nothing happen .What am i missing?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WFFHM.WebForm1" %>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
        <asp:Button ID="Button2" runat="server" Text="Button" />
    <script src="Scripts/jquery-1.7.1.js"></script>
    <script type="text/javascript">
        $("#Button2").click(function () {
            alert("ASD");
        }
            );
    </script>

</asp:Content>

Upvotes: 0

Views: 87

Answers (2)

Brad M
Brad M

Reputation: 7898

Your ID selector is wrong (missing the #, also, you need to set clientIdMode="static" for your button.

You could also do this which is uglier IMO.

$("#<%= Button2.ClientID %>")

Upvotes: 2

romainberger
romainberger

Reputation: 4558

I don't know ASP at all so I might miss something, but this should fix it:

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

Upvotes: -1

Related Questions