English 中文(简体)
将C#变量改为javascript
原标题:Adding a C# variable to javascript
  • 时间:2011-08-09 14:32:22
  •  标签:
  • c#
  • .net

我的头脑中有以下法典部分:

 <script type="text/javascript">
        $(document).ready(function () {
            $( #target ).readmytweet({
                 color :  black ,
                 search :  from:  + <%= GetUserName() %>,
                 user : <%= GetUserName() %>,
                 width : 600,
                 tweets : 10,
                 speed : 25
            });
        })
    </script>

protected string GetUsername()
        {
            return "somestring..";
        }

然而,我正在收到一个错误信息:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

是否有任何人知道,我如何能够在不发现这一错误的情况下将我手法背后的C#变量带入这一支职?

Thanks in advance

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 动态载体:

这样做似乎会奏效,尝试用文字总结成法典部分:

 <%= GetUserName() %> 

也可使用<代码>该说明,以获取该方法:

 <%= this.GetUserName() %> 

www.un.org/Depts/DGACM/index_spanish.htm 固定载体:

• 宣布你作为公众人物在你的牛页上:

public string UserName = "somestring..";

通过:

var userName = <%=this.UserName%>;
问题回答

http://romouly.blogspot.com/2007/08/workaround-controls- Collection-cannot.html” rel=“nofollow noretinger”>,这是一个众所周知的问题,试图在含有密码区块的网页上添加控制。

简单的工作是使用具有约束力的数据表述,即使用<代码><%#...... %>而不是<%=...... %>。 请注意,您将须在<代码>上打上<代码>,编号:,以供参考。

(BTW,记住,你在 Java文中插入的代码:,需要适当引用。)

a. 进入服务器-面 c#erra/property,在1.aspx页内。

<script type="text/javascript">
  <% string username = Class.PropertName; %>
  var jsUsername =  <%: username %> ;
</script>




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签