• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Passing a javascript variable into a C# function

odoe

[H]F Junkie
Joined
Oct 10, 2001
Messages
9,796
Ok, I'm a bit stumped on this portion of a web app I am working on.

I'm not a hardcore developer by any means, but I have had to learn C# over the past year or so for work and I'm still learning. I just recently dived into the nitty gritty of javascript.

I have a variable that is pulled from a database and have the ability to use javascript to grab it.

In my C#, I have a function that creates a Gridview based off a single variable passed to the function.

I'm trying to use javascript to create a hyperlink that will pass the variable to the C# function that creates the Gridview in the same page.
Basically, I'm thinking of calling a javascript function that will call a C# function.
like "onclick='toCsharp(" + variable + ")'"
then
function toCsharp(mine)
{
go to csharp already damnit
}

I have found plenty of documentation on passing C# variables to javascript functions, but not the other way around.

The only other thing I can think of is creating another page with the Gridview function, adding the variable to the URL and using regular expressions to grab the variable from the URL, but I'd like to avoid that if I can.

If I haven't provided enough detail, let me know.
This web page is using a ScriptManager if that matters at all.
 
Javascript cannot directly call functions in your codebehind. The closest that you can come is using AJAX or JSON. It is possible to expose methods on your page that can be accessed via Javascript...but that's not going to help you, really.

Once you've sent your page to your client you're done with your C# until your next postback (or AJAX postback, or JSON call). They are two wholly separate worlds.

The server has to reconstruct the page for every request it gets, and the client doesn't have access to your C# code, all of that processing happens on the web server, all the client sees is HTML, CSS and Javascript.

What exactly are you trying to accomplish?
 
You could write your C# program with argc and argv as input parameters to main()
 
I'm working with a 3rd party toolkit that queries a database.
(ESRI ArcGIS Server 9.3 for .NET for those interested)
One of the options I have is to edit the appearance of a field. This let's me use html to edit the appearance of a field. I've used it once to create a link that calls a javascript popupwindow that opens a new page with the field value at the end.

I was hoping to use this feature as the basis to query a database and show the results in a GridView.
Similar to this example, except I would use a GridView as table.
http://mapapps.esri.com/serverdemos/mailinglist/index.html
If you click on a parcel, you hit submit and get a mailing list. Except in my case, I don't have the ability to add a Button, so I would need to do something based of a link.

After looking at some more options and seeing what you guys are saying, I may be better off send the link to a new page and pulling the value I need from the URL string. That, I am pretty confident I can do.
I suppose I can use js to query my db and a build table to display in a div, it's just the toolkit provides a template that has so far been touchy to adding new divs and tables to the page.

Thanks guys.
 
Does this hyperlink cause a PostBack? If so, you could have the JavaScript function write the value to a hidden field or QueryString variable and on the PostBack, have the GridView's DataSource look in whichever location you chose
 
Back
Top