从C#.NET将参数传递给javascript函数 [英] Pass parameter to javascript function from C#.NET

查看:66
本文介绍了从C#.NET将参数传递给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,
我想通过传递一些参数值从(C#.NET)后面的代码中调用javascript函数.参数值是动态的.我能够以字符串格式发送静态数据作为参数,但无法发送动态值.谁能帮我,这非常紧急.任何帮助将不胜感激.
用C#.NET编写的代码

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>";



请帮帮我.

干杯,
Dileep



Please help me.

Cheers,
Dileep

推荐答案

在这种特殊情况下,您是否尝试过使用<%*来自服务器端的变量名称*%>作为您实际javascript部分中的动态变量?因此,将其放置在javascript部分中就可以了...


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 />




这只是一个猜测,还请记住,从服务器端触发javascript函数确实需要额外的编码,有几种使用AJAX的方法,还有一种使函数带有按钮的肮脏方法,然后隐藏可见性并简单地在服务器端调用要单击的按钮,然后就可以了,但这不是一个好习惯.

祝你好运,对不起,我再也无济于事...




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


这篇关于从C#.NET将参数传递给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