• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Simple ASP .NET question"

Collapse

  • wurzel
    replied
    Originally posted by VectraMan View Post
    Does that mechanism call the Page_Load again with the same Request data?
    Yes, so you don't need the response.redirect. Use the IsPostback property in the Page_Load - this will be true when your handler is invoked & false when you first load the page.

    Edit: Which is basically what Bunk said
    Last edited by wurzel; 18 August 2011, 15:08.

    Leave a comment:


  • Durbs
    replied
    Yes, kinda, if you look at your pages form in the rendered HTML once you've loaded your page with the querystring, it'll look like:

    <form name="form1" method="post" action="basket.aspx?addqty=1" id="form1">

    So that is what your form is posting to. An quick fudge may be to change the action attribute:

    m_basket.IncreaseItem(item);
    form1.Action = "basket.aspx";

    Leave a comment:


  • VectraMan
    replied
    Originally posted by Bunk View Post
    It's been yonks since I did asp.net but I would have thought the way to do it was to make the checkbox do a postback on change (which would reload the page without needing Response.Redirect) and then add an if(!Page.Postback) statement in the page load event.
    I thought the postback was the mechanism that allowed the check box to call the server side CheckChanged function.

    Is that the issue? Does that mechanism call the Page_Load again with the same Request data?

    Leave a comment:


  • StopTheEarthIwantToGetOff
    replied
    Code:
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!this.IsPostBack)
    {
      int addQty;
       if (!string.IsNullOrEmpty(Request["addqty"]) && int.TryParse(Request["addqty"],addQty))
      {
        addQty = Math.Abs(addQty);
         m_basket.IncreaseItem(item);
      }
    }
      // display basket and calculate totals...
    }
    Code needs to be a bit more defensive.
    Remember, most users are t***ts.

    Leave a comment:


  • Bunk
    replied
    Originally posted by VectraMan View Post
    This is not my area, so please be gentle. This is a simple shopping basket system I knocked up in C# and VS2005 and runs on a Windows 2003 server.

    The initial url is of the form: www.site.com/basket.aspx?addqty=1

    And I have something like:
    Code:
    protected void Page_Load(object sender, EventArgs e)
    {
      string addQty = Request["addqty"];
       if (addQty != null)
      {
         m_basket.IncreaseItem(item);
      }
      // display basket and calculate totals...
    }
    That all works. There's also a check box on the page (for VAT) and that has an OnClick handler:

    Code:
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       Session["VATOverride"]=1;
       Response.Redirect("Basket.aspx");
    }
    The problem is if I go to the page via the addqty=1 link, and then click on the checkbox, it reloads the basket but does the addqty again. I assumed (perhaps naively) that because the redirect was to just "Basket.aspx", the Request variable would be empty on the next PageLoad. Is that correct? Or does the Request persist? Or is there something else going on - perhaps the browser is caching the request somehow?

    Thanks for any help.
    It's been yonks since I did asp.net but I would have thought the way to do it was to make the checkbox do a postback on change (which would reload the page without needing Response.Redirect) and then add an if(!Page.Postback) statement in the page load event.

    Leave a comment:


  • VectraMan
    started a topic Simple ASP .NET question

    Simple ASP .NET question

    This is not my area, so please be gentle. This is a simple shopping basket system I knocked up in C# and VS2005 and runs on a Windows 2003 server.

    The initial url is of the form: www.site.com/basket.aspx?addqty=1

    And I have something like:
    Code:
    protected void Page_Load(object sender, EventArgs e)
    {
      string addQty = Request["addqty"];
       if (addQty != null)
      {
         m_basket.IncreaseItem(item);
      }
      // display basket and calculate totals...
    }
    That all works. There's also a check box on the page (for VAT) and that has an OnClick handler:

    Code:
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
       Session["VATOverride"]=1;
       Response.Redirect("Basket.aspx");
    }
    The problem is if I go to the page via the addqty=1 link, and then click on the checkbox, it reloads the basket but does the addqty again. I assumed (perhaps naively) that because the redirect was to just "Basket.aspx", the Request variable would be empty on the next PageLoad. Is that correct? Or does the Request persist? Or is there something else going on - perhaps the browser is caching the request somehow?

    Thanks for any help.
Working...
X