简体   繁体   中英

Send a variable from vb.net to javascript

I have some problems when i send the value variable in visual basic net to javascript, for example: this code:

Partial Class borrador1 // The code in aspx
Inherits System.Web.UI.Page

public myVariable As string

public sub MyMethod()
  myVariable ="Hello World"
end sub

 Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
   MyMethod()
 end sub

In the next part i try to recive the value in javascript

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
 <script type="text/javascript">
  var variable = '<%= myVariable%>';

 </script>

 <body>
 </html>

I load the page and i see the next problem in the browser: [HttpException (0x80004005): Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.] Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +437 Telerik.Web.UI.RadAjaxControl.PerformRender() +419 Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) +1450 Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +197 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +131 System.Web.UI.Page.Render(HtmlTextWriter writer) +40 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +150 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5363

thanks for yours comments.

It seems that you need to register the script. Here is a link for your exact issue you are having. Happy coding!

Thanks my friend, but I resolve my problem. I use the controls telerik UI for ASP.NET AJAX, especific the charts, result the panel have a conflicts when i pass the variable, i comment the line (<%-- --%>) or write a function in jquery wait to load all the controls and when finish send the variable to javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM