Send Calls Button Boot First!

I have a problem with a web form.

My goal: Inside, when the page loads, it should load each text field blank. After filling in the information and click "Submit", it should be sent (UpdatePaymentInfo ())

Problem: Here, when the user fills in the information and presses the "Submit" button, it calls the download function even before the "Submit" button and makes the entire text field empty.

Here is the code:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    string QueryStringupdatecreditcard1 = Request.QueryString.ToString();

    if (String.Equals(QueryStringupdatecreditcard1, "tabID=B"))
    {
        divTitle.Visible = false;
        trmain.Visible = false;
        tdOrderSummary.Visible = false;
        trCCandBilling.Visible = true;
        trtest2.Visible = false;
        divUpdatecreditcard.Visible = true;
        trusecompaddress.Visible = false;

        txtFirstName.Text = "";
        txtLastName.Text = "";
        txtAddress1.Text = "";
        txtAddress2.Text = "";
        txtCity.Text = "";
        txtZip.Text = "";
        txtCardNo.Text = "";
        txtVccNumber.Text = "";
        trAmountCharged.Visible = false;
    }
}

protected void imgbtnSubmit_Click(object sender, ImageClickEventArgs e)
{
    try
    {
        UpdatePaymentInfo();
    }
}
+3
source share
6 answers

Wrap the current contents of your OnLoad method in:

if (!Page.IsPostBack)
{
    // Code in here will only be executed when the page is *not* being loaded by a postback
}

, ASP.NET Life Life Cyle , ,

- , , .

- , . , IsValid .

, ( ):

  • , .
  • .
  • OnLoad , .
  • , - 3 .

, , OnLoad, . , , :

, ( , ) OnLoad, :

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    if (!Page.IsInPostBack)
    {
        SetFieldVisibility();
        ClearFields();
    }
}
+9

_Load .

.

, , Page_Load .

private void Page_Load(object sender, System.EventArgs e)
{
    if(!Page.IsPostBack)
    {
       ///do stuff in here that you want to occur only on the first lad.
    }
    else
    }
       // code that you want to execute only if this IS a postback here.
    {

 }

// do stuff you want to do on Page_Load regardless of postback here.
}
+3

IsPostBack :

protected override void OnLoad(EventArgs e) {
  if (!Page.IsPostBack) { 
    EmptyTextBoxes();
  }
}
+1

Have you tried wrapping the reset code in the check to see if the page is a postback?

if(!Page.IsPostback) {
    // Do form reset here
}
+1
source

Have you considered using the IsPostBack page variable ?

protected override void OnLoad(EventArgs e)
{
   if(!IsPostBack){
      //all your logic here.
   }
}
+1
source

if so, you can use the data binding control and set it to insert mode

0
source

Source: https://habr.com/ru/post/1760280/


All Articles