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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:34:12+00:00 2026-05-13T15:34:12+00:00

I have an HTML table where each row has buttons which toggle status bits

  • 0

I have an HTML table where each row has buttons which toggle status bits in the database for each row. Assuming Javascript is not an option, what would be the “best practice” way of handling this?

I’m currently handling it by wrapping each row in a form like this:

<table>
    <tr>
        <td>
            <form action="/FooArea/BarController/BazAction" id="frm0" name="frm0" method="post">
                 <span>Item 1</span>
                 <input type="submit" value="Toggle1" name="submitButton"  />
                 <input type="submit" value="Toggle2" name="submitButton"  />
                 <input type="hidden" name="itemID" value="1" />
            </form>
        </td>
    </tr>
    <tr>
        <td>
            <form action="/FooArea/BarController/BazAction" id="frm1" name="frm1" method="post">
                 <span>Item 2</span>
                 <input type="submit" value="Toggle1" name="submitButton"  />
                 <input type="submit" value="Toggle2" name="submitButton"  />
                 <input type="hidden" name="itemID" value="2" />
            </form>
        </td>
    </tr>
</table>

And the post method looks something like this:

string buttonName = Request.Form["submitButton"];    
if (!String.IsNullOrEmpty(buttonName )) 
{
     int itemID = Convert.ToInt32(Request.Form["itemID"]);
     switch (buttonName )
     {
         case "Toggle1":
         DoSomething(itemID);
         break;

         case "Toggle2":
         DoSomethingElse(itemID);
         break;
     }
}

Any better suggestions? Is having 50 forms on a page cool? I dunno.. let me know what you are doing in this case.

  • 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-13T15:34:13+00:00Added an answer on May 13, 2026 at 3:34 pm

    The best way to handle POST scenarios without JavaScript is, as several others have stated, a tiny form with only the necessary values, and only one submit button. Basically, what you should do is to create a helper method that creates a form with the necessary POST values in hidden fields and a submit button. For example, you could have a method you use like this:

    <%= Html.PostLink("FooArea/BarController/BazAction", "Toggle1", new List<KeyValuePair<string, string>>{ new KeyValuePair<string, string>("itemId", 1), new KeyValuePair("action", "option1") }); %>
    

    It looks pretty verbose, but I’ve tried to make it as generic as possible. You can probably create the List<KeyValuePair<string, string>> in the controller when you render the view, so you only have to call something

     <%= Html.PostLink("FooArea/BarController/BazAction", "Toggle1", Model.Values) %>
    

    In the action method that handles the post, you bind to the posted FormCollection, and retrieve the values of itemId and action to determine what to do, instead of checking for Request.Form values.

    An implementation of the helper method might look like this:

    public static string PostLink(this HtmlHelper helper, string postAction, string submitText, IEnumerable<KeyValuePair<string, string>> postValues)
    {
        var form = new TagBuilder("form");
    
        // Setup basic properties like method, action
        form.Attributes.Add("method", "post");
        form.Attributes.Add("action", postAction);
    
        // Instantiate a stringbuilder for the inner html of the form
        var innerHtml = new StringBuilder();
    
        // Create and append hidden fields for the post values
        foreach(var value in postValues)
        {
            var hidden = new TagBuilder("input");
            hidden.Attributes.Add("type", "hidden");
            hidden.Attributes.Add("name", value.Key);
            hidden.Attributes.Add("value", value.Value);
            innerHtml.Append(hidden.ToString(TagRenderMode.SelfClosing));
        }
    
        // Create the submit button
        var submit = new TagBuilder("input");
        submit.Attributes.Add("type", "submit");
        submit.Attributes.Add("value", submitText);
        // Append it to the stringbuilder
        innerHtml.Append(submit.ToString(TagRenderMode.SelfClosing));
    
        // Set the InnerHtml property of the form, and return it
        form.InnerHtml = innerHtml.ToString();
        return form.ToString(TagRenderMode.Normal);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thus .. You want to learn how to design and… May 13, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer The problem was that for some reason I downloaded version… May 13, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer Well the obvious answer: std::vector<BaseType*> vec; DerivedType d; vec.push_back(&d); But… May 13, 2026 at 5:32 pm

Related Questions

I have a CakePHP 1.2 application. I'm running into the case where I need
So the short version of this is: Can I traverse only the elements within
I'm working on a table where all rows have at least one class. Some
I'm using Django 1.0.2. I've written a ModelForm backed by a Model. This model
Simple (I hope), HTML question. Let's say I have a column group that spans

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.