1

I have an ASP webpage which I am trying to write some javascript in...

I want to set a variable to the response of a function - which is stored in my code behind (page.aspx.vb).

this is an example of what I am trying to do:

<script type='text/javascript'>
    var test ='<%GetTestName()%>'
</script>

I run this page - which does call the method GetTestName()... but does not set the variable 'test' to the response. In the dynamic view, I can just see that this line of JavaScript now says:

<script type='text/javascript'>
    var test =''
</script>

This method is used a number of times in this ASP listview control - and works fine. For example:

    <ItemTemplate>
        <div class="rlvI" style="height:100px; width:100px; margin-top:0px; margin-left:5px; margin-right:5px; margin-bottom:25px; background-color:<%# GetRowColor(Container.DataItem)%>; color:white">
            <asp:Button ID="SelectButton" runat="server" CausesValidation="False" CommandName="Select" CssClass="rlvBEdit" Text=" " ToolTip="Select" />
             <asp:Label ID="measure" runat="server" Text='<%# Eval("measure")%>' />
            <br />
             <asp:Label ID="actualLabel" runat="server" Text='<%# String.Concat("A: ", Eval("actual"))%>' />
            <br />
            <asp:Label ID="budgetLabel" runat="server" Text='<%# String.Concat("B: ", Eval("budget"))%>' />
            <br />
        </div>
    </ItemTemplate>

Is this not possible in javascript? And if not can you suggest a better way to do it?

Thanks in advance.

2 Answers 2

1

It should be:

<script type='text/javascript'>
    var test ='<%=GetTestName()%>'
</script>

Note the '=' sign.

Sign up to request clarification or add additional context in comments.

Comments

1

If you add <System.Web.Services.WebMethod()> to your function signature, you can use PageMethods to call the method from javascript as so.

<System.Web.Services.WebMethod()>_
Public Shared Function MethodName()
    'dostuff
End Function

You will also have to add a Scriptmanager to your page.

<script language="javascript" type="text/javascript">
function functionName()
{
    PageMethods.MethodName();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.