RE: autopostback vs submit?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Michael,

If the user presses the Submit button, you should process the form data in a
method that handles the Click or Command event of the button, e.g.
In C#:
void Button1_Click(Object sender, CommandEventArgs e) {
//process the form data
}

In VB:
Protected Sub Button1_Command(ByVal sender As Object, ByVal e As
CommandEventArgs) Handles Button1.Command

End Sub


If a dropdownlist on the page had its index changed then you would process
all consequent actions in a method that handles the SelectedIndexChanged, e.g.
void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
//do any processing that is dependent on
//changing the list1 selection
}

Using this approach, you can leave the page load event only for processing
actions common to all requests or to actions specific to the first request of
the page, e.g. populating the dropdownlist when the page is first requested:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
//add code to populate the dropdownlists
}
}

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Dabbler" wrote:


Thanks for the page cycle link. I'm still puzzled though, when a user
presses the submit button I need to process the form data. I was going to
call a function from the Page Load with ispostback = true. But if a control
has autopostback enabled (a drop down list for instance) how do I know if I
can process the data or it's just a dropdownlist refreshing.

Thanks much.

Michael
"Phillip Williams" wrote:

Take a brief look at the description of the various stages of the page cycle:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp

You would typically use the Load event to perform actions common to all
requests. Then during handling the postback events you would realize which
control made a request. Then you can use the PreRender to do what you
probably were trying to do in the Load event. In other words, in the
standard programming style in ASP.NET you do not need to decide which control
caused the postback during the page load event.

Having said so, you can still check the value of
Request.Form["__EVENTTARGET"] to find the ID of the control that caused the
AutPostBack.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


"Dabbler" wrote:

How do I tell wether I'm seeing autopostback vs submit button click in
Page_load?

Thanks for any clues.

.



Relevant Pages

  • RE: sql injection: url or form based?
    ... accept form data through both GET and POST ... form data only in get requests. ... URL based and Forms based SQL injection but I'm wondering what are the ... Cross site scripting and other web attacks before hackers do! ...
    (Pen-Test)
  • Re: File Uploads
    ... You are instantiating cgi.FieldStorage twice. ... requests, because instantiating a FieldStorage reads the form data from ... Try to create a second one and cgi will try to read all the form data ...
    (comp.lang.python)
  • Re: How to read POSTed data
    ... It looks to me like it always expects form data ... Then this data is sent to the standard input of the CGI script. ... about the management of data sent by POST requests). ...
    (comp.lang.python)
  • Re: Writing a Java application to send/receive HTTP Requests
    ... > I would like to write a program that can send and receive HTTP ... > contain a form and I want the user to be able to enter form data via my ... > I know about developing java applications, ... > experience with dealing with HTTP requests in Java. ...
    (comp.lang.java.programmer)