【发布时间】:2014-02-27 17:02:56
【问题描述】:
我有一个 webforms 项目,并且对转发器控件不熟悉,并注意到一些基于元素类型的非常奇怪的定位行为。我不确定是我还是什么。在我的项目模板中,我有一个链接按钮和一个带有多个控件的 div(我在 div 和文本框上设置了这种样式,目的是为了突出问题):
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="repeater_cmd" >
<ItemTemplate>
//this link button sets the visibility of the div below
<asp:LinkButton id ="clr_div" CommandName="nav-to-page" runat = "server">
</asp:LinkButton>
//this div has its visibility set by the link button
<div ID="rdiv" runat= "server" style = "width:700px; background:white; height:100px;">
<asp:TextBox ID="text1" style = "width:700px;height:1px;" runat="server">
</asp:TextBox>
</div>
</ItemTemplate>
</asp:Repeater>
我的物品命令:
protected void repeater_cmd(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "nav-to-page")
{
//hide any open divs
for (int i = 0; i < Repeater1.Items.Count; i++)
{
RepeaterItem item = Repeater1.Items[i];
item.FindControl("rdiv").Visible = false;
}
//then show our div
e.Item.FindControl("rdiv").Visible = true;
}
}
现在是奇怪的部分——无论我点击哪个链接按钮,div 显示在中继器顶部的链接按钮后面,文本框直接显示在链接按钮下方我点击了!我只想让我的整个 div 显示在我刚刚点击的按钮下方。更糟糕的是,如果我查看标记,它会说文本框在 inside div 中,但它显然不是以这种方式呈现的。页面来源显示:
<div id="rdiv" style="width:700px; background:white; height:100px;">
<input name="ctl00$DetailsBoxHolder$Repeater1$ctl11$text1" type="text" id="text1" style="width:700px;height:1px;" />
</div>
它在页面上的样子(顶部链接按钮后面的div,被点击的链接按钮下方的文本框:
---- ---- ----
....- -....- -....- -....
. - - - - - - .
....- -....- -....- -....
---- ---- ----
---- ---- ----
- - - - - -
- - - - - -
- - - - - -
---- ---- ----
...........................
. .
...........................
我注意到,无论项目是作为内联元素还是块级元素呈现,所有元素都具有一些本机回发或输入属性,无论它是否s being used, get positioned correctly whereas those that dont
总是被放在中继器的第一行后面。所以按钮、文本框等(任何输入)都能正确定位。 Divs、spans、Panels 等都在顶部。我的问题是我需要某种面板或跨度,我可以在上面放置样式并将各种控件放入其中。救命!
【问题讨论】:
标签: c# asp.net webforms repeater