question about the events in the webform control

H

Harry

Dear all,

It is found that when a webform control trigger an event,

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub

This function will be load first, followed by

Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Submit.Click
End Sub

the click event of button.

I have to generate a table from the database table.

I found that the generation of table function should put in submit_click
function

Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Submit.Click
displaytablefromdatabase()
End Sub

Also, i have to put the displaytablefromdatabase() function page_load as i
have to deal with the postback when the page is refreshed.

Thus, i added something in Page_load

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If me.ispostback() then
displaytablefromdatabase()
end if
End Sub


The problem is that, i have another button called "reset", if a user click
"reset" button, the textbox in the form is set to empty string.

however, each time the "reset" button has been click, it will autopost back
and go to the "Page_Load" function and execute the
displaytablefromdatabase() and display the form. before the form goes to
"Reset_Click" function.

Clearly, i don't want to execute displaytablefromdatabase() when i click
Reset button. But, the webform has to go to Page_Load function before go to
the "Reset_Click" function.

What can i do?

Thanks all

Regards,
Harry
 
W

William F. Robertson, Jr.

If you have a !Page.IsPostBack in your page load. I don't know how the
displaytablefromdatabase() is running before the Reset_Click method (event).

Please clarify.
 
H

Harry

the displaytablefromdatabase() has been put in

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If me.ispostback() then // if it is
post back, displaytablefromdatabase() will be runned
displaytablefromdatabase()
end if
End Sub

if i don't execute displaytablefromdatabase() when whenever it post back,
the table will disappeared when the page is post back.
 
W

William F. Robertson, Jr.

I don't know how safe this is (I am sure it is plenty safe), but it is what
I started doing for this situation.

override the OnPreRender event for the page and before calling
myBase.OnPreRender()

c# code
protected override void OnPreRender( EventArgs e )
{
DisplayTableFromDataBase();
base.OnPreRender( e );
}

The display table will always run after the page_load and any postback
events have fired.

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top