开发者

Postback on a submit button

I have a page that has 4 tables. Initially when the page is loaded, it shows 1 & 2. Thats working fine. On Post back(When Submit is clicked), it should show 3 & 4. Even thats working fine(code shown here). When the submit is clicked again, it has to call updatePaymentInfo() and redirect. Is there something to write as a condition to call UpdatepaymentInfo() because when submit is clicked, it is taking as an other postback and showing me 3 & 4 again.

protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
    try
    {
        if (Page.IsPostBack)
        {
            trtest.Visible = false;
            trCCandBilling.Visible = true;
            trtest2.Visible = true;
      开发者_如何学C  }
        else
        {
            UpdatePaymentInfo();
            Response.Redirect(ApplicationData.URL_MERCHANT_ACCOUNT_HOME, true);
        }
    }
 }


My thought on the easiest way to do this is to have two image submit buttons in the same place. Button A is the one you already have button B is a new one that whose submit handler runs UpdatepaymentInfo and redirects.

Button B starts off invisible while button A is visible. When Button A is clicked in addition to the visibility changes you hide button a and show button B. Then when they click button B the right stuff happens.

Its not that elegant though.

Another solution might be storing values in the page to indicate the current page state that you can then check on button click.


It sounds like you're having trouble managing the current state of your page. You could try:

  1. Having a second submit button. It would be stylistically indistinguishable from the first, and would be hidden/shown accordingly, but would have its own click event.
  2. Placing a hidden form value on the page to track the current "step" of the process.
  3. Breaking the page into two pages, since from the user's perspective it's clearly a two-page process.
  4. My personal favorite, move to MVC :) Though it's understandable if you're stuck in a pre-existing WebForms app and there's just no budget to re-write it.


I guess that imgbtnSubmit_Click handles Click event of the Submit button so this method will be called only during the postback so the condition is incorrect.

I would not use this approach. ASP.NET contains controls which support these requirements. Check MultiView and Wizard. Create separate view with table 1 & 2 and button and another view with table 3 & 4 and button. Button on the first view will switch the view and button on the second view will call the method and redirect.


Another possible way to do this is keep your current set up and add a command argument to the button. By default it has some argument that you check on the first click. Then checking the command argument on the first click you do your showing and change the command argument to be something different. So on the next button click you do the work associated with the second command argument. Thus flipping the work done without having to hide or show a new control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