Showing posts with label webmatrix. Show all posts
Showing posts with label webmatrix. Show all posts

Tuesday, March 13, 2012

switch statement error?

This is my first application so be gentle. :) I'm using WebMatrix.
I have the following code in index.aspx

<script runat="server">
switch(Request.QueryString["page"]) {
case "products":
masterForm.Controls.Add(LoadControl("products.ascx"));
break;
}
</script
masterForm is the id of the form tag in index.aspx

I am basically trying to dynamically include each section and use index.aspx as the master template file.

Here's the error:
Compiler Error Message: CS1519: Invalid token 'switch' in class, struct, or interface member declaration

It's stopping on the line with the switch statement.

What am I doing wrong?what is "page" in the following code

switch(Request.QueryString["page"])


page is supposed to be coming from:

index.aspx?page=products
ok I think the problem is that you are declaring switch in the HTML View. You need to run this code in the code behind file where all the Page_Load and Page_Init methods are. I hope you understand what I am trying to say.
Thanks, that did it!


<script runat="server">
void Page_Load() {
switch(Request.QueryString["page"]) {
case "products":
masterForm.Controls.Add(LoadControl("products.ascx"));
break;
}
}
</script>

Mohammed, WebMatrix doesn't permit the use of CodeBehind.

grizjr, you need to place the switch in the Page_Load method. For example:

 void Page_Load(Object Sender, EventArgs E) {

switch (...) {
...
}
}

Obviously you've decided against my suggestion of simplifying your code.
The code is not working properly.
<script runat="server">

void Page_Load() {

switch(Request.QueryString["page"]) {

case "products":

masterForm.Controls.Add(LoadControl("products.ascx"));

break;

}

}

</script>
When I try and run it: I get this message:

Active Server Pages-Error 'ASP 0124'

Missing Language attribute

/nbhs/control-panel/switch.asp, line 2

The required Language attribute of the script tag is missing.

Active Server Pages-Error 'ASP 0124'


What tag is it missing?Tongue Tied [:S]


Now that problem is fixed with this line of code:
<script language="vbscript" runat="server">
I just needed to add language="vbscript"
now I get another problem
This is the code that I have:
<script language="vbscript" runat="server">

void Page_Load(Object Sender, EventArgs E) {
switch(Request.QueryString["page"]) {

case "products":

masterForm.Controls.Add(LoadControl("products.ascx"));

break;

}

}

</script>

The error that I get is this:


Microsoft VBScript compilation error-Error '800a03ee'

Expected ')'

/nbhs/control-panel/switch.asp, line 5

void Page_Load(Object Sender, EventArgs E) {
--------^

How can I fix this?