Category Archives: UpdatePanel

[RESOLVED] Loading please wait in VB.NET while gridview loads data

Hi,

I am trying to display the loading please message or a spinning image while a page loads data in a gridview. Users click on a link from one page and get redirected to another page via the response.redirect method. The new page loads some data in a gridview based upon some variables passed. Some times it could take up to 20+ seconds for the gridview to load. I have displayed loading please wait message previously using the jQuery, Post and ajax methods etc. In this case it's just straight VB.NET code that makes a sql connection to the server, executes a stored procedure and binds the returned data to the gridview. I would like the message or image to start showing once they click on the link to get redirected to the new page and continue to display till the gridview data has been loaded. Here is an example of the code:

Try
Dim cmd As SqlCommand = New SqlCommand("CustOrderHist", New SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"))
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("CustomerID", txtCustID.Text)
cmd.Connection.Open()
gvwExample.DataSource = cmd.ExecuteReader()
gvwExample.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try



Thanks

To avoid the loading time. What you can do is lazy load the gridview after the page is loaded using Updatepanel and Timer

This way your page will be loaded while the gridview will be populated later.

http://www.aspsnippets.com/Articles/Delay-Load-Lazy-Load-UpdatePanel-using-Timer-Control-in-ASP.Net.aspx 

Thank you, this trick seemed to work great for me.

[RESOLVED] Load another page without page refresh.

I have 2 pages (test1.aspx & test2.aspx). I have one button in test1.aspx, on click of it, I am loading test2.aspx, like Response.Redirect("test2.aspx"). It refreshes the browser/ page and load test2.aspx.

What I have to do is, I have to load test2.aspx without any page/ browser refresh.

 

 

Thanks,

Whenever any brand new page loads , it will refresh the browser.

You may develop  test2.aspx in a UserControl & load it in a UpdatePanel

That I know. I can use iframe too and can set the source of iFrame to test2.aspx, but I am looking for solution without iframe or UserControl.

 

Thanks, 

Not sure but i think ive done something like that with javascript before without it posting back the page

'Build a javascript alert
                'please note the peculiar '/script' in the last line of the script string
                'This is to work around the problem that compiler would mistake the
                'closing script tag as the outer script closing tag.
                Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder
                sb.Append("<script language='javascript'>")
                sb.Append("window.open('alertsAgent.aspx?MU_ID=" & MU_IDstring.ToString & "&Site=" & SiteString.ToString & "&firstname=" & firstnameString.ToString & "&surname=" & surnameString.ToString & "&username=" & usernameString.ToString & "', 'Alerts', 'width=680,height=300,fullscreen=no,scrollbars=1,resizable=0,status=1,dependent=yes,alwaysRaised=yes');{ self.close() };<")
                sb.Append("/script>")


                'register with ClientScript


                Dim t As Type = Me.GetType
                If Not ClientScript.IsClientScriptBlockRegistered(t, "redirectAgentScript") Then
                    ClientScript.RegisterClientScriptBlock(t, "redirectAgentScript", sb.ToString)
                End If


 

You need to take advantage of ASP.NET Ajax partial page refreshing, or use iFrame inside your page to trigger the test2.spx inside your test1.aspx.

Or may be try using JQuery/JTemplate/JSON to load a page w/o flicker. 

Try like this...use HttpWebRequest class, get the html response and then make a jquery call to this function and try to replace the complete form with the html content which you get to jquery....

i never tried it....but there might be performance concerns, i dont know yet...but it might work...

PS - have you tried MultiView control...look at that may be it might fit your requirement...

Thanks.

function LoadPage() {
            window.location = "test2.aspx";
            return false;
        }


// call this function by button client clcik




 <asp:Button ID="btnClick" runat="server" OnClientClick="return LoadPage();" />


You can achieve this same things by javascript function with below code.

[RESOLVED] display real time data in label using MS acccess database

Hi,

 

I need to display the real time data in the label.

Explain In detail: 

The camera is counting the people and store the counted value in database every minute.

so i need to pick the data and display it same on the screen. There are lot of cameras counting. So i need to take camera number and display respective count.

 

Camera NUmber Counted Value
1 Label1(Display realtime data here)
2 Label2

Can anybody advice me how and which way i can achieve this

Thanks in advance

If you want to do it in WebApp. Do it with AJAX controls. Add a ScriptManager control on top, add update panel and labels in it to update from database. Add a AJAX timer control for continuous update at specified interval.

Hi,

Thanks for your reply

I did the same its shows an error : the name 'label1' doesnt exists in current context

I explain my code here:

<div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:ScriptManager ID="ScriptManager1" runat="server"></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </asp:ScriptManager> </div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditionals></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        <ContentTemplate></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            <asp:Timer ID="Timer1" runat="server" Interval="1000"></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            </asp:Timer></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </ContentTemplate></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </asp:UpdatePanel></div>

 <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager> 

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditionals>

        <ContentTemplate>

            <asp:Timer ID="Timer1" runat="server" Interval="1000" onTick="Timer_Click">

            </asp:Timer>

            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </ContentTemplate>

        </asp:UpdatePanel>


I check all way but still its through the same error. I'm using multiple UPDATEPANEL.

I'm using  15 updatepanel along with the timer to refresh and label to display data. But at .cs file i have used 

public void Timer_Click(object sender, EventArgs e)

{

  Dbcommection_Method();

Label1.Text = data ;

}


HERE it throughs "Label1" doesnt contain in current context


Thanks a lot

I think this is a Designer issue....delete the label control and re-add to the page....if still problem persists, then try by creating a new page and add controls one by one....

Thanks.

[RESOLVED] Enumerate Buttons Controls on Page

Hi,


I have created a load of dynamic buttons in an update panel. I do this so that there is one button for each client name in my DB. I want to then go through a list of these buttons and change the colour of them depending on another value retrieved from my database.

How can I get a list of the buttons that have been created on my update panel. What would be the best method to update the colour as soon as they have been created? Would I use the preRender to create the button objects and then use the form load to update their colour or is there a better way of doing this?

Cheers


Charles

You can get al the controls in the UpdatePanel using UpdatePanel.Controls collections....

http://msdn.microsoft.com/en-us/library/system.web.ui.updatepanel.controls.aspx

Then you can use Foreach loop to actually get individual controls....

or else you can also use UpdatePanel.FindControl() too

http://msdn.microsoft.com/en-us/library/486wc64h.aspx

Thanks.

[RESOLVED] How to activate javascript function from Page_Load and updatepanel

Hi..

In the first Page_Load, I am activating a javascript function to make an ImageButton change between 2 images with an interval.

This works fine.

 

Now when pressing this imagebutton, the Page_Load event will fire the second time and all this is happening in an updatepanel which means a partial postback.

 

The question is how to execute the javascript function stopbk() in the Page_Load event in this scenario as I cant just put it in the "Onload". How can I make that work?

Code is below:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SecondLoad"] != null)
        {
            //How to activate stopbk() ?
            Label1.Text = "Second Load";
        }


        if (Session["SecondLoad"] == null)
        {
            Label1.Text = "First Load";
            Session["SecondLoad"] = "dummy";
            body1.Attributes.Add("Onload", "startbk()");
        }
    }
    protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
    {
        //
    }






