Click here to Skip to main content
16,004,806 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: show and hide gridview cells controls Pin
Not Active28-Nov-09 4:47
mentorNot Active28-Nov-09 4:47 
AnswerRe: show and hide gridview cells controls Pin
April Fans1-Dec-09 22:40
April Fans1-Dec-09 22:40 
GeneralRe: show and hide gridview cells controls Pin
angle573-Dec-09 1:05
angle573-Dec-09 1:05 
Questiontransfer a key value from a page to a popup page "on selected index change" of a gridview. Pin
saurabh8april28-Nov-09 0:03
saurabh8april28-Nov-09 0:03 
AnswerRe: transfer a key value from a page to a popup page "on selected index change" of a gridview. Pin
Not Active28-Nov-09 4:46
mentorNot Active28-Nov-09 4:46 
AnswerRe: transfer a key value from a page to a popup page "on selected index change" of a gridview. Pin
carlecomm2-Dec-09 22:49
carlecomm2-Dec-09 22:49 
GeneralRe: transfer a key value from a page to a popup page "on selected index change" of a gridview. Pin
saurabh8april7-Dec-09 0:47
saurabh8april7-Dec-09 0:47 
QuestionTrying to implement an old chat application into MVC Pin
wardy_boy197227-Nov-09 23:44
wardy_boy197227-Nov-09 23:44 
Morning. I'm new to ASP.NET and MVC. I'm basically trying to implement an old Chat Application, which uses CodeBehind into my MVC application called SkyBlueBarmy. However, the kind of errors that I get are listed below.

Basically, I keep playing around with the inherits tag but get a different error each time. Is it possible for me to re-use this application in MVC. If so can somebody please give me some pointers because i'm struggling being new to the syntax, error messages and concept.

Thanks very much

Server Error in '/' Application.
--------------------------------------------------------------------------------

Parser Error 
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately. 

Parser Error Message: 'Chat' is not allowed here because it does not extend class 'System.Web.Mvc.ViewPage'.

Source Error: 


Line 1:  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" AutoEventWireup="true" CodeBehind="matchchat.aspx.cs" Inherits="Chat" %>
Line 2:  
Line 3:  <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
 

Source File: /Views/chat/matchchat.aspx    Line: 1 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 


or if I change Inherits to 'SkyBlueBarmy.View.Chat.matchchat'

Server Error in '/' Application.
--------------------------------------------------------------------------------

The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: The view at '~/Views/chat/matchchat.aspx' must derive from ViewPage, ViewPage<TViewData>, ViewUserControl, or ViewUserControl<TViewData>.]
   System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) +108499
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +278
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
   System.Web.Mvc.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
   System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
   System.Web.Mvc.Controller.ExecuteCore() +126
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053 


I've also changed it to System.Web.Mvc.ViewPage<matchchat> and System.Web.Mvc.ViewPage but have reached the guessing stage without understanding what is happening or if I can achieve it.

