Reputation: 197
I'm trying to crop an image using Jcrop. It's not working, I keep getting the exception "input string was not in correct format".
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#crop').Jcrop({
onSelect: updateCoords
});
});
function updateCoords(c) {
jQuery('#X').val(c.x);
jQuery('#Y').val(c.y);
jQuery('#W').val(c.w);
jQuery('#H').val(c.h);
};
<asp:Button ID="Submit" runat="server" Text="Crop"
onclick="Submit_Click" />
<asp:Image ID="Image" runat="server" Visible="False" />
<img src="Content/UploadedImage/Image.jpg" id="crop" alt=""/>
<asp:HiddenField ID="X" runat="server" />
<asp:HiddenField ID="Y" runat="server" />
<asp:HiddenField ID="W" runat="server" />
<asp:HiddenField ID="H" runat="server" />
Trying to get the cordinates
protected void Submit_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
int x = Convert.ToInt32(X.Value);
int y = Convert.ToInt32(Y.Value);
int w = Convert.ToInt32(W.Value);
int h = Convert.ToInt32(H.Value);
Upvotes: 2
Views: 1351
Reputation: 1
jQuery('#X').val(Math.round(c.x));
jQuery('#Y').val(Math.round(c.y));
jQuery('#W').val(Math.round(c.w));
jQuery('#H').val(Math.round(c.h));
Upvotes: 0
Reputation: 11
I was having the same problem, and solved it just making this:
var updateCoords = function(c) {
$('#x1').val(Math.round(c.x));
$('#y1').val(Math.round(c.y));
$('#x2').val(Math.round(c.x2));
$('#y2').val(Math.round(c.y2));
$('#w').val(Math.round(c.w));
$('#h').val(Math.round(c.h));
};
Upvotes: 1
Reputation: 9821
Well this code is what I use
In client I have this.. but I don't think it makes a problem
var updateCoords = function(c) {
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
On server "upload.ashx" generic handler i get the dimensions using
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim x As Integer = Integer.Parse(context.Request("x"))
Dim y As Integer = Integer.Parse(context.Request("y"))
Dim w As Integer = Integer.Parse(context.Request("w"))
Dim h As Integer = Integer.Parse(context.Request("h"))
Besides where do you get the error? on client or on server? and what is throwing it?
And it looks like you are trying to get form values after postback, which do not exist any more because by that point the page has been re init without its original values.. because that is how .NET page rendering process works.
So you either have to save the vairables to Session in memory, postback the values to itself and retrieve them using Request.Form or send the data using GET method and retrieve the values like i have
Upvotes: 1