473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

script versus code versus ?

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

Nov 18 '05 #1
1 1448
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

On Wed, 09 Jun 2004 19:19:33 -0400, Russ <ru****@eticomm.net> wrote:
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


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jason | last post by:
Pardon the newbie question... What's the difference between (asp.net)VB code inside one versus the other. And why have both?
3
by: Joe | last post by:
Hi, I have written a webpage that allows a user to delete files in asp.net with I am having a small problem. To access this page a user has to login via login.aspx page. After successful...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
2
by: vmalhotra | last post by:
Hi I am new in python scripting. I want to open a Multiple telnet session through once script. In other way i can tell i want to open two linux consoles through one script. I wrote one...
6
by: metaperl | last post by:
Hello, I am responsible for converting 30 loosey-goosey Perl scripts into 30 well-documented easy to understand and use Python scripts. No one has said anything in particular about how this...
42
by: John Doty | last post by:
I realized that I have a little job on the table that is a fine test of the Python versus Standard Forth code availability and reusability issue. Note that I have little experience with either...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am looking for a java script to close a web form that I can attatch to a button click event. I am using vs2005, c#. Thanks -- Paul G Software engineer.
5
by: Christopher Brewster | last post by:
I am running the same script on the same data on two different machines (the folder is synchronised with Dropbox). I get two different results. All the script does is count words in different...
6
by: empiresolutions | last post by:
I'm trying to slightly alter the script found here, http://www.adrianhodge.com/web-design/mootools-horizontal-div-slider-121/. What i want to do is make the carousel work on a Next/Previous...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.