|
I have retreived the position of the dynamic controls in the hiddenfields (present in usercontrol) using javascript on the content page(.aspx) now I am willing to store their postions in to the viewstate (in user control) before base.SaveViewState(); and get the position of the controls from viewstate after base.LoadViewState(savedState); so that they may not loose their positions.
Any help will be appreciable.
|
|
|
|
|
Only answer that i can think of is: Why? What are you trying to do?
No more Mister Nice Guy... >: |
|
|
|
|
|
Why not just store the position in the DOM? and have the DOM do your work for you. elements just don't loose their positions, unless you move the element in the DOM, and want to return it back.
|
|
|
|
|
Dear can you just send me a example of that. So that i can get the clear picture of what you are suggesting. I'll highly obliged if you can do this favour to me.
|
|
|
|
|
When a browser makes a request for a web page, the html code is downloaded to the client, and stored in your computers memory by the browser, which is called the DOM. You can manipulate the DOM using Javascript, JQuery or Microsoft AJAX.
So in Javascript at the top of the page, you can make a global var like declaring variables in a class outside of the functions in c# or vb
var global_X = 0;
var global_Y = 0;
function getPosition() {
global_X = lalala();
global_Y = lalala();
}
function setPosition() {
}
|
|
|
|
|
Below is the details of what i'm trying to do.
Details:
I'm creating draggable panels making the use of Ajax DargPanelExtender.
DragPanelExtender & the Panel which i'm making draggable are in a usercontrol within a update panel.
Now, on the content page (.aspx page) I have a button & a Update panel. Within this update panel I'm adding usercontrol from code behind. (Note: Button is outside the update panel)
The draggable panels(usercontrol) added on the content page is working fine.
Earlier when I was creating the successive draggable panels on the click event of the button the previous draggable panels were disapperaring (or loosing) so I am re-creating the draggable panels(usercontrol) on OnInIt event which is also working fine.
On the Usercontrol I'm also having two hiidenfields for storing the x & y positions of the usercontrol respectively.
I'm retrieving the x & y positions of the usercontrol into the hiddenfields (present in the usercontrol) using javascript which I have registered on the aspx.cs page using RegisterClientScriptBlock. Which is also working fine I'm able to get the position of each usercontrol into the hiddenfields on onmousedown event( being fired while drag and drop) . Checked via populating the x & y positions present in the hiddenfields into a alert box.
Now, issue is that while I'm re-creating the usercontrols saved in a Generic type I want to set the Left and Top property of the control using the values present in the hiddenfields corresponding to each usercontrol as in the code below so that they may retain their positions on the AsyncPostBack
string hdfposX_val = "(" + controlToAdd.ID + "_hdfPosX"+").Value";
controlToAdd.Attributes.Add("style", "position:absolute;left:" +hdfposX_val+ "px" + ";");
which is not working.
(Note : each usercontrol and its containing hiddenfield controls are having unique ids viz.
usercontrol-> controlToAdd.ID = "usercontrol_" + Guid.NewGuid().ToString();
usercontrol_hiddenfield_position_X-> " + controlToAdd.ID + "_hdfPosX"+"
usercontrol_hiddenfield_position_Y-> " + controlToAdd.ID + "_hdfPosY"+")
Any help from your side will be appreciable.
|
|
|
|
|
I think your trying to fix something that doesn't need fixing.
The dragable panels should be created first and set in position.
Then the update panels should be inside the dragable panels, so use multiple update panels and multiple triggers.
Each draggable panels should be an independent unit, that is self contained, with all the plumbing inside them.
If you put the draggable panel inside a update panel, on async-postback, the server won't know that you changed the position of the panel, and put them back in the original location, where ever they were hard coded to when the server sent the html to the browser the first time.
So make the draggable panels first, test them. Then put a update panel inside the panel, and add your content and logic, then test again. It should work in theory.
I don't use update panels anymore, ditched them for javascript and web services. I also stopped using Microsoft Ajax extenders, in exchange for jquery and javascript instead.
|
|
|
|