Asp.net server control calling javascript

Posted by Gayathri under JavaScript on 10/31/2011 | Points: 10 | Views : 2469 | Status : [Member] | Replies : 4
I am calling the following javascript in asp.net button server control.
it is not running.
please clarify.

<title></title>
<script language ="javascript" >
function AlertMe() {

alert("Welcome to javascript");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>

<asp:Button ID="Button1" OnClick ="AlertMe();" runat="server" Text="Button" />
</form>
</body>
</html>




Responses

Posted by: Jayakumars on: 10/31/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
let me check this


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function AlertMe() {
alert("Welcome to javascript");
}
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" OnClientClick ="AlertMe();" runat="server" Text="Button" />
</form>
</body>
</html>


Mark as Answer if its helpful to you

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mdjack on: 10/31/2011 [Member] Starter | Points: 25

Up
0
Down
hi Gayathri,

add the runat attribute in the head tag then only the script can be execute.

N. MOHAMED ZACKKARIAH

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jpchoudhari on: 10/31/2011 [Member] Starter | Points: 25

Up
0
Down
call ur function in OnClientClick="" instead of click

Kind Regards,
Jay

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetcreed on: 11/15/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

On page load please add the following code ,

Button1.Attributes.Add("onclick", "AlertMe();");

Regards,
sankar

Code till you bleed..........

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response