Conditional Javascript Call

  • Thread starter Thread starter TCORDON
  • Start date Start date
T

TCORDON

Is there a way to conditionally call a Javascript when a Page loads, say: if
txtMyText.text <> string.empty then <Javascript>? Or should it all be calles
using Javascript?

TIA!
 
You can, but since this is on PostBack you could easily check this clientside
before the PostBack occurs...
If you are trying to so some sort of validation then I would do it will all
Javascript and stop the PostBack from occuring at all....
 
I'm confused by your question.

When the page loads server side, why would you want to call Javascript from
code behind ??
 
I think you are looking for RegisterStartupScript ..

in your Page_Load()

string jscript = "<script>alert("1234");</script>";

if(txtMyText.text.Length > 0)
{
Page.RegisterStartupScript("somename", jscript );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top