This is a migrated thread and some comments may be shown as answers.

Send variable from vb net to javascript

3 Answers 1533 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Fabio Cirillo
Top achievements
Rank 1
Fabio Cirillo asked on 29 Nov 2012, 10:40 AM
Hi,
i've a web page write with vbnet 2010, how do to send the value of a variable from vb net to javascript?
 
thanks bye

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Nov 2012, 12:05 PM
Hi,

One suggestion is that to make your server variable as Public Property and access it in java script as follows.

JS:
<script type="text/javascript">
    function OnClientClick() {
        var serverVariable = '<%= ServerVariable %>';
        alert(serverVariable);
    }
</script>

Hope this helps.

Regards,
Princy.
0
Fabio Cirillo
Top achievements
Rank 1
answered on 29 Nov 2012, 02:22 PM

Not work, I blank, I did so

Public Property _image As String
Private Sub Imgbtnupload_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) Handles Imgbtnupload.Click
        _image = "/public/image_profile/" & RadUpload1.UploadedFiles.Item(0).FileName
End Sub
function Close_and_load() {
    var _image = '<%= _image %>'; 
    GetRadWindow().close(_image);
}
0
rdmptn
Top achievements
Rank 1
answered on 03 Dec 2012, 11:34 AM
The server code block is evaluated with the rendering of the page. If you are using AJAX and you change the server variable this will not affect the script if it is not included in the AJAX request. What I'd suggest you do is to register a script from the code-behind and populate some global variable with the value you need (e.g. the ScriptManager.RegisterStartupScript() method). Or, simply use a hidden field.
Tags
General Discussions
Asked by
Fabio Cirillo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Fabio Cirillo
Top achievements
Rank 1
rdmptn
Top achievements
Rank 1
Share this question
or