开发者

Why won't the variable pass from aspx.vb to aspx?

I've read lots of similar threads about the same issue but the fixes aren't working for me.

I'm declaring my variable as Public in the Class area of my code behind page and assigning a value to it in the Page_Load subroutine, but when I call that variable in the aspx page within a javascript function, the error states that 'BC30454: Expression is not a method'.

aspx.vb page

Partial Class Act_Page

Inherits System.Web.UI.Page
Public aname As String

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

    DisplayActInfo()

    aname = Request.QueryString("an开发者_Python百科ame")

Javasctipt in aspx page

<script type="text/javascript">

var aname2 = <%aname%>;

Any ideas?

Cheers, Rob.


It should be:

var aname2 = "<%=aname%>";

You forgot the = sign, plus forgot to wrap this in quotes which would have resulted in client side script error.

Anyhow, that's not the best practice way.. while working, it's the "classic ASP" way. ASP.NET offers new ways to send data from server side to client side code:

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "aname", "var aname = \"" + Request.QueryString("aname") + "\"; ", true);

This is C# but can be easily converted to VB.NET as well, and will have the same effect without spaghetti code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