Passing an integer argument to a javascript function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Passing an integer argument to a javascript function

WengWeng Posts: 52Member

How do we pass an integer argument from C# into a javascript function?
I declare an integer variable first, then I pass it into the javascript function.
But the javascript code didnt execute correctly.

//First, an integer variable is declared
int numofItems;

// Returns the Javascript code to attach the context menu to a HTML element
public string GetMenuReference()
return String.Format("return __showContextMenu({0},numofItems);", Controls[0].ClientID);

//Then the Javascript is called when the oncontextmenu event happens
ctl1.Attributes["oncontextmenu"] = GetMenuReference();

Initially the javascript function has the {0} argument only and it worked fine. But when I added one more integer argument, it doesnt work. What is the correct way to pass an int argument ?

Sign In or Register to comment.