views:

63

answers:

2

I have read many different resources but am still not sure if this is possible without using AJAX.

I have a javascript function that loads a div into a modal and says "Loading Please Wait" I have named this funciton loadingModal()

function loadingModal(url)
{
     loadModal(...)
}

What I need to do is only trigger this after I have verified that the password and username are correct on the server side so:

btnSubmit_OnClick(object sender EventArgs e)
{
     string usr;
     string password;

     if (verify(usr, password))
     {
          ///// TRIGGER JAVASCRIPT HERE
          LOAD TONS OF SESSION VARIABLES
          .
          .
          .
      }
      else
         Show Error and Definitely Don't ever mention still loading
 }

I know I could just attach an onclientclick call to the javascript however it would load the loading modal even if it was an invalid username and password

Can I trigger javascript mid execution from the server side?

+3  A: 

Can I trigger JavaScript mid execution from the server side?

No. JavaScript code is evaluated on the client-side (in the browser), long after the server-side has finished processing the request. Client-side and server-side scripts are run at different places and at different times. There cannot be that kind of direct interaction.

You could use AJAX, if you do not want to trigger a full page refresh. When you use AJAX, your client (the browser) will issue a fresh new request to the server. The server processes this request (checks username and password, for example) and returns a response (access denied or access granted) back to the client. It is then up to the client to handle the response appropriately.

Daniel Vassallo
That's what I thought, thanks for the succinct and straight answer.
Seth Duncan
+1  A: 

If you mean add javascript code to the page, see ScriptManager.RegisterStartupScript

BrunoLM