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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:53:32+00:00 2026-05-27T05:53:32+00:00

Since there is no more code behind in .aspx pages in .NET MVC, It

  • 0

Since there is no more code behind in .aspx pages in .NET MVC, It seems impossible to declare a function or method direclty in the .aspx page (the view).

In classic ASP, I could add a script tag with runat=”server” to declare a local function.

Each client has its own view. The method in the controller send the right view to the right client.

What I’d like to do is to change some method logic depending of the client. Since this is highly dynamic,I don’t want to add a class or a method in the controller then rebuild and upload in production each time we have a new client.

So I thought of adding some logic directly in the view. Is this possible?

  • 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-27T05:53:33+00:00Added an answer on May 27, 2026 at 5:53 am

    In classic ASP, I could add a script tag with runat=”server” to declare a local function.

    I guess you mean in classic WebForms, because in classic ASP the runat="server" attribute doesn’t exist.

    So you could do the same in an ASP.NET MVC view using the WebForm view engine:

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
    
    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
        <script runat="server" type="text/C#">
            public string Foo()
            {
                return "bar";
            }
        </script>
    
        <div><%= Foo() %></div>
    
    </asp:Content>
    

    Now whether this is a good idea and if you should do it is an entirely different topic.

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

Sidebar

Related Questions

I have a small-scale WPF application using VB.net as the code behind and I
My requirement is to call WCF web service from ASP.NET code behind and pass
I'm writting an iPhone client that downloads stuff from the net. Since the cellular
I'd appreciate people's thoughts on a dilemma I've been struggling with ever since ASP.NET
The code below is more or less taken from the example MPMoviePlayerController sample code.
the problem i have is that i have multiple nested master pages: level 1
var keyword in C# is pretty useful, since it is much shorter to write
before I begin, there is another question with a similar title and it is
This is probably going to boil down to a philosophical question more than anything,
I am using C# and .NET 3.5 and have a GridView that I am

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.