[英]How do I display the code behind variable value on my aspx page
Hi I have a Default aspx page and and its code behind page, I want to render the value of particular variable on my code behind page to the aspx page. 嗨,我有一个Default aspx页面及其背后的代码,我想将我代码背后的特定变量的值呈现给aspx页面。 For ex:-
例如:
protected void Page_Load(object sender, EventArgs e)
{
int i=12;
}
Now i am using bootstrap control on my aspx page 现在我在aspx页面上使用引导程序控件
<button type="button" class="btn btn-primary">Primary <span class="badge">7</span></button>
I want to display value of i(present in c# code behind file) on the place of 7 我想在7的位置显示i的值(在文件后面的c#代码中显示)
Please guide me... 请指导我...
Easy way would be to use use a server control like a label instead of the span and you can set the text in the codebehind that way. 一种简单的方法是使用诸如标签之类的服务器控件而不是跨度,并且您可以在该方法后面的代码中设置文本。
C# C#
protected void Page_Load(object sender, EventArgs e)
{
int i = 12;
Lbl_Badge.Text = i.ToString();
}
Markup: 标记:
<button type="button" class="btn btn-primary">Primary <asp:Label CssClass="badge" runat="server" ID="Lbl_Badge" Text="7" /></button>
If you don't want to use an ASP Label as in @abney317's example, you can do this: 如果您不想像@ abney317的示例中那样使用ASP标签,则可以执行以下操作:
CodeBehind 代码隐藏
protected void Page_Load(object sender, EventArgs e) {
int i = 12;
BadgeValue.InnerHtml = i.ToString();
}
Markup: 标记:
<button type="button" class="btn btn-primary">Primary <span class="badge" id="BadgeValue" runat="server">0</span></button>
Note: If you are going to be displaying text that may come from a user, you should be sure to AntiXss.HtmlEncode anything you put into a control's InnerHtml. 注意:如果要显示可能来自用户的文本,则应确保对AntiXss.HtmlEncode放入控件的InnerHtml中的任何内容进行编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.