Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8178591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:48:17+00:00 2026-06-06T23:48:17+00:00

I have made a user control that allows an image to be uploaded and

  • 0

I have made a user control that allows an image to be uploaded and then cropped, but when I have several of these controls on one form, only the last one added will work correctly. The issue is the function storeCoords, has no effect on the X,Y, W and H hidden fields, thus when the crop ‘rubber band’ is moved, these values do not change. With the final control added, as the ‘rubber band’ is moved, the hidden fields are updated, and everything then works as expected. Why when I have several of these controls on one page does only the last one’s javascript work as expected.

<script src="/Controls/ImageUploadAndCrop/Javascript/jquery.Jcrop.min.js" type="text/javascript"> </script>
<link href="/Controls/ImageUploadAndCrop/CSS/jquery.Jcrop.min.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    $(window).on('load', function ()
    {

        var elem = $('#<%= CropImage.ClientID %>'),
            boxWidth = elem.width(),
            boxHeight = elem.height();

        elem.Jcrop({
            onSelect: storeCoords,
            boxWidth: boxWidth,
            boxHeight: boxHeight
        });

        $('#<%=CropButton.ClientID%>').click
        (
            function ()
            {
                var cropImg = $('.jcrop-holder img');

                $('#<%= ImgWidth.ClientID %>').val(cropImg.width());
                $('#<%= ImgHeight.ClientID %>').val(cropImg.height());
            }
        );
    });

        function storeCoords(c)
        {
            $('#<%= X.ClientID %>').val(c.x);
            $('#<%= Y.ClientID %>').val(c.y);
            $('#<%= W.ClientID %>').val(c.w);
            $('#<%= H.ClientID %>').val(c.h);
        }
 </script>
<div>
    <asp:Panel ID="UploadPanel" runat="server">
        <asp:FileUpload ID="Upload" runat="server" />
        <br />
        <asp:Button ID="UploadButton" runat="server" OnClick="UploadButton_Click" Text="Upload" />
        <asp:Label ID="ErrorLabel" runat="server" Visible="false" />
    </asp:Panel>
    <asp:Panel ID="CropPanel" runat="server" Visible="false">
        <asp:Image ID="CropImage" runat="server"/>
        <br />
        <asp:HiddenField ID="X" runat="server" />
        <asp:HiddenField ID="Y" runat="server" />
        <asp:HiddenField ID="W" runat="server" />
        <asp:HiddenField ID="H" runat="server" />
        <asp:HiddenField ID="ImgWidth" runat="server"/>
        <asp:HiddenField ID="ImgHeight" runat="server"/>
        <asp:Button ID="CropButton" runat="server" Text="Crop" OnClick="CropButton_Click" />
    </asp:Panel>
    <asp:Panel ID="CroppedPanel" runat="server" Visible="false">
        <asp:Image ID="CroppedImage" runat="server" />
    </asp:Panel>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T23:48:21+00:00Added an answer on June 6, 2026 at 11:48 pm

    I see few problems with this control:

    1.

     var elem = $('#<%= CropImage.ClientID %>'),
                boxWidth = elem.width(),
                boxHeight = elem.height();
    

    Shouldn’t these lines to be followed by a semi-colon “;” and not a comma? But maybe is a typo.

    2.

    Because you are using this control in several places of the page, you need to take care of the “duplicate” appearances of any JavaScript code:

    For example the following <script> tag will appear every time you the control is added to the page.

    <script src="/Controls/ImageUploadAndCrop/Javascript/jquery.Jcrop.min.js" type="text/javascript"> </script>
    

    This however won’t do anything bad to functionality (I think?!), but the following function will do for sure, because the JavaScript will have more copies of the same function with the same arguments. Which one is considered?

    function storeCoords(c)
            {
                $('#<%= X.ClientID %>').val(c.x);
                $('#<%= Y.ClientID %>').val(c.y);
                $('#<%= W.ClientID %>').val(c.w);
                $('#<%= H.ClientID %>').val(c.h);
            }
    

    A quick fix would be:

     elem.Jcrop({
                onSelect: storeCoords<%= CropImage.ClientID %>,
                boxWidth: boxWidth,
                boxHeight: boxHeight
            });
    

    And

    function storeCoords<%= CropImage.ClientID %>(c) { ... }
    

    In this way you’ll have unique function names.

    However ASP .Net has mechanisms to handle user controls which use JavaScript. See ClientScriptManager

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I did is, I have made 2 user controls. One control is inside
I have a made a simple UserControl that allows a user to drag a
Let me explain my situation. I have made a user control that contains an
I have a user control on a form that can spawn several non-modal child
I have a custom user control that I made called OrderForm.ascx . I also
I have a Windows form user control that is made COM visible. Now I
I have made an application that gives the user the option to open up
I have made an application in android that lets the user compress and decompress
I have made an app that implements the iPhone's camera. When the user finishes
I have made Catifier.com recently, and once the user sets their own background image,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.