2
我有我寫的服務器控件,它通常工作正常。但是,當我加入突出顯示的行時,它不會添加一個,而是兩個<br />
元素,這不是我所追求的。服務器控件行爲奇怪
mounting=new DropDownLabel();
mounting.ID="mountTypeList";
mounting.Attributes.Add("class", "mounting");
mounting.Values=Configuration.MountTypes.GetConfiguration().Options;
mounting.Enabled=Utilities.UserType == UserType.Admin;
mounting.Value=value.Reference;
td1.Controls.Add(mounting);
**td1.Controls.Add(new HtmlGenericControl("br"));**
var span=new HtmlGenericControl("span");
span.Attributes.Add("class", "mountDescription");
span.ID="mountDescription";
td1.Controls.Add(span);
對我在做什麼有什麼想法嗎?
ETA:
我已經通過增加使用jQuery的BR,這我使用反正有解決的情況。但我看到的行爲肯定是錯誤的。如果我添加一個元素,它應該添加該元素,而不是該元素的兩倍。
都能跟得上 - 這只是增加了與它BR跨度。生成的代碼只有正確的標籤,只有兩次。 –
謝謝,我遇到了同樣的問題,您的第二個解決方案解決了它。 – Marlon
Thanks,'div.Controls.Add(new LiteralControl(「
」);'爲我工作,在這個問題也類似的答案; http://stackoverflow.com/q/3095228/1847645 –