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

  • Home
  • SEARCH
  • 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 738277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:49:05+00:00 2026-05-14T07:49:05+00:00

With ASP.NET Webforms, I could drag and drop a control on a form and

  • 0

With ASP.NET Webforms, I could drag and drop a control on a form and be able to access its properties:

if (number == 0)
   AddButton.Enabled = false;

Although I cannot drag and drop a control on a ASP.NET MVC View template, can I change its attributes?

For instance:

  • disable a button in some conditions and be able to enable it if conditions change.
  • Be able to change the text of a button from “Next->” to “Finish”
  • etc.
  • 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-14T07:49:05+00:00Added an answer on May 14, 2026 at 7:49 am

    There are (at least) two Methods to do this:

    Method 1: The Simple Way

    You would do this by adding logic in your view:

    <input type="button" disabled=<%= Model.number <= 0 %> />
    

    Where Model.number is the count of items passed to your view by your controller. If it’s less than or equal to zero, disabled will be true.

    The syntax may not be exact, I haven’t tried this, but this is the path I would go down to do what you want.

    This will work for the initial setting of the value; changing it without refreshing the page is a matter of using JavaScript, as other answers have pointed out.

    Method 2: The overly complex but more ‘MVC’ way

    If you want the logic in the controller rather than the view, you should set up a specific ViewModel object that you can add the logic to:

    ViewModel

    public class MyObjectViewModel
    {
        MyObject MyObject {get; private set; }
        bool Enabled; {get; set; }
        public MyObjectViewModel(MyObject obj)
        {
            MyObject = obj;
        }
        string IsEnabled
        {
            get
            {
                 if (Enabled)
                 {
                     return "";
                 }
                 else return "disabled=disabled";
            }
        }
    

    Controller

    public ActionResult Show(int id)
    {
        MyObject myObject = repository.GetMyObjectById(id)
        MyObjectViewModel movm = myObject; 
        movm.Enabled = myObject.number > 0;
        return View(movm);
    }
    

    View

    <input type="button" <%= Model.IsEnabled %> />
    

    Again, the syntax and usage may be a little off, I’m prototyping this off the top of my head, and am not in a location where I can test this for you.

    If you’re interested in ViewModels, here are some good resources:

    • View Model Best Practices
    • ASP.NET MVC Tip# 50: Create View Models

    I’ve updated it to return disabled=disabled using the string if it is actually disabled.

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

Sidebar

Related Questions

I have an ASP.NET webforms application with a Menu control. How does one hide
In ASP.net Webforms how do you detect which Textbox someone pressed enter? Please no
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the
I am building a asp.net webforms (3.5 sp1) application, using jquery where I can
Duplicate: Should I pursue ASP.NET WebForms or ASP.NET MVC? We are developing an enterprise
So, I've spent enough time using ASP.NET webforms to know that I'd almost rather
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
I'm just starting my first project in ASP.NET MVC. In my webforms experience, I
I'm writing an ASP.Net webform with some DropDownList controls on it. Then user changes
When designing a ASP.net WebForm application what are some important steps to take (or

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.