This is a translation of an ASP page to ASP.Net. First, the background:
The goal is to have a grid of different settings for the application --
think something along the lines of the Property Page for a control. You
have two columns -- the first column is a simple caption, and the second
column can be one of a number of controls (textbox, checkbox,
dropdownlist, etc) for each row. So row #1 might have a textbox in the
second column, row #2 might have a checkbox, etc.
In ASP, this was done just by writing out a <table> with two <td> cells
per <tr> row; in the second <td> cell, an <input type="text">, <input
type="checkbox">, or <select> would be written out, as appropriate.
Some translations had to be done when creating the page (the settings
that were dropdown lists would be numerical values, so "2" would
indicate that the third <option> in the <select> should be selected; it
would have to translate "0" and "1" to be either "" or
"checked=\"checked\"" for a checkbox, that sort of thing.)
But now it's ASP.Net. Most of the translation has been pretty easy, and
a lot of ugly HTML generation has been removed in favor of the objects,
which is great. But this part is giving me trouble.
All of the previous tables are now DataGrids, so it was decided that
this should be a DataGrid too, for consistency. A TemplateColumn was
added to the DataGrid. In the DataGrid's ItemDataBound event, the
proper HtmlElement (HtmlInputText, HtmlInputCheckBox, HtmlSelect, etc)
is created, and added to the appropriate cell.
This all works fine. Looks great.
However, saving didn't work at all. Checking the source of the code, I
found that when an item was assigned an id of "LogoFile", it's actual id
on the page would be set to "gridsettings__ctl2_LogoFile", and it's name
(which was assigned as "LogoFile") became "gridpreference:_ctl2:LogoFile".
So, the Request.Form was looking for names like "LogoFile" that weren't
actually coming through, and since these items are created dynamically,
posting back doesn't work for them either (they only get their correct
ids, it seems after the page has been rendered)
So my options seem to boil down to:
#1: Subclass the HtmlElement objects and override their methods.
Doesn't strike me as elegant, nor a good idea.
#2: Somehow delay the saving of items on a PostBack until after the
rendering is done. Don't even know if this is possible, or a good idea.
#3: Dump the DataGrid, use a table styled like a DataGrid. This seems
the easiest of the solutions.
#4: Some other method I'm not aware of?
Thoughts?
--Colin McGuigan 2 2005
You are using objects for the rendering, yet still looking in Request.Form
for the data afterwards?
You should be examining the grid and its controls, finding the control you
need in each row, and getting its data that way. Remember, the datagrid is
an object, that contains other objects.
"Colin McGuigan" <ma************@speakeasy.net> wrote in message
news:L4********************@speakeasy.net... This is a translation of an ASP page to ASP.Net. First, the background:
The goal is to have a grid of different settings for the application -- think something along the lines of the Property Page for a control. You have two columns -- the first column is a simple caption, and the second column can be one of a number of controls (textbox, checkbox, dropdownlist, etc) for each row. So row #1 might have a textbox in the second column, row #2 might have a checkbox, etc.
In ASP, this was done just by writing out a <table> with two <td> cells per <tr> row; in the second <td> cell, an <input type="text">, <input type="checkbox">, or <select> would be written out, as appropriate. Some translations had to be done when creating the page (the settings that were dropdown lists would be numerical values, so "2" would indicate that the third <option> in the <select> should be selected; it would have to translate "0" and "1" to be either "" or "checked=\"checked\"" for a checkbox, that sort of thing.)
But now it's ASP.Net. Most of the translation has been pretty easy, and a lot of ugly HTML generation has been removed in favor of the objects, which is great. But this part is giving me trouble.
All of the previous tables are now DataGrids, so it was decided that this should be a DataGrid too, for consistency. A TemplateColumn was added to the DataGrid. In the DataGrid's ItemDataBound event, the proper HtmlElement (HtmlInputText, HtmlInputCheckBox, HtmlSelect, etc) is created, and added to the appropriate cell.
This all works fine. Looks great.
However, saving didn't work at all. Checking the source of the code, I found that when an item was assigned an id of "LogoFile", it's actual id on the page would be set to "gridsettings__ctl2_LogoFile", and it's name (which was assigned as "LogoFile") became "gridpreference:_ctl2:LogoFile".
So, the Request.Form was looking for names like "LogoFile" that weren't actually coming through, and since these items are created dynamically, posting back doesn't work for them either (they only get their correct ids, it seems after the page has been rendered)
So my options seem to boil down to:
#1: Subclass the HtmlElement objects and override their methods. Doesn't strike me as elegant, nor a good idea.
#2: Somehow delay the saving of items on a PostBack until after the rendering is done. Don't even know if this is possible, or a good idea.
#3: Dump the DataGrid, use a table styled like a DataGrid. This seems the easiest of the solutions.
#4: Some other method I'm not aware of?
Thoughts?
--Colin McGuigan
Marina wrote: You are using objects for the rendering, yet still looking in Request.Form for the data afterwards?
You should be examining the grid and its controls, finding the control you need in each row, and getting its data that way. Remember, the datagrid is an object, that contains other objects.
But the objects don't exist in the DataGrid until I create them, which,
as I understand the lifecycle, is sometime after the PostBack data has
been inserted into the objects.
Am I wrong?
--Colin McGuigan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jen |
last post by:
Hi
I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that?
...
|
by: Quentin Huo |
last post by:
Hi:
I have a user control and I want to dynamically create a Label control and
TextBox control when the button "add more author name" is clicked.
I did like this:
1. there is a...
|
by: RJN |
last post by:
Hi
Sorry for posting again.
I have a datagrid which is put inside a div tag to make it scrollable. I
need to page the datagrid. The page numbers appear at the bottom of the
datagrid and has...
|
by: Tim_Mac |
last post by:
hi,
i have an aspx page which dynamically loads a user control and adds it
to a placeholder. the control is recreated and added to the
placeholder for postbacks as well.
the user control...
|
by: Larry Grady |
last post by:
Anyone up for a challenge?
I've been struggling with this for a few days and was hoping someone could
help me. Pouring through all the messageboards I just can't find the
solution.
We have a...
|
by: david |
last post by:
I have posted my question before. It seems that I can not find the solution.
The question:
I have datasource, say, ds which is bounded to a datagrid, dg.
Assume that ds have 5 columns,...
|
by: Kiran Kumar Pinjala |
last post by:
Hi,
May be this is silly, or I just need a second pair eyes to look at this.
I am trying to get values that I have edited in a datagrid and update the
values with those values. Here is the code...
|
by: rsaffy |
last post by:
I am having trouble with my dynamically created button's event
handling. I read that the buttons need to be recreated on every trip
to the server, but how exactly do you do that when the datagrid...
|
by: Silver Oak |
last post by:
I have a DataGrid in which one of the columns is TemplateColumn that was
created dynamically using iTemplate. I would like to have multi-row editing
capability on the DataGrid. I'm trying to...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |