以编程方式访问在 ASP.NET 中创建的 Html 控件
你好呀。我在 asp.net 中的另一个 div 中创建了一个新的 div。现在我想使用新创建的div 的innerhtml 属性。我找不到方法..
这就是我在 .aspx 页面中所做的事情..
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="forNewEmployee" runat="server"></div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="link" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<div class="addMore">
<asp:Button ID="link" CssClass="label" runat="server" Text="Add More - Image"
onclick="link_Click" />
</div>
和代码隐藏文件中..
protected void link_Click(object sender, EventArgs e)
{
if (clickCheck != 0)
{
// access the newly generated div 'forNewEmployee' + specific id and call its innerHtml Method?
System.Web.UI.HtmlControls.HtmlControl div = (System.Web.UI.HtmlControls.HtmlControl)ScriptManager1.FindControl("forNewEmployee" + clickCheck);
}
else {
this.forNewEmployee.InnerHtml = newRow();
}
}
我有一个函数,在其中构建字符串以在 forNewEmployee div 中引入新元素。是这样定义的..
protected string newRow() {
// check for click
clickCheck++;
// check for new row
countForEmployee++;
// building our new row
rowString.AppendLine("<label for='empName" + countForEmployee.ToString() + "'>Your Employee Name: <span>(required)</span></label>");
rowString.AppendLine("<input id='empName" + countForEmployee.ToString() + "' class='registrationformEmployeeText' />");
rowString.AppendLine("</div>");
rowString.AppendLine("<div id='forNewEmployee" + countForEmployee.ToString() + "' name='forNewEmployee" + countForEmployee.ToString() + "' runat='server'></div>");
return rowString.ToString();
}
Hello there. I have created a new div inside another div in asp.net. Now I want to use the innerhtml property of that newly created div. I can't find a way..
This is what im doing in my .aspx page..
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="forNewEmployee" runat="server"></div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="link" EventName="click" />
</Triggers>
</asp:UpdatePanel>
<div class="addMore">
<asp:Button ID="link" CssClass="label" runat="server" Text="Add More - Image"
onclick="link_Click" />
</div>
and in codebehind file..
protected void link_Click(object sender, EventArgs e)
{
if (clickCheck != 0)
{
// access the newly generated div 'forNewEmployee' + specific id and call its innerHtml Method?
System.Web.UI.HtmlControls.HtmlControl div = (System.Web.UI.HtmlControls.HtmlControl)ScriptManager1.FindControl("forNewEmployee" + clickCheck);
}
else {
this.forNewEmployee.InnerHtml = newRow();
}
}
I have a function in which I'm building the string to introduce new elements inside the forNewEmployee div. This is how it is defined..
protected string newRow() {
// check for click
clickCheck++;
// check for new row
countForEmployee++;
// building our new row
rowString.AppendLine("<label for='empName" + countForEmployee.ToString() + "'>Your Employee Name: <span>(required)</span></label>");
rowString.AppendLine("<input id='empName" + countForEmployee.ToString() + "' class='registrationformEmployeeText' />");
rowString.AppendLine("</div>");
rowString.AppendLine("<div id='forNewEmployee" + countForEmployee.ToString() + "' name='forNewEmployee" + countForEmployee.ToString() + "' runat='server'></div>");
return rowString.ToString();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不完全确定您可以使用
div
做到这一点,但确定您可以使用asp:Panel
做到这一点:I'm not entirely sure you can do it with
div
but sure you can do it withasp:Panel
:最简单的事情是使用 asp .net 面板,并创建和添加 asp .net 控件(即使它们是文字控件)。
因此,基本上您的 NewRow 函数将是:
这样,您将能够使用您指定的控件 ID 执行 FindControl。
The easiest thing would be to use the asp .net panel, and create and add asp .net controls (even if they are literal controls).
So basically your NewRow function will be:
This way, you will be able to do a FindControl with Control ID that you specified.