ASP.NET AJAX help

Associate
Joined
24 Jul 2003
Posts
1,420
Location
West Mids
I've never used the .NET AJAX controls before and I've come across a problem.

I have a hidden <div> inside an updatePanel that receives an update from a function in the code behind. The function gets results from a database and writes the results into this <div>.

I have a button that runs the server-side function and also an OnClientClick for the JavaScript to make the <div> visible and appear at the cursor location.

The problem is when the button gets clicked, the server side call appears to be resetting the styles applied to the div by the javascript function, even though the page is apparently NOT being posted back.

Code:
<asp:ScriptManager id="script1" runat="server" />
<asp:updatePanel id="update1" runat="server" UpdateMode="Conditional">
     <ControlTemplate>
          <div id="div_updateMe" runat="server" style="position:absolute; visibility:hidden; z-index:1;"></div>
          <asp:Button ID="Button2" runat="server" OnClick="getPages" Text="Client Click" OnClientClick="overlay(event, 'div_updateMe')" />
          </ControlTemplate>
     <Triggers>
          <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
     </Triggers>
</updatePanel>


//Code Behind


protected void getPages(Object sender, Eventargs e)
{
     //Database stuff goes here 

     div_updateMe.innerHtml = databaseResults;
}

The <div> appears for a split second but then vanishes, as if the page were posting back. Am I doing something wrong? :confused:
 
Found a sort of work around:

Added a hidden field to the page and written the database results to that and then set a timeout in the javascript function to keep checking the value of the this field and then display the div when it's not empty.

Feels like a kludge though...
 
Back
Top Bottom