Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using  JavaScript in C Sharp button event

Posted on 2013-01-29
6
Medium Priority
?
372 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 20

Assisted Solution

by:Daniel Van Der Werken
Daniel Van Der Werken earned 2000 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 20

Accepted Solution

by:
Daniel Van Der Werken earned 2000 total points
ID: 38832996
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 20

Expert Comment

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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
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…
Suggested Courses

916 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