matchchat.aspx
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" AutoEventWireup="true" CodeBehind="matchchat.aspx.cs" Inherits="Chat" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	chat
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">       
        function SetScrollPosition()
        {
            var div = document.getElementById('divMessages');
            div.scrollTop = 100000000000;
        }
        
        function SetToEnd(txtMessage)
        {                    
            if (txtMessage.createTextRange)
            {
                var fieldRange = txtMessage.createTextRange();
                fieldRange.moveStart('character', txtMessage.value.length);
                fieldRange.collapse();
                fieldRange.select();
            }
        }
               
        function ReplaceChars() 
        {
            var txt = document.getElementById('txtMessage').value;
            var out = "<"; // replace this
            var add = ""; // with this
            var temp = "" + txt; // temporary holder

            while (temp.indexOf(out)>-1) 
            {
                pos= temp.indexOf(out);
                temp = "" + (temp.substring(0, pos) + add + 
                temp.substring((pos + out.length), temp.length));
            }
            
            document.getElementById('txtMessage').value = temp;
        }
        
        function LogOutUser(result, context)
        {
            // don't do anything here
        }
        
        function LogMeOut()
        {
            LogOutUserCallBack();   
        }
    </script>
    <form id="form1" defaultbutton="btnSend" defaultfocus="txtMessage" runat="server" >
    <div>
        <asp:ScriptManager Id="ScriptManager1" runat="server" EnablePartialRendering="true" />
        <asp:Label Id="lblRoomName" Font-Size="18px" runat="server" /><br /><br />
        <asp:Label Id="lblRoomId" Visible="false" runat="server" />
        <asp:UpdatePanel Id="UpdatePanel1" runat="server">
            <Triggers>
                <asp:AsyncPostBackTrigger ControlId="Timer1" />
            </Triggers>
            <ContentTemplate>
                <asp:Timer Id="Timer1" Interval="7000" OnTick="Timer1_OnTick" runat="server" />
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td style="width: 500px;">
                            <div id="divMessages" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:592px;overflow-y:scroll; font-size: 11px; padding: 4px 4px 4px 4px;" onresize="SetScrollPosition()">
                                <asp:Literal Id="litMessages" runat="server" />
                            </div>
                        </td>
                        <td>&nbsp;</td>
                        <td>
                            <div id="divUsers" style="background-color: White; border-color:Black;border-width:1px;border-style:solid;height:300px;width:150px;overflow-y:scroll; font-size: 11px;  padding: 4px 4px 4px 4px;">
                               <asp:Literal Id="litUsers" runat="server" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:TextBox Id="txtMessage" onkeyup="ReplaceChars()" onfocus="SetToEnd(this)" runat="server" MaxLength="100" Width="500px" />
                            <asp:Button Id="btnSend" runat="server" Text="Send" OnClientClick="SetScrollPosition()" OnClick="BtnSend_Click" />
                            &nbsp;&nbsp;<b>Color:</b> <asp:DropDownList Id="ddlColor" runat="server">
                                <asp:ListItem Value="Black" Selected="true">Black</asp:ListItem>
                                <asp:ListItem Value="Blue">Blue</asp:ListItem>
                                <asp:ListItem Value="Navy">Navy</asp:ListItem>
                                <asp:ListItem Value="Red">Red</asp:ListItem>
                                <asp:ListItem Value="Orange">Orange</asp:ListItem>
                                <asp:ListItem Value="#666666">Gray</asp:ListItem>
                                <asp:ListItem Value="Green">Green</asp:ListItem>
                                <asp:ListItem Value="#FF00FF">Pink</asp:ListItem>
                            </asp:DropDownList>
                            &nbsp;
                            <asp:Button Id="btnLogOut" Text="Log Out" runat="server" 
                                OnClick="BtnLogOut_Click" />
                        </td>
                    </tr>
                </table>                
            </ContentTemplate>
        </asp:UpdatePanel> 
    </div>
    </form>   
</asp:Content>


matchchat.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Text;
using SkyBlueBarmy.Models;

namespace SkyBlueBarmy.Views.Chat
{
    public partial class matchchat : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
    {
        private string _callBackStatus;
        private SkyBlueBarmyDataContext db = new SkyBlueBarmyDataContext();
        Label lblRoomId;
        Label lblRoomName;
        TextBox txtMessage;
        ScriptManager ScriptManager1;
        DropDownList ddlColor;
        Literal litUsers;
        Literal litMessages;
        //Timer Timer1;

        public void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // for simplity's sake we're going to assume that a
                // roomId was passed in the query string and that
                // it is an integer
                // note: in reality you would check if the roomId is empty
                // and is an integer
                string roomId = (string)Request["roomId"];
                lblRoomId.Text = roomId;

                this.GetRoomInformation();
                this.GetLoggedInUsers();
                this.InsertMessage(ConfigurationManager.AppSettings["ChatLoggedInText"] + " " + DateTime.Now.ToString());
                this.GetMessages();

