我可以通过编程方式更改asp.net控件的ID-ASP.NET [英] Can I change the ID of a asp.net control programatically - ASP.NET

查看:57
本文介绍了我可以通过编程方式更改asp.net控件的ID-ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有控制力

<asp:Button ID="btnAjax" runat="server" Text="Ajaxified" OnClick="btnAjax_Click" />

现在从后面的代码中我想更改按钮的ID

Now from the code behind I want to change the ID of the button

btnAjax.ID = "newButtonID";

但是它现在正在工作.首先有可能吗?

But it is now working. Is it possible at the first place?

编辑

我已经在HTML标记中而不是通过代码创建了控件.

I've created the control in the HTML mark up and not through code.

推荐答案

是的,您发布的代码可以使用.

Yes it is possible and your code you posted will work.

我有一个按钮和一个文本字段

I have a button and a text field

<asp:Button ID="button" runat="server" />
<input type="text" id="result" name="result" runat="server" />

在页面加载时,我更改按钮的ID,然后将结果输出到文本字段.

On page load I change the ID of the button and then output the result to the text field.

protected void Page_Load(object sender, EventArgs e)
{
    button.ID = "OtherButton";
    result.Value = button.ID;
}

文本字段中的结果为"OtherButton"

The result in the text field is "OtherButton"

这篇关于我可以通过编程方式更改asp.net控件的ID-ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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