Click here to Skip to main content
15,997,591 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,
I want to call a javascript function from code behind (C#.NET) by passing some parameter values. The parameter values are dynamic. I am able to send static data as parameter in a string format but unable to send dynamic values. Can anyone help me, it's very urgent. Any help would be grateful.
This code written in C#.NET
string s="<a href='#' runat='server' onclick='javascript:ShowDiv(this,1,"+<b>DynamicVariable</b>+");' id='" + y + "'  style=cursor: hand>";


Please help me.

Cheers,
Dileep
Posted
Updated 2-Sep-10 0:02am
v2

1 solution

In this particular case, have you tried using the <% *variable name from server side* %> as your dynamic variable in the actual javascript part? Thus in the javascript part place this in and it could work...


<br />
<a href='#' runat='server' onclick='javascript:ShowDiv(this,1,"+ <%= DynamicVariable %> +");' id='" + <%= y %> + "'  style=cursor: hand><br />



This is just a guess, but also remember that firing a javascript function from the server side requires extra coding indeed, there are a few ways using AJAX and also there is the dirty way of making button with the function then make visibility hidden and simply on the server side call the button to be clicked and thats done, not good practice to do though.

good luck mate sorry I couldn't be of any more help...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900