                // create a call back reference so we can log-out user when user closes the browser
                string callBackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "LogOutUser", "");
                string logOutUserCallBackScript = "function LogOutUserCallBack(arg, context) { " + callBackReference + "; }";
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LogOutUserCallBack", logOutUserCallBackScript, true);
            }
        }

        private void GetRoomInformation()
        {
            // get the room information from the database
            // we're going to set this up so that we can use
            // many rooms if we want to

            var room = (from r in db.Rooms
                        where r.roomid == Convert.ToInt32(lblRoomId.Text)
                        select r).SingleOrDefault();

            lblRoomId.Text = room.roomid.ToString();
            lblRoomName.Text = room.name;
        }

        public void BtnSend_Click(object sender, EventArgs e)
        {
            if (txtMessage.Text.Length > 0)
            {
                this.InsertMessage(null);
                this.GetMessages();
                txtMessage.Text = String.Empty;
                ScriptManager1.SetFocus(txtMessage.ClientID);
            }
        }

        public void Timer1_OnTick(object sender, EventArgs e)
        {
            this.GetLoggedInUsers();
            this.GetMessages();

            if ((string)Session["IsChatroomInFocus"] == null)
                ScriptManager1.SetFocus(txtMessage);
        }

        /// <summary>
        /// This will insert the passed text to the message table in the database
        /// </summary>
        private void InsertMessage(string text)
        {

            Message message = new Message();
            message.roomid = Convert.ToInt32(lblRoomId.Text);
            message.userid = Convert.ToInt32(Session["ChatUserID"]);

            if (String.IsNullOrEmpty(text))
            {
                message.text = txtMessage.Text.Replace("<", "");
                message.color = ddlColor.SelectedValue;
            }
            else
            {
                message.text = text;
                message.color = "gray";
            }

            //message.touserid = null;            // in the future, we will use this value for private messages
            message.timestamp = DateTime.Now;
            db.Messages.InsertOnSubmit(message);
            db.SubmitChanges();
        }

        private void GetLoggedInUsers()
        {
            // let's check if this authenticated user exist in the
            // LoggedInUser table (means user is logged-in to this room)
            var user = (from u in db.Logged_In_Users
                        where u.userid == Convert.ToInt32(Session["ChatUserID"])
                        && u.roomid == Convert.ToInt32(lblRoomId.Text)
                        select u).SingleOrDefault();

            // if user does not exist in the LoggedInUser table
            // then let's add/insert the user to the table
            if (user == null)
            {
                Logged_In_User loggedInUser = new Logged_In_User();
                loggedInUser.userid = Convert.ToInt32(Session["ChatUserID"]);
                loggedInUser.roomid = Convert.ToInt32(lblRoomId.Text);
                db.Logged_In_Users.InsertOnSubmit(loggedInUser);
                db.SubmitChanges();
            }

            string userIcon;
            StringBuilder sb = new StringBuilder();

            // get all logged in users to this room
            var loggedInUsers = from l in db.Logged_In_Users
                                where l.roomid == Convert.ToInt32(lblRoomId.Text)
                                select l;

            // list all logged in chat users in the user list
            foreach (var loggedInUser in loggedInUsers)
            {
                // show user icon based on sex
                if (loggedInUser.User.gender.ToString().ToLower() == "m")
                    userIcon = "<img src='Images/manIcon.gif' style='vertical-align:middle' alt=''>  ";
                else
                    userIcon = "<img src='Images/womanIcon.gif' style='vertical-align:middle' alt=''>  ";

                if (loggedInUser.User.username != (string)Session["ChatUsername"])
                    sb.Append(userIcon + "<a href=#>" + loggedInUser.User.username + "</a><br>");
                else
                    sb.Append(userIcon + "<b>" + loggedInUser.User.username + "</b><br>");
            }

            // holds the names of the users shown in the chatroom
            litUsers.Text = sb.ToString();
        }

        /// <summary>
        /// Get the last 20 messages for this room
        /// </summary>
        private void GetMessages()
        {

            var messages = (from m in db.Messages
                            where m.roomid == Convert.ToInt32(lblRoomId.Text)
                            orderby m.timestamp descending
                            select m).Take(20).OrderBy(m => m.timestamp);

            if (messages != null)
            {
                StringBuilder sb = new StringBuilder();
                int ctr = 0;    // toggle counter for alternating color

                foreach (var message in messages)
                {
                    // alternate background color on messages
                    if (ctr == 0)
                    {
                        sb.Append("<div style='padding: 10px;'>");
                        ctr = 1;
                    }
                    else
                    {
                        sb.Append("<div style='background-color: #EFEFEF; padding: 10px;'>");
                        ctr = 0;
                    }

                    if (message.User.gender.ToString().ToLower() == "m")
                        sb.Append("<img src='Images/manIcon.gif' style='vertical-align:middle' alt=''>  " + message.text + "</div>");
                    else
                        sb.Append("<img src='Images/womanIcon.gif' style='vertical-align:middle' alt=''>  " + message.text + "</div>");
                }

                litMessages.Text = sb.ToString();
            }
        }

        public void BtnLogOut_Click(object sender, EventArgs e)
        {
            // log out the user by deleting from the LoggedInUser table

            var loggedInUser = (from l in db.Logged_In_Users
                                where l.userid == Convert.ToInt32(Session["ChatUserID"])
                                && l.roomid == Convert.ToInt32(lblRoomId.Text)
                                select l).SingleOrDefault();

            db.Logged_In_Users.DeleteOnSubmit(loggedInUser);
            db.SubmitChanges();

            // insert a message that this user has logged out
            this.InsertMessage("Just logged out! " + DateTime.Now.ToString());

            // clean the session
            Session.RemoveAll();
            Session.Abandon();

            // redirect the user to the login page
            Response.Redirect("Default.aspx");
        }

        #region ICallbackEventHandler Members

        string System.Web.UI.ICallbackEventHandler.GetCallbackResult()
        {
            return _callBackStatus;
        }

        void System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            _callBackStatus = "failed";

            // log out the user by deleting from the LoggedInUser table

            var loggedInUser = (from l in db.Logged_In_Users
                                where l.userid == Convert.ToInt32(Session["ChatUserID"])
                                && l.roomid == Convert.ToInt32(lblRoomId.Text)
                                select l).SingleOrDefault();

            db.Logged_In_Users.DeleteOnSubmit(loggedInUser);
            db.SubmitChanges();

            // insert a message that this user has logged out
            this.InsertMessage("Just logged out! " + DateTime.Now.ToString());

            _callBackStatus = "success";
        }

        #endregion*/
    }
}

