开发者

Misplaced sense of an ASP PlaceHolder control

I have a simple div on html, something like:

<div class="warning">
    <h3>Please make sure:</h3>
    <asp:PlaceHolder id="phWarnings" runat="server"></asp:PlaceHolder>
    <br />
    <a href="javascript:void(0)" onClick="$('#warning').hide()">Okay</a>
</div>

The PlaceHolder is being populated with a couple of radio buttons, a covering div, some h4 and p elements.

However, when the page shows up, the whole div (along with its children conten开发者_高级运维ts) are completely outside the warning div. I thought I was messing up the div structure in codebehind so I just commented out everything and did this:

phWarnings.Controls.Add(new LiteralControl("Meh"));

Guess what? Yeah, the string "Meh" was outside the warning div too. The HTML (on view source) option shows this:

<div class="warning">
    <h3>Please make sure:</h3>
    <br />
    <a href="javascript:void(0)" onClick="$('#warning').hide()">Okay</a>
</div>

Meh

I have done the similar things other times but never faced this problem. I was hoping you guys could shed some light on why placeholder decided to go out of parent div or how to avoid it. removing the class from warning div etc doesn't seem to work.

Any idea why this is happening please?


Things don't just happen, they happen for a reason. If they look as if they just happen, then that just means you don't know the reason... which is why you are asking. So...

The problem has to be with either your html or your css. As you don't give us much to go on, there isn't much that anyone can say.

You could put a page up, and provide a link to that, for people to look at the html and the css. No reason you can't do that.

Things to look out for in your css? floats that haven't been cleared for example.

Things to look out for in the Html? Unclosed tags.

You can diagnose the above kind of problem by right clicking on the offending area and doing "Inspect Element" when viewing the page in either Google Chrome or FireFox?

Are you assigning css classes using jquery or similar? Probably not, given your inline js code in the a tag...

All the above or a combination thereof are possible candidates, but in the absence of a page to look at, your not going to get much help.


I may not be correct but what i interpreted from the description is you are appending some HTML from code behind into your place holder.

If it is possible you can append the elements into your div through jquery.

$('div.warning').append("your content")


Just guessing here, are you overriding the page's render method? And ff you try and change the containing div to runat="server" what happens?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