在aspx页面中向cs页面中的后面代码写入相同的代码
有没有办法从 aspx 页面编写此代码 到asp.net 中的aspx 页面(cs) 的后台代码。
<a rel="lightbox" id="userImageLightBox" runat="server" title="profile image">
<img id="userImage" runat="server" width="150" height="146" alt="" src=""/>
</a>
例如,如果我在 apsx 中有代码:
<asp:Label ID="pageProfileHeadName" runat="server" Visible="true"/>
在后面的代码中我可以这样做:
Label label = new Label();
label.ID = "pageProfileHeadName";
label.Visible = true;
谢谢
is there a way to write this code from an aspx page
to a behind code of the aspx page (cs), in asp.net.
<a rel="lightbox" id="userImageLightBox" runat="server" title="profile image">
<img id="userImage" runat="server" width="150" height="146" alt="" src=""/>
</a>
for example if i have the code in apsx:
<asp:Label ID="pageProfileHeadName" runat="server" Visible="true"/>
in the behind code i can do:
Label label = new Label();
label.ID = "pageProfileHeadName";
label.Visible = true;
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答 - 是的 - 超链接控件呈现为
,因此您可以执行以下操作:
请参阅有关此服务器控件的 MSDN:
http://msdn.microsoft.com/en-us/library/k0b15efk(v=vs.71).aspx
任何时候控件
runat=server
这意味着您将能够从页面后面的 aspx 代码(.cs、.vb 等)访问它。因此,如果您想要更改特定属性,例如NavigateURL
属性,您可以这样做。Short answer - yes - a hyperlink control renders as
<a>
so you could do this:See the MSDN regarding this server control:
http://msdn.microsoft.com/en-us/library/k0b15efk(v=vs.71).aspx
Anytime a control is
runat=server
this means you will be able to access it from the aspx code behind page (.cs, .vb, etc). So if you ever want to change a specific property, such as theNavigateURL
property you could do so.由于您已经设置了
runat="server"
属性,因此您可以通过其id
访问代码隐藏中的 HTML 控件:更新: 如果您想从代码隐藏创建 HTML,您可以按照 JonH 写道:
哦,请提高您的接受率。
Since you have already set the
runat="server"
attribute, you can access the HTML controls in your code-behind through itsid
:Update: If you want to create the HTML from the code-behind, you can do as JonH wrote:
Oh, and please increase your accept rate.