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
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