Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8400483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:34:15+00:00 2026-06-09T21:34:15+00:00

I have searched for a definitive answer to my question and not been able

  • 0

I have searched for a definitive answer to my question and not been able to find one. Lots a site cover the topic but I cannot find the answer I am looking for.

I have an ASPX page that, for example, processes customer queries. In the code behind I have a Customer class. If I want to use, for example, the customer ID and Name in a JavaScript function. What is the best way for me to do it?

I have this code (a website I have been asked to update) but I try to sort out all warnings VS displays and this code displays two.

<script type="text/javascript">
function DoSomeThingFunction(enable)
{
    var enableStr = enable ? "on" : "off";
    var intClientID = <%= Customer.ClientID %>;
    var strClientName = <%= Customer.ClientName %>;

    <!--
        More functionality
    -->

};
</script>

Expected expression on the following two lines..

var intClientID = <%= Customer.ClientID %>;
var strClientName = <%= Customer.ClientName %>;

I can update this code to stop the warnings..

<script type="text/javascript">
function DoSomeThingFunction(enable)
{
    var enableStr = enable ? "on" : "off";
    var intClientID = parseInt('<%= Customer.ClientID %>');
    var strClientName = '<%= Customer.ClientName %>';

    <!--
        More functionality
    -->

};
</script>

My question is: What is the best method of achieving this without getting any kind of warning? Does the best method mean I will get a warning and therefore have to put up with it? I hate to see warnings of any kind and try to fix them all.

Thanks for looking

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:34:16+00:00Added an answer on June 9, 2026 at 9:34 pm

    The first code block is how I have done it in the past. If the value is a string single or double quoted. Numbers are ok to not have quotes.

    Another approach is to use hidden fields in the page.

    <input type="hidden" id="customerId" value="1234" />
    <input type="hidden" id="customerName" value="John Doe" />
    
    <script type="text/javascript">
    function DoSomeThingFunction(enable)
    {
        var enableStr = enable ? "on" : "off";
        var intClientID = $('input#customerId').val(); //using jQuery to retrieve the value
        var strClientName = $('input#customerName').val();
    
        <!--
            More functionality
        -->
    
    };
    </script>
    

    I don’t worry about VS warnings, in fact I rarely look at them. Most of the time the code will still work as expected and especially when it comes to html, css and javascript the warnings are obsolete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

apologies if this has been asked before but I have searched the site... Anyway,
I have searched the internet looking for a definitive answer to the question of
I have searched for a general solution to this but only find answers to
I have searched around but have been unsuccessful in determining whether the following approach
I have searched stackoverflow for a question like mine but most of the questions
I have another WPF databinding question... one that I haven't found an answer to
So I've searched around and I couldn't find a definitive answer. I want my
OK, struggling to get a definitive answer to this one... I have an application
I have searched this site top to bottom yet have not found a single
I have searched countless of sites but havent come upon a definite answer. Maybe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.