943,790 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 6376
  • ASP.NET RSS
Mar 12th, 2008
0

javascript alert???

Expand Post »
how to use javascript alert in C# web forms?
im using this:
ASP.NET Syntax (Toggle Plain Text)
  1. 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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
waterfall is offline Offline
24 posts
since Nov 2007
Mar 12th, 2008
0

Re: javascript alert???

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

Example:
ASP.NET Syntax (Toggle Plain Text)
  1. <asp:Button id="btnSubmit" .... runat="server" />
  2.  
  3. btnSubmit.attributes.Add("onClick","javascript:alert('data saved successfully')");
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Mar 13th, 2008
0

Re: javascript alert???

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
waterfall is offline Offline
24 posts
since Nov 2007
Mar 13th, 2008
0

Re: javascript alert???

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.
Reputation Points: 43
Solved Threads: 68
Veteran Poster
SheSaidImaPregy is offline Offline
1,080 posts
since Sep 2007
Mar 19th, 2008
0

Re: javascript alert???

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.
Last edited by peter_budo; Mar 22nd, 2008 at 4:40 pm. Reason: Keep It Organized - please use [code] tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sms_net is offline Offline
4 posts
since Mar 2008
Mar 22nd, 2008
0

Re: javascript alert???

Please do the following

In Aspx page write the following
html Syntax (Toggle Plain Text)
  1. <script language="javascript">
  2. function MyAlert(var msgStr)
  3. {
  4. alert(msgStr);
  5. }
  6. </script>

In aspx.cs page

Button.attributes.Add("onClick","MyAlert('myMessage');");





Click to Expand / Collapse  Quote originally posted by waterfall ...
how to use javascript alert in C# web forms?
im using this:
ASP.NET Syntax (Toggle Plain Text)
  1. 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.
Last edited by peter_budo; Mar 22nd, 2008 at 4:39 pm. Reason: Keep It Organized - please use [code] tags
Reputation Points: 10
Solved Threads: 2
Newbie Poster
razool is offline Offline
16 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how to skip controls and datasource in asp.net
Next Thread in ASP.NET Forum Timeline: How to add mouseover event on hyperlink with in a gridview?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC