简体   繁体   中英

Passing javascript variable to VB.Net

I have the code needed to pass a variable from javascript to vb.net, but it is not working for some reason and I can't seem to figure out what is wrong with the code. Please help. I declared a hidden variable and it stores the value and is then posted back, but the variable in the codebehind file is always empty.

Aspx code ( EDITED: )

            <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication3.WebForm1" %>

            <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

            <!DOCTYPE html>

            <html xmlns="http://www.w3.org/1999/xhtml">
            <head runat="server">
                <title></title>
            </head>
            <body>
                <form id="form1" runat="server">
                           <asp:HiddenField ID="nwLatHidden" runat="server" Value="" />
                           <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                               <Scripts>
                                   <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                                   </asp:ScriptReference>
                                   <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                                   </asp:ScriptReference>
                                   <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                                   </asp:ScriptReference>
                               </Scripts>
                           </telerik:RadScriptManager>
                           <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                           </telerik:RadAjaxManager>
                           <telerik:RadHtmlChart runat="server" ID="RadHtmlChart1">
                                <Legend>
                                    <Appearance Position="Bottom">
                                        <TextStyle FontSize="14" Color="Blue" FontFamily="Courier New, sans-serif" />
                                    </Appearance>
                                </Legend>
                                <PlotArea>
                                    <XAxis>
                                        <Items>
                                            <telerik:AxisItem LabelText="KM41872"/>
                                            <telerik:AxisItem LabelText="KM41873"/>
                                            <telerik:AxisItem LabelText="KM41871"/>
                                        </Items>
                                        <MajorGridLines Visible="false" />
                                        <MinorGridLines Visible="false" />
                                    </XAxis>
                                    <YAxis>
                                        <MinorGridLines Visible="false" />
                                    </YAxis>
                                    <Series>
                                        <telerik:LineSeries Name="Mean">
                                            <SeriesItems>
                                                <telerik:CategorySeriesItem Y="0.59" />
                                                <telerik:CategorySeriesItem Y="0.63" />
                                                <telerik:CategorySeriesItem Y="0.6" />
                                                <telerik:CategorySeriesItem Y="0.65" />
                                                <telerik:CategorySeriesItem Y="0.64" />
                                                <telerik:CategorySeriesItem Y="0.63" />
                                                <telerik:CategorySeriesItem Y="0.65" />
                                                <telerik:CategorySeriesItem Y="0.67" />
                                                <telerik:CategorySeriesItem Y="0.63" />
                                            </SeriesItems>
                                        </telerik:LineSeries>
                                        <telerik:LineSeries Name="Min">
                                            <SeriesItems>
                                                <telerik:CategorySeriesItem Y="0.55" />
                                                <telerik:CategorySeriesItem Y="0.56" />
                                                <telerik:CategorySeriesItem Y="0.55" />
                                                <telerik:CategorySeriesItem Y="0.61" />
                                                <telerik:CategorySeriesItem Y="0.56" />
                                                <telerik:CategorySeriesItem Y="0.57" />
                                                <telerik:CategorySeriesItem Y="0.59" />
                                                <telerik:CategorySeriesItem Y="0.61" />
                                                <telerik:CategorySeriesItem Y="0.55" />
                                            </SeriesItems>
                                        </telerik:LineSeries>
                                        <telerik:LineSeries Name="Max">
                                            <SeriesItems>
                                                <telerik:CategorySeriesItem Y="0.66" />
                                                <telerik:CategorySeriesItem Y="0.74" />
                                                <telerik:CategorySeriesItem Y="0.66" />
                                                <telerik:CategorySeriesItem Y="0.71" />
                                                <telerik:CategorySeriesItem Y="0.72" />
                                                <telerik:CategorySeriesItem Y="0.73" />
                                                <telerik:CategorySeriesItem Y="0.71" />
                                                <telerik:CategorySeriesItem Y="0.74" />
                                                <telerik:CategorySeriesItem Y="0.71" />
                                            </SeriesItems>
                                        </telerik:LineSeries>
                                    </Series>
                                </PlotArea>
                            </telerik:RadHtmlChart>
                </form>
                <script type="text/javascript">
                    document.getElementById('nwLatHidden').value = '6.00';
                </script>
            </body>
            </html>

Codebehind: Public Class WebForm1 Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            Dim nwLat As String
            nwLat = nwLatHidden.Value.ToString


    End Sub

    End Class

try this

document.getElementById('<%=nwLatHidden.clientID').value = '6.00';

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