第三方的webcontrol生成以下代码来显示自己:
<div id="uwg">
<input type="checkbox" />
<div>blah-blah-blah</div>
<input type="checkbox" />
</div>
是否可以将其更改为
<div id="uwg">
<input type="checkbox" disabled checked />
<div>blah-blah-blah</div>
<input type="checkbox" disabled checked />
</div>
当我们点击
<asp:CheckBox id="chk_CheckAll" runat="server" AutoPostBack="true" />
位于同一页面上?
我们需要在服务器端(在 ASP.NET 中)执行此操作。
该第三方控件没有为此提供接口,因此唯一的可能性是使用 html 输出。我应该处理哪个页面事件(如果有)?另外,是否有一些相当于 DOM 模型的东西,或者我需要将输出作为字符串处理?
当复选框不在服务器上运行或封装在控件内部时,我们可以使用以下方法:
protected override void Render(HtmlTextWriter writer)
{
// setup a TextWriter to capture the markup
TextWriter tw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(tw);
// render the markup into our surrogate TextWriter
base.Render(htw);
// get the captured markup as a string
string pageSource = tw.ToString();
string enabledUnchecked = "<input type=\"checkbox\" />";
string disabledChecked = "<input type=\"checkbox\" disabled checked />";
// TODO: need replacing ONLY inside a div with id="uwg"
string updatedPageSource = pageSource;
if (chk_CheckAll.Checked)
{
updatedPageSource = Regex.Replace(pageSource, enabledUnchecked,
disabledChecked, RegexOptions.IgnoreCase);
}
// render the markup into the output stream verbatim
writer.Write(updatedPageSource);
}
解决方案取自here.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)