I ran into a strange case this evening.  Rendered text can not be copied to the clipboard after posting back a page containing an UpdatePanel. 

Here’s a simple use case:

  1. User enters client name and clicks button to request phone number.
  2. Page posts back and displays phone number.
  3. User selects the phone number, CTRL+C and attempted to CTRL+V into their contact list.
  4. User gets frustrated because the phone number was selectable but apparently could not be copied.

One might assume only the phone number can’t be copied.  Maybe the changing of the text and visible properties of the associated ASP:Label control is to blame.  Well, that’s not the case.  ALL text on the page can no longer be copied after the postback. 

Basically, add an UpdatePanel to a page, postback and you can’t copy anything to the clipboard.  By the way, I discovered the problem while using FireFox 2.0. I tested against IE 7 and I wasn’t able to duplicate the experience.

Try out the most simplistic example I could come up with below.  It might surprise you.

<%@ Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
        <ProgressTemplate>
            <img id="Img1" runat="server" src="AjaxIndicator.gif"/>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:ScriptManager ID="scriptManager" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="updatePanel" runat="server">
        <ContentTemplate>
        <asp:Label ID="message" runat="server">
            This is asp:Label text inside the update panel
                and it can be selected and copied only
                before the postback but not after.</asp:Label>
        <br />
        <br />
            This is regular text inside the update panel
                and it acts the same.
        <br />
        <br />
        <asp:Button ID="button" runat="server" Text="Go" />
        </ContentTemplate>
    </asp:UpdatePanel>

    This text is outside of the update panel and
    it acts the same as well.

    </form>
</body>
</html>

kick it on DotNetKicks.com

4 Comments to “Copy/Paste Lost Due To UpdatePanel”

  1. Wonderful goods from you, man. I’ve understand your stuff previous to and you are just too fantastic. I actually like what you have acquired here, certainly like what you are stating and the way in which you say it. You make it entertaining and you still take care of to keep it sensible. I can not wait to read far more from you. This is really a tremendous web site.

  2. I was reading through some of your articles on this site and I conceive this website is rattling instructive! Continue putting up.

  3. I like this site so much, saved to my bookmarks. “To hold a pen is to be at war.” by Francois Marie Arouet Voltaire.

  4. I enjoy your writing style truly enjoying this internet site. “What a child doesn’t receive he can seldom later give.” by P. D. James.

Leave a Reply

You can wrap your code with [ruby][/ruby] or [python][/python] blocks for syntax highlighting and you can use these traditional tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>