Solved

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

Posted on 2013-12-18
2
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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