Solved

Using  JavaScript in C Sharp button event

Posted on 2013-01-29
6
363 Views
Last Modified: 2013-01-30
Hi,

How can I call a JavaScript code in C Sharp Button even call???

Your help will be appreciated.
Thank you!

protected void btnMyBtTest_Click(object sender, EventArgs e)
{

// Need to use a JavaScript call here

}

Open in new window

0
Comment
Question by:Rad1
  • 3
  • 3
6 Comments
 
LVL 19

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 500 total points
ID: 38832569
Probably the best explanation for this is here:
http://forums.asp.net/t/1117189.aspx

Note that you want the entry near the bottom that shows this:

The best that you can do is something like this:
private void Button1_Click(object sender, System.EventArgs e)
{
 string javaScript =
  "<script language=JavaScript>\n" +
  "alert('Button1_Click client-side');\n" +
  "</script>";
 
 RegisterStartupScript("Button1_ClickScript", javaScript); 
}

Open in new window


Do the same in your event.
0
 

Author Comment

by:Rad1
ID: 38832935
I am getting Error      The name 'RegisterStartupScript' does not exist in the current context
0
 
LVL 19

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 38832996
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:Rad1
ID: 38833008
By the way, the code in on .ASCX... does it make a difference???
0
 

Author Closing Comment

by:Rad1
ID: 38833119
Thank you!

Also, please note:
string javaScript =
  "<script language=JavaScript>\n" +
  "alert('Button1_Click client-side');\n" +


 "<" + "/script>";
0
 
LVL 19

Expert Comment

by:Daniel Van Der Werken
ID: 38837134
ASCX or ASPX should not make any difference.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now