nnnn
nnnn

Reputation: 1051

Show a Message Box after a Thread in ASP.net

I am a new to .Net.Please Help Me.
I have a button and one label in my aspx page , i would like to display text in label and after few seconds i would like to show message box on button click . My code is -

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblFirst" runat="server" Text=""></asp:Label> 
<asp:Button ID="btnClick" runat="server" Text="MyThread" 
       onclick="btnClick_Click" />
</ContentTemplate>
</asp:UpdatePanel>

and Code File-

protected void btnClick_Click(object sender, EventArgs e)
    {
        lblFirst.Text = "Thread Start!";

        Thread threadObj = new Thread(new ThreadStart(myThreadMethod));
        threadObj.Start();
    }

    public void myThreadMethod()
    {
        //Server Code that take long time..
        Debug.Write("Thread Ending");
        Page.ClientScript.RegisterStartupScript(GetType(),"msgbox","alert('End');",true);

    }

I got Label's Text Changing but Message Box was not shown.
Is it possible to show a Message Box ,after a thread?
How can I do this?
Thanks for your interests and replies.

Upvotes: 0

Views: 2203

Answers (3)

Nishant
Nishant

Reputation: 109

You can use System.Threading.Thread.Sleep(x);
Replace x by time in milliseconds.
After this you can use Button1.PerformClick();
where Button1 is the name of the button.

Upvotes: 0

R.D.
R.D.

Reputation: 7403

@Nyein Nyein Chan Chan:

   Response.Write("<script language='javascript'>alert('Your message is here.')</script>");

Upvotes: 0

JohnnBlade
JohnnBlade

Reputation: 4327

Use a backgroundworker, then add the event BackGroundWorker complete and in that event u add your messagebox

        BackgroundWorker bgw = new BackgroundWorker();

    // setup the anonymous event, this fires when the thread starts
    bgw.DoWork += (sender, e) =>
    {
        // do work here
    };

    // event when the thread has finished
    bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, e) =>
    {
        // set yr messagebox here
    });

Upvotes: 1

Related Questions