Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

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 ? :)

Posted

Hi

This is how i do it in VB I'n not sure how to do it in C#

Hope it helps!

 Page.Response.Write("<script type=""text/javascript"""> var someJSvariable="& yourappvarvalue & "</script>")

 

Cheers Mrb

Posted

Umm...How about taking the variable out of the string

 

public string GetMenuReference()

{

return String.Format("return __showContextMenu({0},{1});", Controls[0].ClientID, numofItems);

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...