views:

324

answers:

1

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>
A: 

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!

Paul Creasey
This doesn't seem to address my needs at all - I'm looking for how to put an Editor control onto an UpdatePanel inside of a Repeater. I'm not using jQuery, and I don't see how CSS is applicable here.Could this have been meant for a different post?
Joe Enos
The <htmlz> is the editor control, you want to download the control code once, and insert it in many places (in this example, into all divs with the class myclass), then in order to access the the controls indivually you should use the the parent div id. it was not intended for another post! This is what you seem to be referring to in you 3rd paragraph, but im not familiar with page methods.
Paul Creasey
I think I see what you're talking about now - sorry I didn't see it at first. But if I understand correctly, your jQuery code would move the HTML from the original control into a new place. I've already tried this using regular javascript (see the edit at the bottom of my post), with no luck - my guess is due to the complexity of the control. I'd expect that using the jQuery syntax would have the same end result. Simple controls like TextBoxes move just fine, but something about the Editor makes it unfriendly to move around.
Joe Enos