[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HiddenField value not being set

Posted on 2011-10-14
3
Medium Priority
?
762 Views
Last Modified: 2012-05-12
I am trying to retrieve 4 hiddenfield values from a page that are being set using JCrop. Standard HTML input 'text' fields are being set with the correct values but not ASP:HiddenField items.

Either the JS setting the values on the HiddenFields is not correct or it is my call to retrieve the value that is incorrect...

Dim xpos As Integer = CInt(X.Value)

errors telling me;

System.FormatException: Input string was not in a correct format. This is I THINK because it is blank!

Thaks in advance
<script language="Javascript" type="text/javascript">
	    jQuery(document).ready(function () {
	        jQuery('#cropbox').Jcrop({
	            aspectRatio: 1,
	            onSelect: updateCoords,
                onChange: showCoords,
                onSelect: showCoords,
                onChange: updateCoords
		    });
	    });

	    function updateCoords(c) {
	        jQuery('#X').val(c.x);
	        jQuery('#Y').val(c.y);
	        jQuery('#W').val(c.w);
            jQuery('#H').val(c.h);
		};

		function showCoords(c) {
		    jQuery('#x1').val(c.x);
		    jQuery('#y1').val(c.y);
		    jQuery('#x2').val(c.x2);
		    jQuery('#y2').val(c.y2);
		    jQuery('#w2').val(c.w);
		    jQuery('#h2').val(c.h);
		};
    </script>

<img src="/uploads/users/temp/<%=Request.Querystring("FileName") %>" id="cropbox" alt="Crop image"/><br />
                <label>X1 <input type="text" size="4" id="x1" name="x1" /></label>
			    <label>Y1 <input type="text" size="4" id="y1" name="y1" /></label>
			    <label>X2 <input type="text" size="4" id="x2" name="x2" /></label>
                <label>Y2 <input type="text" size="4" id="y2" name="y2" /></label>
                <label>W <input type="text" size="4" id="w2" name="w" /></label>
                <label>H <input type="text" size="4" id="h2" name="h" /></label>
                <asp:HiddenField ID="X" runat="server" />
                <asp:HiddenField ID="Y" runat="server" />
                <asp:HiddenField ID="W" runat="server" />
                <asp:HiddenField ID="H" runat="server" />


 Protected Sub btnCrop_Click(ByVal sender As Object, ByVal e As EventArgs)
        If IsPostBack Then
            Dim xpos As Integer = CInt(X.Value)
            Dim ypos As Integer = CInt(Y.Value)
            Dim width As Integer = CInt(W.Value)
            Dim height As Integer = CInt(H.Value)

            Dim NewImage As Image = Bitmap.FromFile(Server.MapPath("/uploads/users/temp/") & "\" & Request.QueryString("FileName"))
            Dim BMP As Bitmap = New Bitmap(width, height, NewImage.PixelFormat)
            Dim g As Graphics = Graphics.FromImage(BMP)
            g.DrawImage(NewImage, New Rectangle(xpos, ypos, width, height), New Rectangle(xpos, ypos, width, height), GraphicsUnit.Pixel)
            BMP.Save(Server.MapPath("/uploads/users/") & "\" & Request.QueryString("UserID") & ".jpg", NewImage.RawFormat)
            CroppedImage.Visible = True
            CroppedImage.ImageUrl = "~/uploads/users/" & Request.QueryString("UserID") & ".jpg"
        End If
    End Sub

Open in new window

0
Comment
Question by:swgdesign
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 2000 total points
ID: 36967987
You need access asp.net control like below

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

    function showCoords(c) {
        jQuery('#<%=x1.ClientID%>').val(c.x);
        jQuery('#<%=y1.ClientID%>').val(c.y);
        jQuery('#<%=x2.ClientID%>').val(c.x2);
        jQuery('#<%=y2.ClientID%>').val(c.y2);
        jQuery('#<%=w2.ClientID%>').val(c.w);
        jQuery('#<%=h2.ClientID%>').val(c.h);
    };
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36967997
One mistake in above. showCoords should be your original one since it is simple html control i.e.

function showCoords(c) {
        jQuery('#x1').val(c.x);
        jQuery('#y1').val(c.y);
        jQuery('#x2').val(c.x2);
        jQuery('#y2').val(c.y2);
        jQuery('#w2').val(c.w);
        jQuery('#h2').val(c.h);
    };
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36968110
Debug the JS function updateCoords before postback. If it not set then the hidden fields value will be blank. This can't be converted into int. However use TryParse method of type for conversion.

http://www.dotnetperls.com/integer-tryparse-vbnet

If it is blank then set default values as per your need.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question