Guru's challenge: ASP.Net: How to place multiple controls with extended capabilities on a page

N

.Net Newbie

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 _ctl1:phone, _ctl2:phone, _ctl3:phone, 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
 
J

Jaxson Tammaru

I dont 100% understand the full problem as ASP.NET isn't really my forte
although I did create a page with simular functionality a while back (and I
mea a WHILE back so i'm sorry if this isn't 100% accurate).
I used a repeater control to place the controls on the page and used a
method to name them in the html template for the repeater:

E.G. /// This is only part of the template

<asp:DropDownList id="DropDownList1" title = '<%#
DataBinder.Eval(Container.DataItem, "Name") %>' AutoPostBack = true
OnSelectedIndexChanged = "IndexChanged" Purpose = "Colour" runat="server"
Height="40px" Width="150px">

The 'title' was a made up tag that I placed on the control and was filled
with the value of a field in the data item that was being placed into it by
the repeater control (the field is called name in this example).
Then I hooked up an event on the control.

private void IndexChanged(object sender, EventArgs e)
{
DropDownList myList = (DropDownList) sender;
Response.Write("ComboBox changed " + myList.Attributes["Title"]);
}

And this will display the correct name of the comboBox and allow you to pin
it back to the object that it came from.
I think I tried to change the "ID" tag this way but it didn't work so I went
with the made up attribute instead.

I would seriously recommend using the code behind rather than scripting as
that is one of the best new features of ASP.NET.

I hope that helps.

Jax
 

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

Top