Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Guru's challenge: How to place multiple instance of a control on a page with abnormal capabilities

Reply
Thread Tools

Guru's challenge: How to place multiple instance of a control on a page with abnormal capabilities

 
 
.Net Newbie
Guest
Posts: n/a
 
      07-29-2004
I am relatively new to .Net and have been coding an intranet site for my
employer for a couple of months. I am currently stuck coding in a
text-editor called EditPlus without access to the VS.Net IDE, and coding
pages with the script directly in each page (not using the codebehind
method) as most of my learning material has demonstrated. I started with
the IBuySpy Portal (SDK version not VS Version) as my base portal and have
coded custom controls and pages within the portal.

My employer recently requested that I change one of my pages so that at a
click of a button a section of code, including roughly 23 asp WebServer
Controls, can be repeated so that the user can enter multiple sets of the
same information into one SQL Server table when they save the information on
the page (along with the main information in another table). I had already
designed the tables with this in mind, however I am having some problems
with getting the .Net code to function correctly. The way the original page
was designed was that when a user clicked on one of three different buttons
in this section in question the cooresponding popup window was called which
loaded a lookup(aspx) page. When the user clicked on a hyperlink in the
lookup page the 23 controls on the main page were populated from SQL Server
tables (via JavaScript) and the popup window closed. Although I'm sure
there's a better way to do it, I used JavaScript to pass the variables back
to the main window because I knew how to do it. Since the change request
came in have I moved this section of 23 controls into an ascx file, removed
the popup windows(lookups), and am able to call it with the click of a
button. Into a table column formatted as follows: <td id="ContentPane"
colspan="2" runat="server"></td>

Unfortunately, my method has left me no way to reference the controls or get
the popup windows to function correctly. Each one of the newly displayed
controls have names like _ctl1hone, _ctl2hone, _ctl3hone, etc for each
time I add the control. Furthermore I am not able to retain information in
a given control instance. The way I currently have the code designed is
that a counter increments everytime the "Add" button is pressed. This
determines the number of times to add the control by looping through the
following code:

Control parent = Page.FindControl("ContentPane");
PortalModuleControl portalModule = (PortalModuleControl)
Page.LoadControl("Children.ascx");
parent.Controls.Add(portalModule);

Everything I have read indicates that I need to have this control inside
some container such as a datagrid or datalist in order to reference it
correctly. However all of my efforts have met with failure. The biggest
problem I have is that I don't even know if what I am trying to do can be
done much less how to do it. If anyone has any idea how I can get this
functioning correctly and/or how I can reference each new control instance,
while limited by my current coding environment
please, please, please, let me know.

Thanks in advance,

Jeff


 
Reply With Quote
 
 
 
 
Jeffrey Palermo [MCP]
Guest
Posts: n/a
 
      07-31-2004
Jeff,
First of all, you are severely limiting yourself by not using the VS.NET
IDE. I realize that money is an issue, but just know that your employer is
holding you back when this project could take half the time to do if you had
the proper tools. With that being said, I respect you for doing whatever it
takes to learn .NET and use it for something useful.

I assume that you are dynamically loading these controls at runtime and that
at design time you don't know how many instances of this control will be on
the page. The first thing that comes to mind is to make an asp:Table with a
dynamic number of <asp:TableRow/>, and each TableRow would have your editing
controls. Then when you need access to all the controls, you can:
<code>
foreach(TableRow row in myTable.Rows){
TextBox txt = (TextBox)row.FindControl("myInputControl");
//save off txt.Text
txt = (TextBox)row.FindControl("mySecondInputControlInTh eSameRow");
//save off txt.Text
}
</code>
and you will be able to find and use every control, but remember this when
using dynamic controls: The code to recreate the controls must run at the
same time on the first load as in the post back. If you are creating the
controls in Page_Load, you should be fine, but on PostBack, you have to
recreate the same number of controls in the same place so that the posted
data can be filled into these dynamic controls. Then after all the controls
are there again, you can loop through and get their values.

Best regards,
Jeffrey Palermo
".Net Newbie" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I am relatively new to .Net and have been coding an intranet site for my
> employer for a couple of months. I am currently stuck coding in a
> text-editor called EditPlus without access to the VS.Net IDE, and coding
> pages with the script directly in each page (not using the codebehind
> method) as most of my learning material has demonstrated. I started with
> the IBuySpy Portal (SDK version not VS Version) as my base portal and have
> coded custom controls and pages within the portal.
>
> My employer recently requested that I change one of my pages so that at a
> click of a button a section of code, including roughly 23 asp WebServer
> Controls, can be repeated so that the user can enter multiple sets of the
> same information into one SQL Server table when they save the information

on
> the page (along with the main information in another table). I had

already
> designed the tables with this in mind, however I am having some problems
> with getting the .Net code to function correctly. The way the original

page
> was designed was that when a user clicked on one of three different

buttons
> in this section in question the cooresponding popup window was called

which
> loaded a lookup(aspx) page. When the user clicked on a hyperlink in the
> lookup page the 23 controls on the main page were populated from SQL

Server
> tables (via JavaScript) and the popup window closed. Although I'm sure
> there's a better way to do it, I used JavaScript to pass the variables

back
> to the main window because I knew how to do it. Since the change request
> came in have I moved this section of 23 controls into an ascx file,

removed
> the popup windows(lookups), and am able to call it with the click of a
> button. Into a table column formatted as follows: <td id="ContentPane"
> colspan="2" runat="server"></td>
>
> Unfortunately, my method has left me no way to reference the controls or

get
> the popup windows to function correctly. Each one of the newly displayed
> controls have names like _ctl1hone, _ctl2hone, _ctl3hone, etc for

each
> time I add the control. Furthermore I am not able to retain information

in
> a given control instance. The way I currently have the code designed is
> that a counter increments everytime the "Add" button is pressed. This
> determines the number of times to add the control by looping through the
> following code:
>
> Control parent = Page.FindControl("ContentPane");
> PortalModuleControl portalModule = (PortalModuleControl)
> Page.LoadControl("Children.ascx");
> parent.Controls.Add(portalModule);
>
> Everything I have read indicates that I need to have this control inside
> some container such as a datagrid or datalist in order to reference it
> correctly. However all of my efforts have met with failure. The biggest
> problem I have is that I don't even know if what I am trying to do can be
> done much less how to do it. If anyone has any idea how I can get this
> functioning correctly and/or how I can reference each new control

instance,
> while limited by my current coding environment
> please, please, please, let me know.
>
> Thanks in advance,
>
> Jeff
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Back button abnormal behavior =?Utf-8?B?SG9yc3k=?= MCSD 1 05-28-2005 12:20 PM
Guru's Challenge: How to place multiple instances of a control in a single page in an abnormal situation .Net Newbie ASP .Net Datagrid Control 0 07-29-2004 04:38 PM
Guru's Challenge: How to Repeat multiple Controls in a Page in an abnormal situation .Net Newbie ASP .Net 0 07-29-2004 04:36 PM
ABNORMAL PROGRAM TERMINATION Control Panel CBUILDER 6 R6_2003 C++ 1 10-23-2003 07:30 AM



Advertisments