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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:20:17+00:00 2026-05-13T14:20:17+00:00

Interesting situation. I have a Html.Textbox() that I render from a view as follows:

  • 0

Interesting situation. I have a Html.Textbox() that I render from a view as follows:

<%= Html.TextBox("title", Model.Title, new { @class = "txt" }) %>

In my controller, I have the following, somewhat simplified, validation on the title. For arguments sake, assume it finds the error, and re-renders the view with the modelstate error information.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditBook(string title) {
    Model = new Book(ControllerContext.RequestContext);
    if (String.IsNullOrEmpty(title))
    {
        title = String.Empty;
        ModelState.AddModelError("title", "* Title is a required");
        modelState.SetModelValue("title", ValueProvider["title"]);
    }
    else { // show confirmation }

    if (!ModelState.IsValid)
    {
        return View("EditBook", Model);
    }
}

When the page is re-rendered, my html text box correctly has the input-validation-error class attached to it… But it’s useless as it’s the first class attached! I need it to override all existing styles on my text box. The html output is as follows:

<input type="text" name="title" id="title" class="input-validation-error txt"/>

Assume the following css styles have been defined:

input.txt { border: 1px; color: #000 }
.input-validation-error { border: 2px solid #fff }

The problem is, my original css class “txt” takes precedence, and prevents me from being able to style the error text box correctly.

Any thoughts?

  • 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-13T14:20:17+00:00Added an answer on May 13, 2026 at 2:20 pm

    Instead of relying on the framework to render styles at all, I went with an approach where I could apply my own css classes, while still using much of the Html.ValidationMessage() infrastructure.

    Looks something like this:

    <% bool emailError = !String.IsNullOrEmpty(Html.ValidationMessage("email"));  %>
    <div id="EmailMod" class="module <%= emailError ? "error" : String.Empty %>">
        <label class="text_right">Email address</label>
        <div class="input">
            <input type="text" id="Email" name="Email" class="input" tabindex="1" />
            <p id="EmailRequired" class="required <%= emailError ? "" : "hide" %>">* Please enter a valid email address.</p>
        </div>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a partial view that inherits from ViewUserControl<Guid?> - i.e. it's model is
I just came across an interesting situation in JavaScript. I have a class with
Have an interesting situation: I have a foreign key from a.name (child table) to
I have an interesting situation where I need to deploy an ASP.NET MVC app
I have somewhat interesting development situation. The client and deployment server are inside a
I have, what I believe to be, an interesting situation at hand. I have
I have an interesting situation and I'm wondering if there is a better way
I have an interesting situation, and Google doesn't appear to have any information regarding
My colleague has found himself in an interesting situation. He is working on a
An interesting issue came up recently. We came across some code that is using

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.