Click here to Skip to main content
15,909,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay, this is the first time posting here. I'm converting a c# program to asp.net for web deployment. My problem is, and for the love of god I can't find an answer any where. My labels, when I run it locally on chrome using visual studio, update. But when I move it to the remote server on Azure, the labels do not get updated. I have the free account so it's hard to do any debugging remotely. Everything else works, just not this. It not only is frustrating, but I have tried most of the solutions I have seen on this site and others for problems slightly similar but nothing is working.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace BoggleBoardWeb
{
    public partial class BoggleBoard : Page
    {
        static int width_ = 4;
        static int desiredLength_ = 3;
        static int desiredSeed_ = 7;
        static int divisorHeight = 0;
        static int divisorWidth = 0;
        static int scoreComp;
        static int scoreHuman;
        static Queue<Tuple<string, char>> stringValues = new Queue<Tuple<string, char>>();
        static BogglePieceGenerator generator = new BogglePieceGenerator(width_, desiredSeed_);
        static BoggleBoard_Board boardInformation = new BoggleBoard_Board(width_, generator);
        static List<string> acceptedWords = new List<string>();
        static private char[,] board2D = new char[width_, width_];
        static Lexicon lexi = new Lexicon("lexicon-clean.txt");
        //TextBox humanScoreDisplay = new TextBox();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                //only call if this is the first entry.
                fillBoard();
                computerScoreDisplay.Text = scoreComp.ToString();
                humanScoreDisplay.Text = scoreHuman.ToString();
           }
            while (this.Panel1.Height.Value % width_ != 0)
            {
                this.Panel1.Height = new Unit(this.Panel1.Height.Value - 1);
            }
            //get the divisor
            divisorHeight = (int)this.Panel1.Height.Value / width_;
            divisorHeight -= 2;
            while (this.Panel1.Width.Value % width_ != 0)
            {
                this.Panel1.Width = new Unit(this.Panel1.Width.Value - 1);
            }
            divisorWidth = (int)this.Panel1.Width.Value / width_;
            divisorWidth -= 2;
            gridLayout();
            computerScoreDisplay.Text = scoreComp.ToString();
            humanScoreDisplay.Text = scoreHuman.ToString();
        }
        //makes the board to be used by the gridLayout to set all the values.
        private char[,] fillBoard()
        {
            //Panel playArea = new Panel();
            //playArea = (Panel)FindControl("playArea");
            for (int x = 0; x < width_; x++)
            {
                for (int y = 0; y < width_; y++)
                {
                    board2D[x, y] = boardInformation.getLetter(x, y);
                }
            }
            return board2D;
        }
        public BoggleBoard()
        {
            
            
            
        }
        //this makes the grid layout for the program. 
        public void gridLayout()
        {
            Button[,] grid = new Button [width_,width_]; //for width * height
            for(int height = 0; height < width_; height++)
            {
                for(int width = 0; width < width_; width++)
                {
                    grid[width, height] = new Button();
                    grid[width, height].Text = board2D[width,height].ToString();
                    grid[width, height].ID = width.ToString() + '_' + height.ToString() + '_' + "btn";
                    grid[width, height].Width = divisorWidth;
                    grid[width, height].Height = divisorHeight;
                    grid[width, height].BackColor = System.Drawing.Color.White;
                    grid[width, height].Visible = true;
                    grid[width, height].Click += new System.EventHandler(OnClick);
                    this.Panel1.Controls.Add(grid[width, height]);
                }
            }
            //this.Controls.Add(playArea);
        }
        //if the user clicks on a white square it turns red
        //else it turns red for 'selected'
        protected void OnClick(object sender, EventArgs e)
        {
            //Panel playArea = (Panel)FindControl("playArea");
            Button temp = sender as Button;
            if( temp.BackColor == System.Drawing.Color.White)
            {
                temp.BackColor = System.Drawing.Color.Red;
                stringValues.Enqueue(new Tuple<string, char>(temp.ID, temp.Text.ToCharArray()[0]));
            }
            else
            {
                //check to see if there is a way to make this dynamic so we only change the ones surronding the thing.
                Button button;
                for (int height = 0; height < width_; height++)
                {
                    for (int width = 0; width < width_; width++)
                    {
                        string locator = width.ToString() + '_' + height.ToString() + '_' + "btn";
                        button = (Button)this.Panel1.FindControl(locator.ToString());   
                        button.BackColor = System.Drawing.Color.White; 
                    }
                }
                stringValues.Clear();
            }
        }
        //Check the squares clicked to see if the user has made a word.
        protected void Check_Click(object sender, EventArgs e)
        {
            Panel playArea = (Panel)FindControl("Panel1");
            if (stringValues.Count != 0)
            {
                string stringToBeSent = new string(stringValues.Dequeue().Item2, 1);
                while (stringValues.Count != 0)
                {
                    stringToBeSent += stringValues.Dequeue().Item2;
                }
                if (stringToBeSent.Length >= desiredLength_ && !hasBeenPlayer(stringToBeSent) && lexi.wordStatus(stringToBeSent) == Lexicon.Status.WORD)
                {
                    if (boardInformation.isWordOnBoard(stringToBeSent))
                    {
                        //this.Controls.Add(humanScoreDisplay);
                        acceptedWords.Add(stringToBeSent);
                        this.humanScoreDisplay.Text = acceptedWords.Count.ToString();
                        scoreHuman = acceptedWords.Count;
                    }
                }
                //reset the buttons back to their orignal color
                Button button;
                for (int height = 0; height < width_; height++)
                {
                    for (int width = 0; width < width_; width++)
                    {
                        string locator = width.ToString() + '_' + height.ToString() + '_' + "btn";
                        button = (Button)this.Panel1.FindControl(locator.ToString());
                        button.BackColor = System.Drawing.Color.White;
                    }
                }
            }
        }
        //if the user has already selected the word do nothing
        private bool hasBeenPlayer(string wordToBeCheck)
        {
            //bool hasPlayed = false;
            foreach(string word in acceptedWords)
            {
                if(word == wordToBeCheck)
                {
                    return true;
                }
            }
            return false;
        }
       //if user clicks this then hand it to computer for the beating
       protected void doneBTN_Click(object sender, EventArgs e)
        {
            ComputerPlayer compPlayer = new ComputerPlayer(lexi);
            List<string> computerPlayedWords = compPlayer.playBoggle(boardInformation, acceptedWords, 3);
            this.computerScoreDisplay.Text = computerPlayedWords.Count.ToString();
            scoreComp = computerPlayedWords.Count;
            finishBTN.Visible = true;
        }
        //if user clicks this, then load new board and reset score
        protected void playAgain_Click(object sender, EventArgs e)
       {
            //generator = new BogglePieceGenerator(width_, desiredSeed_);
            boardInformation = new BoggleBoard_Board(width_, generator);
           board2D = new char[width_, width_];
           board2D = fillBoard();
           Button button;
            //remove all the buttons
           for (int height = 0; height < width_; height++)
           {
               for (int width = 0; width < width_; width++)
               {
                   string locator = width.ToString() + '_' + height.ToString() + '_' + "btn";
                   button = (Button)this.Panel1.FindControl(locator.ToString());
                   this.Panel1.Controls.Remove(button);
               }
           }
            //recreate all the buttons
           gridLayout();
           scoreComp = 0;
           scoreHuman = 0;
           //computerScoreDisplay.Text = "0";
          // humanScoreDisplay.Text = "0";
       }
    }
}

