[英]How to pass a full asp.net control or HTML tags from server code in C# to a specific place in HTML design?
I'm not sure if this is even possible, but I wonder if I can generate a full control that its tags are stored in a text property to HTML page.我不确定这是否可能,但我想知道我是否可以生成一个完整的控件,它的标签存储在 HTML 页面的文本属性中。 let's say that I have an
<asp:Image....... />
or <div><i href=""/></div>
as a Text, and it is stored in a property named X in.cs file
, and I want this X to be placed in a specific line in the Html page.假设我有一个
<asp:Image....... />
或<div><i href=""/></div>
作为文本,它存储在名为X in.cs file
,我希望将此 X 放在 Html 页面的特定行中。
is that possible?那可能吗?
in.cs file let's say I have something like this in.cs 文件假设我有这样的东西
X = @"<asp:Image ID = ""Image111"" runat = ""server"" ImageUrl = ""img.jpg"" />";
and in the HTML file I want this:在 HTML 文件中,我想要这个:
<body>
<form id="form1" runat="server">
.
<!-- X comes here but as a real control -->
.
.
.
</form>
I'm not sure if it is possible but I wish to find a way to do this, any way.我不确定这是否可能,但我希望找到一种方法来做到这一点,无论如何。
Thanks in advance, best regards.提前致谢,致以最诚挚的问候。
I would change the way youre thinking about this.我会改变你对这件事的看法。 Sounds like what you want to do is create a server control then pass some sort of parameter into that control which will then change the output accordingly.
听起来你想要做的是创建一个服务器控件,然后将某种参数传递给该控件,然后相应地更改 output。 If you were using razor you can also have helpers which would handle this sort of thing.
如果您使用的是 razor,您还可以使用助手来处理此类事情。
This might be of interest.这可能很有趣。
Pass data from a ASP.NET page to ASCX user controls loaded dynamically 将数据从 ASP.NET 页面传递到动态加载的 ASCX 用户控件
Hope that helps.希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.