JScripts on ASP.NET Master page?

javascript Poland
  • 13 years ago
    Hello,


    I have a problem to use JScript (I can't use JavaScript) on ASP.NET masterpage.

    when I use this script on ordinary ASP.NET page, it works ok.

    How can I use script like this on master page?

    <Script for="window" event="onload" language="jscript">

    if(window.form.txtSomeTextBox.value == "")
    {
     window.form.txtSomeTextBox.focus();
    }
    </Script>

    Thanks!







    Wojtek










  • 13 years ago
      Use like this..
     
    May be helpful....
    <HTML>
     <HEAD>
      <title>Ter_TicketDetails</title>


     
    <script language="javascript">
    function clientid(obj)
    function clientid(obj)
  • 13 years ago

    You should use ClientScript.RegisterStartupScript to be able to run scripts on the master page whithout having any problems on runtime.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", "<Script for=" + "window" + " " + "event=" + "onload" + " " + "language=" + "jscript" + ">" + "if(window.form.txtSomeTextBox.value == ""){ window.form.txtSomeTextBox.focus();}</Script>")

    '// To test it, just comment the above line and uncomment the line bellow.

    '// if the alert window is shown then it's working just fine!

    '// I've tested and works great!

    'ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", "<Script for=" + "window" + " " + "event=" + "onload" + " " + "language=" + "jscript" + ">" + "alert('works!');</Script>")

    End Sub
  • 13 years ago

    If i have a javascript function and i want to call that function instead of writing the entire script here,What will i do?

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens