Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

get the position of an panel

Hi i have this code that get an div and needs to put above an panel to make the loading gif run. but this code was getting the position for an gridview instead of panel, i can't make it work with panels.


<script type="text/javascript" language="javascript">

    function onUpdating() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it visible
        updateProgressDiv.style.display = '';
        //  get the wizard element        
        var wizard = $get('<%= UpdatePanel2.ClientID %>');


        // get the bounds of both the wizard and the progress div
        var wizardBounds = Sys.UI.DomElement.getBounds(wizard);

        var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

        //    do the math to figure out where to position the element (the center of the gridview)
        var x = wizardBounds.x + Math.round(wizardBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
        var y = wizardBounds.y + Math.round(wizardBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
        //    set the progress element to this position
        Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
    }

    function onUpdated() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it invisible
        updateProgressDiv.style.display = 'none';
    }

</script>

Open in new window

0
rafaelrgl
Asked:
rafaelrgl
2 Solutions
 
MrunalCommented:
hi,
can you provide your aspx page design code?
It will help.

Also please have a look over this:

http://devarchive.net/update-progress-indicator.aspx
0
 
strickddCommented:
The code below will get the position of an object on the page relative to the top left corner. I included a sample call to the function, but you can pass in any object you want. Remember to use the "ClientID" of your controls because they can be changed when you move them around on the page.
getPosition(document.getElementById('<%= MyPanelID.ClientID %>'));


function getPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    finalvalue = leftValue + "," + topValue;
    return finalvalue;
}

Open in new window

0
 
rafaelrglAuthor Commented:
i want that div above the panel. this is so hard. pls help me see what am i doing wrong?
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" language="javascript">

    


    function getPosition(obj) {
        var topValue = 0, leftValue = 0;
        while (obj) {
            leftValue += obj.offsetLeft;
            topValue += obj.offsetTop;
            obj = obj.offsetParent;
        }
        finalvalue = leftValue + "," + topValue;
        return finalvalue;
    }

    function onUpdating() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it visible
        updateProgressDiv.style.display = '';
         //  get the wizard element        
        var wizard = getPosition(document.getElementById('<%= UpdatePanel2.ClientID %>'));


        // get the bounds of both the wizard and the progress div
        var wizardBounds = Sys.UI.DomElement.getBounds(wizard);

        var updateProgressDivBounds = Sys.UI.DomElement.getBounds(updateProgressDiv);

        //    do the math to figure out where to position the element (the center of the gridview)
        var x = wizardBounds.x + Math.round(wizardBounds.width / 2) - Math.round(updateProgressDivBounds.width / 2);
        var y = wizardBounds.y + Math.round(wizardBounds.height / 2) - Math.round(updateProgressDivBounds.height / 2);
        //    set the progress element to this position
        Sys.UI.DomElement.setLocation(updateProgressDiv, x, y);
    }

    function onUpdated() {
        // get the update progress div
        var updateProgressDiv = $get('updateProgressDiv');
        // make it invisible
        updateProgressDiv.style.display = 'none';
    }

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="clearfloat"></div>
     <div id="default_submenu">
         <table style="width: 100%;">
             <tr>
                 <td style="width: 100%;"></td>
                 <td></td>
                 <td></td>
                 <td></td>
                 <td></td>
                 <td style="text-align:right;">
                     <uc8:SimpleSearch ID="SimpleSearch1" runat="server" />
                 </td>
             </tr>
         </table>
     </div>     <div class="clearfloat"></div>
     <div>
         <table style="width: 100%;">
             <tr>
                 <td id="default_col_left">
                    <div style="padding-top : 0px; padding-left : 0px;">
                      <T4>Esqueceu seu Password?</T4>
                     <p>
                         Você não pode lembrar seu password? Sem Problema!
                         <br />
                         <br />
                         Preencha alguns dos campos abaixo que nós enviaremos uma mensagem para seu e-mail
                         <br />
                         que especifica-ra como renovar seu password.
                         <br />
                         <br />
                         Por favor entre com seu e-mail ou nome de usuário informado quando você efetuou seu cadastro.
                     </p>
                         <br />
                         <asp:UpdatePanel ID="UpdatePanel2"  ClientIDMode="AutoID" runat="server">
                             <Triggers>
                                  <asp:AsyncPostBackTrigger ControlID="btn_forgotpassword" EventName="Click" />
                             </Triggers>
                             <ContentTemplate>
                                 <asp:Panel ID="panelrecoverpassword"  DefaultButton="btn_forgotpassword" runat="server">
                                    <table>
                                         <tr>
                                             <th align="left" style="width: 130px;">
                                             </th>
                                             <th align="left" style="width: 450px;">
                                             </th>
                                         </tr>
                                         <tr>
                                             <td>
                                                 Email ou usuário:</td>
                                             <td>
                                                 <asp:TextBox ID="TxtEmail" runat="server" SkinID="txtnormal" Width="300px" ValidationGroup="forgotpassword"></asp:TextBox>
                                             </td>
                                         </tr>
                                         <tr>
                                             <td>
                                                 &nbsp;</td>
                                             <td>
                                                 &nbsp;</td>
                                         </tr>
                                         <tr>
                                             <td colspan="2">
                                                 <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Medium" 
                                                     ForeColor="Red"></asp:Label>
                                             </td>
                                         </tr>
                                         <tr>
                                             <td>
                                                 &nbsp;</td>
                                             <td style="text-align: right">
                                                 <asp:Button ID="btn_forgotpassword" OnClick="btn_forgotpassword_Click" runat="server" Text="Recuperar Senha" Height="46px" Width="170px" />
                                             </td>
                                         </tr>
                                     </table>
                                  </asp:Panel>
                             </ContentTemplate>
                        </asp:UpdatePanel>
                         <asp:UpdatePanelAnimationExtender ID="UpdatePanel2_UpdatePanelAnimationExtender" 
                            runat="server" BehaviorID="animation" TargetControlID="UpdatePanel2">
                                            <Animations>
                                                <OnUpdating>
                                                    <Parallel duration="0">
                                                        <ScriptAction Script="onUpdating();" />  
                                                        <EnableAction AnimationTarget="btn_forgotpassword" Enabled="false" />
                                                        <FadeOut minimumOpacity=".5" />
                                                     </Parallel>
                                                </OnUpdating>
                                                <OnUpdated>
                                                    <Parallel duration="0">
                                                        <FadeIn minimumOpacity=".5" />
                                                        <EnableAction AnimationTarget="btn_forgotpassword" Enabled="true" />
                                                        <ScriptAction Script="onUpdated();" /> 
                                                    </Parallel> 
                                                </OnUpdated>
                                            </Animations>
                        </asp:UpdatePanelAnimationExtender>
                     </div>
                 </td>
                 <td id="default_col_right">
                       <uc1:User_Login ID="Login1" runat="server" />
                 </td>
             </tr>
             </table>
     </div>
     <div id="updateProgressDiv" style="display: none;">
          <div style="text-align:center;">
             <asp:Image ID="Image1"  SkinID="Img_Loading01" runat="server" /> Loading...
          </div>
     </div>
</asp:Content>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now