RegisterClientScriptBlock to register OUTSIDE form tags

Discussion in 'ASP .Net' started by Wes Weems, Jul 19, 2003.

  1. Wes Weems

    Wes Weems Guest

    Hello,

    I currently have javascript and vbscript that needs to be spat out based on
    certain conditions in the codebehind. My vbscript code relies on the OnLoad
    event. However with the RegisterClientScriptBlock(), sticking the code in
    the form tags, I cant seem to get the bastard to work.


    Basically heres what I *NEED* to do. Generate some js and vbscript to be
    output before or after the form tags.

    I tried defining the variables in the codebehind with the protected
    modifier... then setting them in Page_Load... and then doing <%=myVar%> and
    nothing gets spat out to the browser.

    If anyone could *PLEASE* give me any words of wisdom, they would be greatly
    appreciated.

    Wes
    Wes Weems, Jul 19, 2003
    #1
    1. Advertising

  2. Hi Wes, you might find that RegisterStartupScript does what you need since it
    runs on load or thereabouts.

    In your code behind:

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    Dim strName As String = "Wes"
    RegisterStartupScript("start", _
    "<script>sayHello('Hello " & strName & "');</script>")
    End Sub

    ' In your .aspx page:

    <script language="javascript">
    function sayHello(strMsg) {
    alert(strMsg);
    }
    </script>

    Ken
    MVP [ASP.NET]


    "Wes Weems" <> wrote in message
    news:...
    Hello,

    I currently have javascript and vbscript that needs to be spat out based on
    certain conditions in the codebehind. My vbscript code relies on the OnLoad
    event. However with the RegisterClientScriptBlock(), sticking the code in
    the form tags, I cant seem to get the bastard to work.


    Basically heres what I *NEED* to do. Generate some js and vbscript to be
    output before or after the form tags.

    I tried defining the variables in the codebehind with the protected
    modifier... then setting them in Page_Load... and then doing <%=myVar%> and
    nothing gets spat out to the browser.

    If anyone could *PLEASE* give me any words of wisdom, they would be greatly
    appreciated.

    Wes
    Ken Cox [Microsoft MVP], Jul 19, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Wagner

    Re: js script block outside form tags...

    Alex Wagner, Apr 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    479
    Joanne Shovelton
    Apr 20, 2004
  2. Jasper Pearlman

    Defining methods outside of script tags

    Jasper Pearlman, Aug 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    342
  3. Mark
    Replies:
    0
    Views:
    360
  4. Replies:
    0
    Views:
    418
  5. Krzysztof Poc

    outside type, outside function

    Krzysztof Poc, Feb 3, 2012, in forum: C++
    Replies:
    1
    Views:
    273
    Victor Bazarov
    Feb 7, 2012
Loading...

Share This Page