954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

javascript alert???

how to use javascript alert in C# web forms?
im using this:

Button.attributes.Add("onClick","javascript:alert('data saved successfully')");

but its not working.
i searched for it on internet but im getting tutorials etc for windows forms.

waterfall
Newbie Poster
24 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

make sure "Button" is the name of your button that you are adding the attribute to.

Example:

<asp:Button id="btnSubmit" .... runat="server" />

btnSubmit.attributes.Add("onClick","javascript:alert('data saved successfully')");
SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

ive used the correct button id. rest of my code including code for javascript alert is working well without any error.but im not getting any alerts.

waterfall
Newbie Poster
24 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

check to see if it is actually being added. You can do this by viewing the source of your document.

Search for your "id" and see if the onclick attribute is correctly put on the submit button.

SheSaidImaPregy
Veteran Poster
1,080 posts since Sep 2007
Reputation Points: 43
Solved Threads: 68
 

Button1.Attributes.Add("onclick", "javascript:alert('data save successfully')");

The above code is working fine in my application, put this code in ur Page Load and see if it works.

sms_net
Newbie Poster
4 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Please do the following

In Aspx page write the following

<script language="javascript">
 function MyAlert(var msgStr)
{
  alert(msgStr);
}
</script>


In aspx.cs page Button.attributes.Add("onClick","MyAlert('myMessage');"); how to use javascript alert in C# web forms?
im using this:

Button.attributes.Add("onClick","javascript:alert('data saved successfully')");

but its not working.
i searched for it on internet but im getting tutorials etc for windows forms.

razool
Newbie Poster
16 posts since Mar 2008
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You