0

i have java script in my page and i want to call it from vb.net code behind from function AND didn't want to call it (onload or onclick or any similar event) but i want to call it from function doing looping.so it will be run more one time

5
  • 1
    ?! ...Do you have a code snipped / example of what you try to do? Commented May 8, 2012 at 10:22
  • 4
    Younds like you did not understand the difference between clientside and serverside code. Commented May 8, 2012 at 10:23
  • 1
    This is not possible. Code behind = server side, javascript = client side. Commented May 8, 2012 at 10:23
  • example: in my page aspx i add javascript that get value of element by id <script type="javascript">function getval(elemntid) mycode;</script> and in my vbcode the function is : public function() for i = 0 to 5 (i want to call javascript here...) next i end function Commented May 8, 2012 at 10:41
  • this is most certainly possible. Commented May 8, 2012 at 12:25

2 Answers 2

3

You need to do it like this:

 ' Define the name and type of the client scripts on the page. 
    Dim csname1 As [String] = "PopupScript"
    Dim cstype As Type = Me.[GetType]()

    ' Get a ClientScriptManager reference from the Page class. 
    Dim cs As ClientScriptManager = Page.ClientScript

    ' Check to see if the startup script is already registered. 
    If Not cs.IsStartupScriptRegistered(cstype, csname1) Then
        Dim cstext1 As New StringBuilder()
        cstext1.Append("<script type=text/javascript> getval('elementid') </") 'Your javascript function
        cstext1.Append("script>")

        cs.RegisterStartupScript(cstype, csname1, cstext1.ToString())
    End If

Source.

Sign up to request clarification or add additional context in comments.

2 Comments

Whomever downvoted this had no reason to do it. This is exactly what the OP is asking and it will definitely work.
thanks,but can i use it direct in my function in behind code to run it or putting it in page load to register it only
0

This is actually possible using SignalR.

https://github.com/SignalR/SignalR

Very cool stuff.

A persistent connection sounds like it would do what you are looking for.

https://github.com/SignalR/SignalR/wiki/PersistentConnection

1 Comment

thanks for your answer but i don't understand how can i use it in my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.