Hello all,
With the help of this community, I've been able to pass a static chunk of text from javascript (clientside) to ASP 3.5 (server side)! This piece of code works beautifully:
$('.drop').droppable({
tolerance: "touch", // Here should be a string
drop: function() {
$('[id$="myHidden"]').val('Testy test test');
__doPostBack('<%= HiddenButton.UniqueID %>', '');
alert($('[id$="myHidden"]').val());
}
});
What the above does, is when an element with the class of .drop is dropped, it will assign the string "Testy test test" to my hidden field on my aspx page. Then it does a postback to an invisible button I have that is within an updatepanel. The hidden button's click event fires, which throws up a msgbox displaying the contents of the hidden element, which invariably are "Testy test test".
Now here is where I'm having some problems. Of whatever I drop into the dropzone, instead of setting the hidden field's value to a static string, I want to set it to the ID of whatever it was I dropped into the dropzone. This is what I changed:
$('[id$="myHidden"]').val($(ui.draggable).attr("id"));
__doPostBack('<%= HiddenButton.UniqueID %>', '');
alert($('[id$="myHidden"]').val());
Now all of a sudden, when I drop something it stays glued to the dropzone, and no drop event fires. Did I break something? Or am I trying to get the ID of the dropped element the wrong way?
In case it matters, here is the relevant aspx page stuff:
<asp:Button ID="HiddenButton" runat="server" Text="Button" />
That button is typically hidden via css, I just left it unhidden for now for testing purposes.
EDIT!!!!:
I tried this as well, and it does not work (so I can rule out the 'var' thing?)
var foo = $(ui.draggable).attr("id")
$('[id$="myHidden"]').val(foo);
__doPostBack('<%= HiddenButton.UniqueID %>', '');
alert($('[id$="myHidden"]').val());