AnswerRe: Trying to implement an old chat application into MVC Pin
Not Active28-Nov-09 4:43
mentorNot Active28-Nov-09 4:43 
Questionhow to cretae web page more efficiant Pin
fak.kumar27-Nov-09 19:05
fak.kumar27-Nov-09 19:05 
AnswerRe: how to cretae web page more efficiant Pin
sashidhar27-Nov-09 19:48
sashidhar27-Nov-09 19:48 
Questioncreating an asp.net discussion web site Pin
Thilina.madush27-Nov-09 17:14
Thilina.madush27-Nov-09 17:14 
AnswerRe: creating an asp.net discussion web site Pin
Kannan Ar27-Nov-09 17:25
professionalKannan Ar27-Nov-09 17:25 
GeneralBuilding an ASP.NET P3P framework Pin
djechelon27-Nov-09 10:55
djechelon27-Nov-09 10:55 
QuestionInstall IIS on Visual Studio 2002-What server software for ASP.net Pin
andrew p jones27-Nov-09 10:30
andrew p jones27-Nov-09 10:30 
AnswerRe: Install IIS on Visual Studio 2002-What server software for ASP.net Pin
Christian Graus27-Nov-09 11:23
protectorChristian Graus27-Nov-09 11:23 
QuestionTreeView Selected Node Scroll Problem Pin
W4Rl0CK4727-Nov-09 6:16
W4Rl0CK4727-Nov-09 6:16 
AnswerRe: TreeView Selected Node Scroll Problem Pin
Abhishek Sur27-Nov-09 10:13
professionalAbhishek Sur27-Nov-09 10:13 
AnswerRe: TreeView Selected Node Scroll Problem Pin
Petr Pechovic27-Nov-09 10:32
professionalPetr Pechovic27-Nov-09 10:32 
GeneralExecute client Javascript after Ajax callback. Pin
Brady Kelly27-Nov-09 5:24
Brady Kelly27-Nov-09 5:24 
GeneralRe: Execute client Javascript after Ajax callback. Pin
Christian Graus27-Nov-09 5:28
protectorChristian Graus27-Nov-09 5:28 
GeneralRe: Execute client Javascript after Ajax callback. Pin
Abhishek Sur27-Nov-09 9:58
professionalAbhishek Sur27-Nov-09 9:58 
QuestionHow to programmatically add message in out of office (Outlook feature) using asp.net Pin
Manprit.bagga27-Nov-09 3:32
Manprit.bagga27-Nov-09 3:32 
AnswerRe: How to programmatically add message in out of office (Outlook feature) using asp.net Pin
Abhijit Jana27-Nov-09 3:49
professionalAbhijit Jana27-Nov-09 3:49 
QuestionRe: How to programmatically add message in out of office (Outlook feature) using asp.net Pin
Manprit.bagga27-Nov-09 17:37
Manprit.bagga27-Nov-09 17:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.