Solved

Change an image in asp.net while stored procedure is running

Posted on 2013-12-18
2
340 Views
Last Modified: 2014-01-02
I have a stored procedure that is run from a single button click on an aspx page. I have the image change at the end when the stored procedure runs successfully. I want to change the image also WHILE the stored procedure is running. The image I want to change to is an animated gif.
    protected void btnSubmit_Click(object sender, ImageClickEventArgs e)
    {
        btnSubmit.ImageUrl = "~/images/cog.gif";

    try
    {
        System.Data.SqlClient.SqlConnection oConn = new System.Data.SqlClient.SqlConnection();
        System.Data.SqlClient.SqlCommand oCmd = new System.Data.SqlClient.SqlCommand();
        oConn.ConnectionString = ConfigurationManager.ConnectionStrings["man_pilotConnectionString"].ConnectionString;
        oConn.Open();
        oCmd.Connection = oConn;
        oCmd.CommandText = "aer_deactivate_recipes";
        oCmd.CommandType = CommandType.StoredProcedure;
        oCmd.Parameters.Add("@user", SqlDbType.VarChar, 25).Value = Label2.Text;
        oCmd.ExecuteNonQuery();
        oConn.Close();

        System.Data.SqlClient.SqlConnection oConn2 = new System.Data.SqlClient.SqlConnection();
        System.Data.SqlClient.SqlCommand oCmd2 = new System.Data.SqlClient.SqlCommand();
        oConn2.ConnectionString = ConfigurationManager.ConnectionStrings["fin_pilotConnectionString"].ConnectionString;
        oConn2.Open();
        oCmd2.Connection = oConn2;
        oCmd2.CommandText = "AER_UPDATE_PART_UOM_CONVERSIONS";
        oCmd2.CommandType = CommandType.StoredProcedure;
        oCmd2.ExecuteNonQuery();
        oConn2.Close();

        btnSubmit.ImageUrl = "~/images/Halo.gif";
        Label1.Text = "Wasn't that easy??";

    }
        
    catch (Exception ex)
        {
            btnSubmit.ImageUrl = "~/images/failure.jpg";
            Label1.Text = "Woops. Something went awry: " + ex.Message;
        }
    }

Open in new window

The image at the end changes successfully when the stored procedure is finished, but it takes several seconds for the sproc to run. I put the image change as the first action on the button click, before the sproc starts. I have also tried putting as the first action under the try block. What am I missing to get this image to change while the stored procedure is running?

Ultimately, I also want to get the page to play a sound when everything is finished. This is an application that is run once per year on January 1st and I try to make it "fun" and "different" every year since they have to work on the 1st.
0
Comment
Question by:Hers2keep
2 Comments
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 500 total points
ID: 39728537
OK, I think there is a misunderstanding about how web pages work.

When the user presses a button, the page request is submitted to the server.  The browser then waits for the server to process the request.  Your code and the stored procedure are executed before any results are sent back to the client.  What you have to understand is that there actually isn't an active streaming connection between the server and browser while the page is being processed on the server.  The browser won't show the page until the server is done processing the page and sends the results back to the browser.

What you are trying to do is not how web pages were designed!

Your results can be achieved but it's really tricky to do using some clever JavaScript and an IMG tag that executes an ASPX page instead of retrieving an image.  Many people don't realize that the src for an IMG tag can actually execute a page on the server.
<img src="http://mysite/mywebpage.aspx" />

Or you can look at using the UpdateProgress control in AJAX.

Sorry but it would take me an hour to write out a detailed example and I don't have time to do it.  I'm a volunteer.  I can point you in the right direction, however you need to find a good example on the web yourself.
0
 

Author Comment

by:Hers2keep
ID: 39751758
I found a work-around to achieve almost the same thing as I originally wanted. The only difference was I didn't change the image WHILE the query was running, but only changed it after it finished.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# replace string in void with dR["myData"].ToString() 3 39
Linq Help 1 33
C# Offline Apllication 5 48
Export import database 4 39
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 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

18 Experts available now in Live!

Get 1:1 Help Now