Solved

get the position of an panel

Posted on 2010-08-17
3
412 Views
Last Modified: 2012-05-10
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
Comment
Question by:rafaelrgl
3 Comments
 
LVL 22

Accepted Solution

by:
Mrunal earned 250 total points
ID: 33463890
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
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 250 total points
ID: 33464498
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
 
LVL 1

Author Comment

by:rafaelrgl
ID: 33471446
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wrapper for APPs 9 76
using php variable inside javascript 5 27
How to convert from xls to xlsx using java 7 34
Select case on click 3 13
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now