<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>




<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<script type="text/javascript">
    var TimerProps = {
        refTimer: null,
        index: 0
    }
    function startTimer() {
        if (TimerProps.index > 1) {
            TimerProps.index = 0;
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/inboxKuvert.jpg";
            TimerProps.index += 1;
        }
        else {
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/Transparent.gif";
            TimerProps.index += 1;
        }
    }
    function startbk() {
        TimerProps.refTimer = setInterval("startTimer()", 550)
    }


    function stopbk() {
        clearInterval(TimerProps.refTimer)
    }
</script>


<asp:ImageButton ID="ImageButton6" runat="server" Height="12px" Width="16px"
 ImageUrl="http://www.abc.com/images/inboxKuvert.jpg" onclick="ImageButton6_Click" />


    <br />
    <asp:Label ID="Label1" runat="server" Text="-"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>


 

ASPusers

The question is how to execute the javascript function stopbk() in the Page_Load event in this scenari

ScriptManager.RegisterStartupScript()....

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx

Thanks.

Thank you,

I have tried to understand the example but are not 100% sure of how the parameters should be set.

My attempt is as below but are not sure if I have done it correctly, I think I miss something?

Example:

RegisterStartupScript( Control control, Type type, string key, string script, bool addScriptTags );

 

My attempt:
RegisterStartupScript(ImageButton6, GetType(), "???", "stopbk()", true); 

It seems to work with the example below:

Thank you!

 

 

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SecondLoad"] != null)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "stopbk", "stopbk();", true);
            Label1.Text = "Second Load";
        }


        if (Session["SecondLoad"] == null)
        {
            Label1.Text = "First Load";
            Session["SecondLoad"] = "dummy";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "startbk", "startbk();", true);
        }
    }
    protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
    {
        //
    }




<script type="text/javascript">
    var TimerProps = {
        refTimer: null,
        index: 0
    }


    function startTimer() {
        if (TimerProps.index > 1) {
            TimerProps.index = 0;
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/inboxKuvert.jpg";
            TimerProps.index += 1;
        }
        else {
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/Transparent.gif";
            TimerProps.index += 1;
        }
    }
    function startbk() {
        TimerProps.refTimer = setInterval("startTimer()", 550)
    }
    function stopbk() {
        clearInterval(TimerProps.refTimer)
    }
    </script>