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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:23:54+00:00 2026-05-16T07:23:54+00:00

I have a problem with a webform. My Goal: Intially when a page is

  • 0

I have a problem with a webform.

My Goal: Intially when a page is loading, it has to load every textbox empty. After filling the info and click submit, it has to get submitted(UpdatePaymentInfo())

Problem: Here, When the user fills the info and clicks Submit,it calls onload function even before the submit button and makes all text box 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();
    }
}
  • 1 1 Answer
  • 0 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-16T07:23:54+00:00Added an answer on May 16, 2026 at 7:23 am

    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
    }
    

    This is because, as per the ASP.NET Page Life Cyle, the things that you care about in this instance happen in this order:

    Load – During load, if the current request is a postback, control
    properties are loaded with information
    recovered from view state and control
    state.

    Postback event handling – If the request is a postback, control event
    handlers are called. After that, the
    Validate method of all validator
    controls is called, which sets the
    IsValid property of individual
    validator controls and of the page.

    So what happens is (somewhat simplified):

    1. You click the image button, triggering the postback.
    2. The data from your form is loaded into your controls.
    3. Your OnLoad method overwrites the values in the controls to clear them.
    4. Your click handler is run, but because of step 3 it sees empty values.

    As others have sort-of mentioned, it wouldn’t necessarily be a bad thing to refactor your OnLoad method whilst you’re doing this. At the moment you seem to have it doing two distinct things:

    • Clearing the text fields
    • Setting the visibility of fields

    It might be worth separating this into one or two (depending on if the visibility setting and field clearing will be done independently) separate methods and adjusting your OnLoad method so it looks like this:

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
    
        if (!Page.IsInPostBack)
        {
            SetFieldVisibility();
            ClearFields();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with UIWebView delay when the load image from url. In my
I have problem while loading data into html select when users press or click
I have problem with TableView its empty. In (.h) file: @interface TableViewController : UITableViewController{
I have a webform with a button and a textbox. I want to set
I have the webform with dropdown list, label and textbox. Like below: <asp:DropDownList ID=ddlTest
I'm trying to create an Ajax enabled webform, and have created a simple page.
This has been plaguing me for a while. I have a page in my
I have a nested content page within a master page, upon load the the
I have a webform with a TextBox, SaveButton, RequiredFieldValidator, DataGrid and a paging button.

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.