如何使用HtmlTextWriter c#在div中编写html代码 [英] How to write html code inside a div using HtmlTextWriter c#

查看:268
本文介绍了如何使用HtmlTextWriter c#在div中编写html代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序我必须使用htmltextwriter在特定div中编写我的html代码。



现在我可以将它简单地写入源代码但我有把它写在div里面。我怎样才能做到这一点。 div应该在源代码中使用runat =server我必须使用c#调用该div并将我的html文本绑定到它。

I have a application i have to write my html code inside a particular div using htmltextwriter.

Now i can write it simply to the source code but i have to write it inside a div. How can i do that. The div should be in the source code with runat="server" i have to call that div using c# and bind my html text in to it.

推荐答案

Hi Udayams ,



这是用于创建我们项目中使用的单选按钮的示例代码段,

将其作为参考

Hi Udayams,

This is sample snippet to create radio button which is used in our project,
take it as reference
StringWriter stringWriter = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(stringWriter);
htw.AddAttribute(HtmlTextWriterAttribute.Id, ClientID);
            htw.AddAttribute(HtmlTextWriterAttribute.Type, "radio");
            htw.AddAttribute(HtmlTextWriterAttribute.Name, GroupName);
            htw.AddAttribute(HtmlTextWriterAttribute.Value, Value);
            if (Checked)
                htw.AddAttribute(HtmlTextWriterAttribute.Checked, "checked");
            if (!Enabled)
                htw.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");

            string onClick = Attributes["onclick"];
            if (AutoPostBack)
            {
                if (onClick != null)
                    onClick = String.Empty;
                onClick += Page.GetPostBackClientEvent(this, String.Empty);
                htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
                htw.AddAttribute("language", "javascript");
            }
            else
            {
                if (onClick != null)
                    htw.AddAttribute(HtmlTextWriterAttribute.Onclick, onClick);
            }

            if (AccessKey.Length > 0)
                htw.AddAttribute(HtmlTextWriterAttribute.Accesskey, AccessKey);
            if (TabIndex != 0)
                htw.AddAttribute(HtmlTextWriterAttribute.Tabindex,
                    TabIndex.ToString(NumberFormatInfo.InvariantInfo));
            htw.RenderBeginTag(HtmlTextWriterTag.Input);
            htw.RenderEndTag();



除了代码之外,你可以选择链接 [ ^ ]以获取更多参考。

希望这对你有所帮助。



问候,

RK


Other than code, you can go for this link[^] for more reference.
Hope this helps you a bit.

Regards,
RK


这篇关于如何使用HtmlTextWriter c#在div中编写html代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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