here is the code behind for the program. I have add the label more often then I originally did to see if maybe it was an event issue, it is not. still works locally not remotely.
here is the front end code:
ASP.NET
<%@ Page Title= "BoogleBoard" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BoggleBoard.aspx.cs" Inherits="BoggleBoardWeb.BoggleBoard" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        
        <asp:Panel ID="Panel1" runat="server" Height="840px" Width="840px" BorderStyle="Groove" ToolTip="Click the bottoms to move" ViewStateMode="Enabled">
        </asp:Panel>
        <asp:Button ID="checkBTN" runat="server" Text="Check Word" OnClick="Check_Click" Visible="True" Width="145px" />           
        <asp:Button ID="finishBTN" runat="server" Text="Finish" OnClick="doneBTN_Click" Visible="True" Width="116px" />
        <asp:Button ID="playAgain" runat="server" Text="Play Again" OnClick="playAgain_Click" Visible="True" Width="92px" />
        <p><asp:Label ID="humanScore" runat="server" Text="Your Score: "></asp:Label>
        <asp:Label ID="humanScoreDisplay" runat="server" Text="0" BorderStyle="Groove" CssClass="active" AssociatedControlID="checkBTN"></asp:Label></p>
        <p><asp:Label ID="ComputerScoreLabel" runat="server" Text="Computer Score: "></asp:Label>
            <asp:Label ID="computerScoreDisplay" runat="server" Text="0" BorderStyle="Groove" CssClass="active" AssociatedControlID="finishBTN"></asp:Label>
        </p>
</asp:Content>


If some of this seems rough, I apologize, like I said I'm learning asp.net to help myself in the job market. I don't normally ask for help, but I'm lost on why this is doing this, or not in this case. Any suggestions, help, or feedback/information will be greatly appreciated. Like I said this works perfectly on my local machine using visual studio, just not on azure. I do not have any other server to try this on.

Thank you,

Lee
Posted
Comments
caperneoignis 27-May-15 0:39am    
I want to add, that when the user clicks checkBTN the score should be updated if it is a word. Once the user clicks done, the computer takes over and finds all the words the user misses. The labels are supposed to get updated, each time the user clicks, and only once when the computer is done running. If it helps I can link the Azure page. Thank you in advance for your help!

1 solution

I figured out what was going on. The word file was not being uploaded, I had an exception but forgot to add a throw, I know stupid. But the program works now. BoggleBoard[^] If any one wants to check it out. The board and computer player now works great! On the local system the file was being located. When it was uploaded the command HttpContext.Current.Server.MapPath(lexiconFile) would put the root directory where the website was, and not the sub directory where the text file was located.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900