Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Please help me,
how to call a public void (BlueOn) in c # to javasript (StartBlink) in asp.net?

C#
C#
namespace ArduinoTest
{
    public partial class LEDTest : System.Web.UI.Page
    {

        SerialPort ardo;

        protected void Page_Load(object sender, EventArgs e)
        {
            ardo = new SerialPort();
            ardo.PortName = "COM4";
            ardo.BaudRate = 9600;
            //BlueOn();
        }

        [WebMethod]
        public void BlueOn()
        {

            string blue = "1";
            ardo.Open();
            ardo.Write(blue);
            ardo.Close();
        }


JS in Asp.Net
XML
<asp:ScriptManager ID="ScriptManager2" runat="server" EnablePageMethods="true"></asp:ScriptManager>
        <script type="text/javascript">


            function StartBlink() {



            }
Posted
Updated 15-Mar-14 21:00pm
v2

You can register client side scripts and run server side scripts on the page.
For e.g. How to: Add Client Script Dynamically to ASP.NET Web Pages[^].
 
Share this answer
 
If you want to Call a client side(JavaScript) function from your code file(.cs file), than you can use like below.


C#
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "start", "StartBlink();", true);


The above line will call your StartBlink() Method which is on client side.

Hope it will help. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900