So, here's the thing.
on my .aspx page i have 2 divs. In div 1 i have 4 other divs (could be labels to, or somethign else ).
With JavaScript i then let the user drag (using help from JQuery ^^) the new divs from div1 to div2 and back.
Now, when i click a button I should know which div IDs are in div2(or which are not in div1)
To make it myself a bit easier to know which div is placed where (as divs aren't runat=server), i made an invisble ListBox(runat="server") where i keep copies of the divIDs that get dragged in div2.
Problem is that by the time it reaches the btn_click code in code-behind, the page has refreshed and thus the listbox is empty again, and there's nothing to get from there.
So somehow i must send the stuff from the listbox to the server-side BEFORE the page is refreshed and the listbox is clear... and i don't know how :crying:
My only requirement, and problem is that i do not want any postbacks untill the button is pressed.
Any ideas?
3 replies to this topic
#1
Posted 28 April 2010 - 11:19 AM
|
|
|
#2
Posted 28 April 2010 - 10:42 PM
well you could do this using a Hidden Field with ViewState enabled. i had a similar issue some day this solved mine!!
below code works for me
below code works for me
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Default Page</title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css" />
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="jquery-ui.min.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<style type="text/css">
#draggable { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script type="text/javascript">
function drag(){
$("#draggable").draggable();
document.getElementById("hd1").value = "Div dragged";
}
</script>
<div class="demo">
<div id="draggable" style="background-color:Gray" onclick="drag()">
<p>
Drag me around</p>
</div>
<asp:HiddenField ID="hd1" runat="server" />
<asp:Button ID="btnpost" runat="server" Text="PostBack" OnClick="btnpost_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
also in the Code Behind write this code
protected void btnpost_Click(object sender, EventArgs e)
{
if (hd1.Value == "")
{
Label1.Text = "you did not drag anything";
}
Label1.Text = "you dragged "+hd1.Value;
}
#3
Posted 29 April 2010 - 09:14 AM
Thank you very much! Last night, while i was trying to fall asleep, i came up with the idea that textboxes don't loose their text on postbacks, so instead of storing stuff in the listbox i may store IDs in the textbox.
So i was allready thinking of making an invisible textbox. A hidden field is basicly the same but probably more secure i suppose^^.
Been looking for a solution for the ListBox for hours...turns out that the main problem with the ListBox was that it's impossible to do a databind from JavaScript... Which makes sence in some way.
So i was allready thinking of making an invisible textbox. A hidden field is basicly the same but probably more secure i suppose^^.
Been looking for a solution for the ListBox for hours...turns out that the main problem with the ListBox was that it's impossible to do a databind from JavaScript... Which makes sence in some way.
#4
Posted 30 April 2010 - 12:56 AM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









