script versus code versus ?

R

Russ

I've been trying to get my head around this for 3 days now and it
seems like everything I try does not work for one reason or another.
I built a test page using the TabStrip and MultiPage controls. The
example shows how to put up pictures in each tab, and it works fine.

But of course I don't want pictures, I want a webform where the data
is different in each tab/view. The form could be different in each
tab too, but for now I'll settle on same form, different data, if that
is how it has to be. Also, I need to dynamically add the tabs because
there will be a different number of them depending on data. The test
I have does dynamically create the PageViews, but I cannot figure out
how to dynamically create the tabs. I tried the follwing script, as a
guess, but it does not work, failing on the Add.

Tab t = new Tab ();
t.Text = "Tab 0";
TabStrip1.Controls.Add (t);

I get an error about Add not having the correct parameter. I am
assuming I have to add to the TabStrip, but I get the same error if I
try to add to the MultiPage, or even the PageView.

But this is the least of my problems. The data I want to display
comes from a web service, and must be intially loaded when the page is
displayed. My problem is that since the code to dynamically add the
pages is done in script, how do I get all my data into the pages. In
fact, how do I go about placing text boxes and other controls on each
PageView? I sure hope I don't have to do it all in script - I want to
use the visual designer in VS! But when I switch to the designer, I
get errors like: "Error creating control: TabStrip1".

I've tried to insert the script into the page using
RegisterStartupScript and RegisterClientScriptBlock, but the script
never executes. No errors are generated, and I can see my script in
the resulting page, but it never executes. That is because the script
needs to be placed before the <form> section, but it is not. Here is
the code I tried to use to do the pictures from the Page_Load method
in the code behind:

ArrayList list = new ArrayList ();
list.Add ("pic1.gif");
list.Add ("pic2.gif");

System.Text.StringBuilder sb = new System.Text.StringBuilder ();
sb.Append (@"<script language=""C#"" runat=""server"">");

foreach (string url in list)
{
sb.Append ("\nPageView pv = new PageView ();");
sb.Append ("\nMultiPage1.Controls.Add (pv);");

sb.Append ("\nSystem.Web.UI.WebControls.Image image =
new System.Web.UI.WebControls.Image();");
sb.Append ("\npv.Controls.Add(image);\n");
sb.AppendFormat (@"image.ImageUrl = ""{0:C}""", url);
}
sb.Append ("\n</script>");

if (! IsClientScriptBlockRegistered ("Startup"))
RegisterClientScriptBlock ("Startup", sb.ToString ());

I realize that the above might result in a problem due to having the
same variable names (pv, image) for each iteration of the loop, but
since the script never gets executed I have not faced that issue yet.
I would dearly love to not have to deal with script at all! Is there
not some way to accomplish all this in the code behind file?

Where do I go from here?

Thanks, Russ
 
R

Russ

Four hours later:

After 3 days of banging my head on the desk I think something broke
loose a little because I suddenly figured out a lot of my problems!

In VS I happened to notice the Add/Remove toolbox items. I then
browsed to and included the Microsoft.Web.UI.WebControls.dll file.
Then I removed the MultiPage item I had put in, and "viola" I was able
to add it back in using the designer. But better than that, NOW the
code in the code behind page 'knows' about the
Microsoft.Web.UI.WebControls and I can write code for them.

Hallileuiegh! No more writing script and having to execute the
program to find out if I made a syntax error or guessed wrong about
how a function works! I was even able to figure out how to make the
dynamic tab creation work since the intellisense shows me what is
available (Use TabStrip1.Items.Add instead of TabStrip1.Controls.Add).

There seems to be no way to use the design view to set up the controls
in each PageView, because they are not created yet (being done
dynamically). I can live with that, I guess. Maybe there is a way to
create a page and then use it as a template for the dynamically
created pages. Anyone know how to do this?

Anyway most all of my troubles are gone now, and I can get back to
some productive work (I hope). Thanks to any who were getting ready
to answer my long message (below).

Regards, Russ
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top