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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:48:15+00:00 2026-05-15T22:48:15+00:00

I have a user control which contains the following code: <form id=CurrencyForm method=post runat=server>

  • 0

I have a user control which contains the following code:

<form id="CurrencyForm" method="post" runat="server">    
    Display prices in&nbsp;
    <asp:DropDownList ID="currency" runat="server" AutoPostBack="true">
        <asp:ListItem Value="GBP">GBP (£)</asp:ListItem>
        <asp:ListItem Value="USD">USD ($)</asp:ListItem>
        <asp:ListItem Value="EUR">EUR (€)</asp:ListItem>
    </asp:DropDownList>
</form>

This user control is included in my Master page so it is available on every page of the site.

Here is the codebehind:

protected void page_load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        currency.SelectedValue = (string)Session["currency"];
    }
    else
    {
        session["currency"] = currency.SelectedValue;
        Response.Redirect(Request.RawUrl);
    }
}

When I change the selection of the drop down list, a postback is triggered. However, the value of IsPostBack seems to always be false. I can’t quite put my finger on what I am doing wrong here?

Solution

After looking at the advice from the majority of posts I understand I was going wrong by using code_behind code etc instead of the controllers. I figured out how to use an action to basically redirect back to the same page so the following is now what I have:

User control:

<% using (Html.BeginForm("ChangeCurrency", "Home", FormMethod.Post)) {%>    
    Display prices in&nbsp;
    <select id="currency" name="currency">
        <option value="GBP">GBP (£)</option>
        <option value="USD">USD ($)</option>
        <option value="GBP">EUR (€)</option>
    </select>
    <input type="submit" value="change" /> // this is temporary to test the submit
<%} %>

Action

public ActionResult ChangeCurrency(string currency)
{
    Session["currency"] = currency;
    return new RedirectResult(Request.UrlReferrer.AbsoluteUri);
}
  • 1 1 Answer
  • 2 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-15T22:48:16+00:00Added an answer on May 15, 2026 at 10:48 pm

    MVC never does postbacks. Therefore, IsPostBack will always, correctly, be false. The thing you think is a postback is actually a POST, because MVC doesn’t do postbacks. You should not be using the ASP.NET server controls at all in MVC.

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

Sidebar

Related Questions

I have a user control in silverlight which contains both XMAL and .cs file.
I have a user control in my wp7 application which contains two text boxes
I have a nested user control which appears on every single page. It contains
I have a user control which uses objects as inner properties (some code is
I have an ASP.NET user control that contains a textbox which has an AJAX
I have a user control which contains a textbox. I have a class called
I have a user control that contains a repeater. I use the Eval() method
I have a user control which displays the currently logged in user's name. I
I have a user control which is 2 RadCombos cascaded. I'm trying to add
I have a user control which has a DateTimePicker overlaid with the single line

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.