Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Using JavaScript in C Sharp button event

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
Rad1
Asked:
Rad1
  • 3
  • 3
2 Solutions
 
Daniel Van Der WerkenIndependent ConsultantCommented:
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
 
Rad1Author Commented:
I am getting Error      The name 'RegisterStartupScript' does not exist in the current context
0
 
Daniel Van Der WerkenIndependent ConsultantCommented:
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.

 
Rad1Author Commented:
By the way, the code in on .ASCX... does it make a difference???
0
 
Rad1Author Commented:
Thank you!

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


 "<" + "/script>";
0
 
Daniel Van Der WerkenIndependent ConsultantCommented:
ASCX or ASPX should not make any difference.
0

Featured Post

Industry Leaders: 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!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now