Ajax Div positioning
I have an aspx page with ajax panel on it and a button. this is my button :
<asp:Button ID="Button1" runat="server" OnClientClick="javascript:SetValues()" onclick="Button1_Click" Text="Button" />
when 开发者_StackOverflow社区I click on the button I call the SetValues() function on the OnClientClick event. this function will change the position of the div on the screen. the Button1_Click method is running on the server and loading the div with data.
The problem is that the work that "SetValues()" did is canceled because the div after comming back from the server, is going back to it's original position on the screen.
What are you trying to make happen server side? Have you considered doing an ajax postback to send/process your data on the server? This will allow your client side JS to change the UI, while the server receives and process your data.
Check out this article for more information on using jQuery to trigger server side processing.
One option would be to call SetValues() after the ajax panel has updated (I'm assuming you are using an UpdatePanel here).
<script type="text/javascript">
function EndRequestHandler(sender, args) {
if (args.get_error() == undefined)
{
SetValues();
}
else
{
alert("There was an error" + args.get_error().message);
}
}
function load() {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}
</script>
You will need to fire the load function when the page has loaded to register for the Javascript event.
<body onload="load()">
Use a hidden server control and read/write values from the hidden control. Values will be persisted across post back.
精彩评论