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
-
1?! ...Do you have a code snipped / example of what you try to do?creativeby– creativeby2012-05-08 10:22:43 +00:00Commented May 8, 2012 at 10:22
-
4Younds like you did not understand the difference between clientside and serverside code.ThiefMaster– ThiefMaster2012-05-08 10:23:22 +00:00Commented May 8, 2012 at 10:23
-
1This is not possible. Code behind = server side, javascript = client side.Rory McCrossan– Rory McCrossan2012-05-08 10:23:56 +00:00Commented 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 functionDev.H– Dev.H2012-05-08 10:41:05 +00:00Commented May 8, 2012 at 10:41
-
this is most certainly possible.Jason C– Jason C2012-05-08 12:25:33 +00:00Commented May 8, 2012 at 12:25
Add a comment
|
2 Answers
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
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
Dev.H
thanks for your answer but i don't understand how can i use it in my problem