• 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.

ASP.NET C# - javascript functions postback

LBJuice

n00b
Joined
Jan 23, 2005
Messages
27
I have an ASP.net repeater that creates a table.

I want an onclick event for each row that triggers a javascript function "MarkComplete(TaskID)" that can pass a variable "Task ID" to a C# code behind function that will run the query to mark the task as complete.
eg:
<td colspan="3" onclick="MarkComplete(<%#DataBinder .... )%>)">

However, I can't figure out how you get javascript functions to trigger C# functions and pass variables to the code behind.
 
I don't do much ASP.Net development but from I've studied I don't think you will be calling your C# codebehind directly from Javascript.

As long as this is all server side I think you would have to compile your C# code into an assembly which exposes the necessary methods through COM. Then you can get an instance of that class and then call it's methods.
 
You want the whole row to be a link or just a link?

What you are looking for is a LinkButton (if you just want a link).

What you need to do is define the LinkButton in your repeater template. Then you'll need to create a handler for the OnRowBound event (of the repeater) - or maybe it's the On Item bound - I forget, but in any case there's an event fired when the repeater binds to an object in your datasource. In there you'll look for the LinkButton, and set it's command properties (probably to something like the ID of the row you want to mark completed) then you'll write an event handler for the LinkButton OnClick event.

You might be able to do it declaritively, but I'm not sure about that. It'd would be much easier to just use the on row bound event to set the properties of the link button there.

You shouldn't have to write any javascript to accomplish this. ASP.Net will handle everything for you. A project I'm working on now does A LOT of this... You can get pretty wild with it if you want.

Hope this helps.
 
Back
Top