Showing posts with label UpdatePanel. Show all posts
Showing posts with label UpdatePanel. Show all posts

Friday, 4 July 2014

Update Panel - Handle async partial-page state with client script

Leave a Comment
This is a sample script you can put at the master page. So that you dont need to have updatepanel progress every time you add the update panel in you aspx page.

Script 

<div id="pageUpdating"></div>

    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
        function BeginRequestHandler(sender, args) {
            //page is begin request, you can put code to lock screen etc.  
            writePageLoading();

        }
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler)
        function endRequestHandler(sender, args) {
            //page load successfully , end request  
            RemoveLoading();
            if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
                //if have error
                var errorMessage = args.get_error().message;
                alert(errorMessage + " . " + errorMessageAdditional);
            }
        }

        Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(pageLoadingHandler)
        function pageLoadingHandler(sender, args) {
            //page updating..
            writePageUpdating();
        }

        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedHandler)
        function pageLoadedHandler(sender, args) {
            //page loaded
            RemoveLoading();
        }

        //method to write loading indicator
        function writePageLoading() {
            var divPageUpdating = document.getElementById('pageUpdating');
            divPageUpdating.innerHTML = "<div id=\"loading\" style=\"position: absolute; top: 46%; left: 40%; width: 200px; z-index: 100000;\" class=\"PopupBackground\"><center><br /> <img src=\"images/loading.gif\" alt=\"page is updating\" /><br /><br/>Please Wait While Processing Your Request...</center></div>";

        }

        //method to remove any updating / loading indicator
        function RemoveLoading() {
            var divPageUpdating = document.getElementById('pageUpdating');
            divPageUpdating.innerHTML = "";
        }

        //method to write updating indicator
        function writePageUpdating() {
            var divPageUpdating = document.getElementById('pageUpdating');
            divPageUpdating.innerHTML = "<div id=\"loading\" style=\"position: absolute; top: 46%; left: 40%; width: 200px; z-index: 100000;\" class=\"PopupBackground\"><center><br /> <img src=\"images/loading.gif\" alt=\"page is updating\" /><br /><br/>Please Wait While System Updating Your Page...</center></div>";
        }
    </script>


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Sunday, 5 January 2014

Integrate Timer with UpdatePanel to async page update - ASP.NET

Leave a Comment
The Example show integration Timer with UpdatePanel to update page asynchronously.

The ASPX Page


   <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <!-- Interval time 5000 will be 5 second -->
                <asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick">
                </asp:Timer>
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
        <asp:UpdateProgress ID="UpdateProgress1" DisplayAfter="10" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <div style="position: absolute; top: 40%; left: 45%; background-color: #fffff0">
                    Please wait...
                </div>
            </ProgressTemplate>
        </asp:UpdateProgress>
    </div>

The Code Behind

 
protected void Timer1_Tick(object sender, EventArgs e)
{
     if (ViewState["updateTime"] != null)
     {
         Label1.Text = "Page update " + (Convert.ToInt16(ViewState["updateTime"]) + 1) + " times";
         ViewState["updateTime"] = (Convert.ToInt16(ViewState["updateTime"]) + 1).ToString();
     }
     else
     {
         Label1.Text = "Page update 1 times";
         ViewState["updateTime"] = "1";
     }
}


Output



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Friday, 23 August 2013

Button in UpdatePanel requires two / double clicks to fire - ASP.NET

Leave a Comment
Recently in my project i was implement Update panel for my page update the content. but then i found out that my button (inside) update panel need to click 2 times in order for event click to fire. So after do some testingi found the solution.

Here the simple solution to avoid button require double click  for event click to fire :
  1. Check on your page, is there any validator
  2. Set on the validator attribute "Display="Static"
  3. Try again your page, is the problem solved.?

example :


 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
 ErrorMessage="*"
 ControlToValidate="TextBox4" Display="Static" SetFocusOnError="true">
</asp:RequiredFieldValidator>

Other Thoughts:

Is there any javascript running on the button's client side onclick, onmousedown, onmouseup?Are you dynamically adding this button to the page?Do you set the  CheckBox's AutoPostBack property to True or False? If it is set to true, you might be in the middle of a async postback while you click the button.


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.