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 7614837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:30:18+00:00 2026-05-31T02:30:18+00:00

One question I ask myself for a long time: below are 2 methods for

  • 0

One question I ask myself for a long time: below are 2 methods for passing parameters from my view to my javascript:

Method 1:

My view:

<script type="text/javascript">
    tabChangeConfirmationTitle = "@Html.Raw(UserResource.Warning)";
    tabChangeConfirmationMessage = "@Html.Raw(UserResource.TabChangeConfirmationMsg)";
</script>

My javascript file:

var tabChangeConfirmationTitle;
var tabChangeConfirmationMessage;

Method 2:

My view:

<script type="text/javascript">
    fctTranslationsForConfirmationDialog("@Html.Raw(UserResource.Warning)", "@Html.Raw(UserResource.TabChangeConfirmationMsg)");
</script>

My javascript file:

var tabChangeConfirmationTitle;
var tabChangeConfirmationMessage;

function fctTranslationsForConfirmationDialog(Title, Message) {
    tabChangeConfirmationTitle = Title;
    tabChangeConfirmationMessage = Message;
}

I prefer the 1st method. Is it a good one? Is there a better method?

Thanks.

PS: I know there are othere related questions but I would like your opinion on these two methods.

  • 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-05-31T02:30:20+00:00Added an answer on May 31, 2026 at 2:30 am

    I would go for a variation on method 1:

    js file:

    var p = {
        tabChangeConfirmationTitle: null,
        tabChangeConfirmationMessage: null
    };
    

    in your html head:

    <script type="text/javascript">
        document.onload = function() {
            p.tabChangeConfirmationTitle = "@Html.Raw(UserResource.Warning)";
            p.tabChangeConfirmationMessage = "@Html.Raw(UserResource.TabChangeConfirmationMsg)"
        };
    </script>
    

    this way your html doesn’t contain as much javascript and if you ever want to add more variables it’s very clean and easy how to do that; just add the variable to your p object in your js file and initialize it in your onload handler. Any other javascript then the onload initialization code can go in your js file and it doesn’t get cluttered by non javascript code.

    Also, by using the p object you create a namespace and avoid polluting the global namespace with more than 1 object.

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

Sidebar

Related Questions

A question I often ask myself, if you need to call one method on
one question I always ask myself is how is it possible that javascript has
This may not be the kind of question one should ask on StackOverflow, but
Hello every one I want to ask a question that what is simple exec
There may be more than one way to ask this question, so here's a
I have a model Question with a field called userid , before one ask
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
I happened to ask myself a question about arrays in c++. Well, we all
I would like to ask one question: How do i redirect requests to http://sub.example.com
One question about protected constructor. I learnt that the protected constructor can be used

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.