Question

Is it possible to use a IF statement withing the case of a switch statement? I have tried the following code but nothing happens. I have verified that SectionID does not equal -1 but the page does not process anything, it will not shoot off the Server.Transfer nor propagate the assignments to the ListView or Labels.

case "Media":
    if (SectionID != "-1") { Server.Transfer("/Staff/Section.aspx"); }
    lvSearchResults.DataSource = SQLHelper.GetDataByQuery("SELECT SectionID AS ID, ShortName AS Title, Synopsis AS Descript, 'Section' AS PageName FROM dbo.tblSectionInfo WHERE  ShortName != 'Unknown' ORDER BY SectionTitle");
    lvSearchResults.DataBind();
    lblTitleRow.Text = "Add Section";
    lblDescriptionRow.Text = "Add new section home page.";
    btnAddNewItem.PostBackUrl = "/Staff/Section.aspx";
break;
Was it helpful?

Solution

It is perfectly valid to write if statements inside a case statement.

Why don't you try using Response.Redirect instead ??

Response.Redirect("/Staff/Section.aspx" , false);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top