• Advertisement
Sign in to follow this  

Simple postback of values without clearing the page's values

This topic is 1458 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Note: I've been using ASP.NET Webforms, so ViewState was my friend.

Note: Default.html and Default.cshtml are two different files/pages.

Basically, all I'm trying to do is take form values from a .html page, post them, and then go back to the original page without the values resetting.

Here's what I have so far:

My client-side script

    <!-- Default.html -->
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Testing Stuff</title>
    </head>
    <body>
        <form id="mainpage" action="Default.cshtml" method="post">
            <div style="clear:both;" id="dbInput">
                <label for="linedesc">Description:</label>&nbsp;
                <input type="text" id="linedesc" name="linedesc" />
                <br /><br />
                <input id="fruits" name="options1" value="fruits" type="radio" />
                <label for="fruits">Fruits</label>&nbsp;
                <input id="candies" name="options1" value="candies" type="radio" />
                <label for="candies">Candies</label>&nbsp;
                <input id="snacks" name="options1" value="snacks" type="radio" />
                <label for="snacks">Snacks</label>
                <br /><br />
                <label for="options2">Choose beverage:</label>&nbsp;
                 <select id="options2" name="options2">
                    <option value="Coca-Cola">Coca-Cola</option>
                    <option value="Sprite">Sprite</option>
                    <option value="Root Beer">Root Beer</option>
                    <option value="Orange Juice">Orange Juice</option>
                </select>
                <br /><br />
                <input type="submit" id="submit" name="submit" value="Submit" />
            </div>
        </form>
    </body>
    </html>


And my server-side script
 

    //Default.cshtml
    @{
        var linedesc = Request.Form["linedesc"];
        var food = Request.Form["options1"];
        var drinks = Request.Form["options2"];
        
        // Go back to Default.html and keep values selected, ie. values don't reset
        var blah = "hi";
    }


All I want to do is simple, no bells, no whistles, postback and return. I'm just missing that last piece.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement