473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Button Click Event Data Not available in time

I am trying to handle a button click event, which updates a web control
table with data. The button is dynamically created in the table itself.

When I call updateTable() in the Page_Load the new data from the button is
not available at this time as to allow the table to properly update.
So basically, I need to call UpdateTable() twice, once from page load and
once from button. This causes problems with my application, and I was
trying to figure out how I can make this work.

Basically I want to do this.

loadTable()
read data from source
create rows in table
as I create rows, create controls in each row based on data
wire click events to these controls

button click event
update current location var
call loadTable to display new data based on this location var
Nov 18 '05 #1
6 2823
Michael Johnson Jr. wrote:
I am trying to handle a button click event, which updates a web control
table with data. The button is dynamically created in the table itself.

When I call updateTable() in the Page_Load the new data from the button is
not available at this time as to allow the table to properly update.
You _have_ to re-create the dynamically created controls in Page_Load or
earlier stage in the same order you created them before and with the
same identifiers as they had before. If you then also wire the events
again, you'll see that after Page_Load, the event will be emitted
by the button as expected.
So basically, I need to call UpdateTable() twice, once from page load and
once from button. This causes problems with my application, and I was
trying to figure out how I can make this work.


What problems does it cause ? After Page_Load the state must have
been restored, which for most controls happens automatically,
but if you create controls dynamically, you have to restore them yourself.

Best regards,

Eric
Nov 18 '05 #2
Well if I run the method in the button click event, the method runs twice,
which fouls up my code trying to drill down in the table.

If I just set a member variable in the button click event, i end up needing
to click the button twice to make it work.
"Eric Veltman" <eric@[RemoveThis]veltman.nu> wrote in message
news:vt************@corp.supernews.com...
Michael Johnson Jr. wrote:
I am trying to handle a button click event, which updates a web control
table with data. The button is dynamically created in the table itself.

When I call updateTable() in the Page_Load the new data from the button is not available at this time as to allow the table to properly update.


You _have_ to re-create the dynamically created controls in Page_Load or
earlier stage in the same order you created them before and with the
same identifiers as they had before. If you then also wire the events
again, you'll see that after Page_Load, the event will be emitted
by the button as expected.
So basically, I need to call UpdateTable() twice, once from page load and once from button. This causes problems with my application, and I was
trying to figure out how I can make this work.


What problems does it cause ? After Page_Load the state must have
been restored, which for most controls happens automatically,
but if you create controls dynamically, you have to restore them yourself.

Best regards,

Eric

Nov 18 '05 #3
Hello Michael,

Michael Johnson Jr. wrote:
Well if I run the method in the button click event, the method runs twice,
which fouls up my code trying to drill down in the table.
Do you mean that the method contains some piece of code that drills down
in the table and you don't want that piece to run both from Page_Load
and Button_Click ? Then I'd say split up the method in two methods.
Otherwise, could you perhaps explain in more detail what the problem is ?
If I just set a member variable in the button click event, i end up
needing to click the button twice to make it work.


I don't understand what you mean here.

Best regards,

Eric
Nov 18 '05 #4
Have a table1 webcontrol, and a method updateTable() that runs from
Page_Load event. updateTable() does a Directory.GetDirectories() and
Directory.GetFiles() to get a list of files/directories, and it populates
the table with this information. It also makes some buttons for each row.
For directories, it makes a "Enter Directory" button, for files it makes
"Delete, Download, and what not". I have created a standard event handler
for the button "Enter Directories" (Havent' messed with rest of the buttons
till I solve this problem". Now the problem comes in when the user clicks
the button (which passes the rows directory in the button.Attributes
collection to the click event) I want to update the table. I have tried
calling updateTable() with the new directory as the arguement and I have
tried using a variable which I set in the click event. The problem is the
click event fires after the page_load event, but if I do not populate the
table in the page_load event, the event won't fire. But since the event
hasn't fired, I don't know what to populate the table with. I have tried
calling the method in page_load then recalling it in the button click, the
problem with this is it gives me trouble when I try to go further than one
directory deep. I have tried setting a variable in the click event for the
new directory, but since the page_load event fires before it it causes me to
need to click twice to see the changes. I tried placing the function in the
OnPreRender and Render methods, since they are after the Page_load but I
seemed to have problems with it not showing anything.

I really can't think of any solution to this problem, but yet it sounds so
easy of a requirement.
"Eric Veltman" <eric@[RemoveThis]veltman.nu> wrote in message
news:vt************@corp.supernews.com...
Hello Michael,

Michael Johnson Jr. wrote:
Well if I run the method in the button click event, the method runs twice, which fouls up my code trying to drill down in the table.


Do you mean that the method contains some piece of code that drills down
in the table and you don't want that piece to run both from Page_Load
and Button_Click ? Then I'd say split up the method in two methods.
Otherwise, could you perhaps explain in more detail what the problem is ?
If I just set a member variable in the button click event, i end up
needing to click the button twice to make it work.


I don't understand what you mean here.

Best regards,

Eric

Nov 18 '05 #5
Hello Michael,

Sorry for not replying today, I'll try to reply tomorrow.
It's almost midnight now here in the Netherlands.
How does a sleepy smiley look ? Something like E-) ?

Best regards,

Eric
Nov 18 '05 #6
Hello Michael,

Michael Johnson Jr. wrote:
till I solve this problem". Now the problem comes in when the user clicks
the button (which passes the rows directory in the button.Attributes
collection to the click event) I want to update the table. I have tried


I think a better idea for associating a row with a file/directory would
be to have a property that maintains an array in ViewState, which contains
the current list of files/directories. You can use this array to "redraw"
the table at Page_Load and it also makes the HTML smaller than when you're
using button.Attributes, especially if you have multiple buttons in a row.

public string[] FsEntries
{
get
{
if(ViewState["FsEntries"] == null)
ViewState["FsEntries"] = new string[];

return((string[])(ViewState["FsEntries"]));
}
set
{
ViewState["FsEntries"] = value;
}
}

I think using this array will solve the problem.
It's easy to "redraw" the table at Page_Load, so that the
event from the button will be properly emitted and handled.

In the code that creates the table, I would put some code
that assigns the ID of the button such that it always ends
with the row number, so that you get button IDs like :
cmdEnterDirectory0, cmdEnterDirectory1, etc.

Then from the Button_Click, you can easily find out in which
row the button was that was clicked and, by looking at the array,
what directory you wanted to enter. Then you can get the new
items and store them in the array and redraw the table based
on the new contents.

Best regards,

Eric
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
10
by: tasmisr | last post by:
This is an old problem,, but I never had it so bad like this before,, the events are refiring when clicking the Browser refresh button. In the Submit button in my webform, I capture the server side...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
3
by: hb | last post by:
Hi, I have a asp:button btnGo. When clicking this button, the code will parse a asp:table to find a specific ID under certain conditions. Once the ID is found, the code need to keep the current...
3
by: vcornjamb | last post by:
Hello, I am developing a web form that contains some buttons and a data grid which has as its last column link buttons that will delete the data associated with that row. Everything works fine,...
5
by: Charlie J | last post by:
I have developed a website with several (30) pages that works just fine on my development machine (XP Pro SP2). When I move the site to the server (W2K3) I have 7 pages where a mouse click on a...
3
by: Imran Aziz | last post by:
Hello All, I have a search text and button that post data and my button handler filters the repeater control. However when the button is clicked the first time. The page_load event is being called...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
3
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.