0

Can someone please let me know how to call a C# method from onclick event using the example provided by Miguel Angelo in this link? How to get started with developing Internet Explorer extensions?

I have tried the following but it doesn't work. Is it possible to have a javascript run on Onclick and have that call a C# method? I have tried WebMethod, that didn't work either.

Both the following code is in the same .cs file

var newText = textNode.data.Replace(m.Value, "< span runat='server'; style='background-color: yellow; cursor: hand;' onclick='OnClientClick'; title='Click for more options.'>" + m.Value + "</span>");

c# method

protected void OnClientClick(object sender, EventArgs e)
    {
        MessageBox.Show("Called OnClientClick ");
    }

Thanks in advance

Community
  • 1
  • 1
user3613050
  • 13
  • 1
  • 4
  • Explain what "doesn't work" means. That tells us pretty much nothing about the problem you're encountering. – tnw May 07 '14 at 18:07
  • I don't get the pop that says "Called OnClientClick" when I click on the text I am targeting on. I have tried calling a javascript instead having an alert on Onclick, that worked, i got the pop. What I want to accomplish is to call the OnClientClick method either through a javascript or directly. – user3613050 May 07 '14 at 18:16
  • In the example you are copying from, the `onclick` event handler that is dynamically added by the C# code is still only calling a javascript function. The example doesn't show calling back into C#. – David May 07 '14 at 18:43
  • that's true, but I want know how to call back in to C# on onclick event. Is there a way of doing it? – user3613050 May 07 '14 at 18:50
  • Can anyone help me with this? I am new to web development, greatly appreciate with any advice. – user3613050 May 07 '14 at 20:33

1 Answers1

0

I am not super familiar with C#, but in Java, or PHP, I would create a JavaScript event that would call a separate 'processing' page via AJAX. If you need a response, AJAX can return a structured set of values in the JSON format which you can also parse with JavaScript.

http://html.net/tutorials/javascript/lesson18.php

Andrew
  • 7,619
  • 13
  • 63
  • 117