开发者

Add an Editor control dynamically inside of a repeater using AJAX

I'm looking for a way to add an Editor control (from the ASP.NET AJAX Control Toolkit) to each element of a repeater. It's working fine if I just include it in the ItemTemplate of the repeater, but my problem is that the markup it produces is massive, which slows down the page considerably (even with compression on).

I haven't had any luck adding the control inside the repeater item using an Update Panel - I think this is probably the preferred method, but dynamically adding a control inside an Update Panel inside of a Repeater Item isn't something I've had any success doing, and there don't seem to be any good examples of this that I can find.

The other alternative I considered was using PageMethods to render the control and send the HTML back to the page to let the javascript put it in the appropriate place, then deal with it, but it won't let me render the control - I get an InvalidOperationException of "Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.". 开发者_如何转开发 My guess is that all the javascript that's generated makes it so that I can't just render an Editor control on the fly.

Can you point me in the right direction for accomplishing this?

Thanks

EDIT: Another alternative, if it is possible, would be to put a normal Editor control in the markup of the page, then move it around inside of the repeater as needed, using javascript. I can do this with normal controls, but when I do it with an editor, it is not behaving nicely - the textbox appears, but won't let me click inside it. If you have any ideas on this one, I'd appreciate that as well. Here's the code for this:

<span id="spanHiddenEditor" style="display: block;">
    <cc1:Editor ID="ed1" runat="server" Height="200" Width="400" />
</span>
<script type="text/javascript">
    function createTextBox(idx) {
        var span = $get("span1_" + idx); // this gets me the target location
        var hiddenEditorSpan = $get("spanHiddenEditor")
        var editorHtml = hiddenEditorSpan.innerHTML;
        hiddenEditorSpan.innerHTML = "";
        span.innerHTML = editorHtml;
    }
</script>


identify the location within the repeater with a class then use jquery to inser the html on page ready

$(function() {  
        $(".myclass").Append("<htmlz>");
}); 

Then if you need to identify each text box you can do it using the parent container ID eg.

$("#myID div.class input").value

I'm a total jquery newb so none its likely none of it will work, but i believe the idea is a good one!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