Solved

Using  JavaScript in C Sharp button event

Posted on 2013-01-29
6
368 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 20

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 20

Accepted Solution

by:
Daniel Van Der Werken earned 500 total points
ID: 38832996
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

717 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