我如何在.aspx页面访问C#变量的值? [英] How do I access a c# variable's value in an .aspx page?

查看:484
本文介绍了我如何在.aspx页面访问C#变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Controls集合不能修改,因为该控件包含code块(即<%...%>)。

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

我们需要我们有问题的时候访问.aspx页面中的C#变量

we need to access the c# variable in .aspx page at the time we have problem

请指导一下?

推荐答案

如果你给你正在尝试做更详细的这会有所帮助,但你可以试试这个:

It would help if you gave more detail about what you're trying to do, however you can try this:

首先让你想在你的 ASPX 标记来访问任何变量保护

First make any variables you want to access in your aspx markup protected.

然后在Page_Load方法,调用的DataBind();

Then in the page_load method, call DataBind();

然后在你的标记,你可以这样做:

Then in your markup you can do this:

<%# VariableName %>

&LT;%= 程序只能在服务器控件某些情况下内使用。序列&LT;%#是数据绑定控件,可以在ASPX页面标记任何上下文中使用。调用的DataBind(); 让你随时随地在页面上使用这个(几乎)

The "<%=" sequence can only be used within certain contexts in server controls. The sequence "<%#" is for DataBound controls and can be used in any context in ASPX page markup. Calling DataBind(); allows you to use this (almost) anywhere on the page.

这篇关于我如何在.aspx页面访问C#变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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