I am working on a ASP.NET 4 assignment but am stuck on nuber 6 how do I do a cll
ID: 3681973 • Letter: I
Question
I am working on a ASP.NET 4 assignment but am stuck on nuber 6 how do I do a cllback to check server status. Have seen examples of call back for database and to have the server do something. but question six has me stumped. I had posted this before but forgot to say I was using VB not C#.
1.) Modify your page from week 1 (the one with the codebehind code) to add all relevant attributes for your item. Include at least 5 attributes and at least 2 data types (example: a coin's item name is a string and its weight is a floating point number).
2.) Delete the page that uses inline code since the project architect insists that all pages use only codebehind code. 3.)Create a "Home.aspx" page that displays a welcome message for your application.
4.)Change the project's settings to display the "Home" page when the project runs instead of the "Insert" page.
5.) Add a "Cancel" button that will redirect to "Home.aspx" when clicked.
6.) Add a button to "Home.aspx" called "Check System Status." When clicked, this button will initiate a client callback to the server. The server-side method will return a string indicating that the server is online. Display this response as a JavaScript popup. Do not use a full page postback. Use a client callback. ( I am using VB.NET)
HTML --- file Home.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Home.aspx.vb" Inherits="JimHawthorneMusic.WebForm2" %>
<script src="JavaScript.js" type="text/javascript"></script>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Jim's Music Home</title>
<link href="StyleSheet1.css" rel="stylesheet"type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="home">
<section id="firstsentence">
<br />
<h2>Jim's Music Listings</h2>
<h3> Home Page</h3></section>
<section id="buffer" class="auto-style1">
</section>
<section id="Musicbutton" class="auto-style2">
<table class="auto-style9">
<tr>
<td class="auto-style5">
<asp:Button ID="btnMusic" runat="server" Text="Music" ForeColor="Black" Height="30px" Width="100%" />
</td>
<td class="auto-style8"></td>
<td class="auto-style4">
<asp:Button ID="btnCheckSysStat" runat="server" Text="Check System Status" ForeColor="Black" Height="30px" Width="100%" />
</td>
</tr>
</table>
</section>
</div>
</form>
</body>
</html>
VB -- file Home.aspx.vb
Public Class WebForm2
Inherits System.Web.UI.Page
Partial Class CallBack_DB_aspx
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Public Sub RaiseCallbackEvent(eventArgument As String) Implements ICallbackEventHandler.RaiseCallbackEvent
Throw New NotImplementedException()
End Sub
Public Function GetCallbackResult() As String Implements ICallbackEventHandler.GetCallbackResult
Throw New NotImplementedException()
End Function
End Class
Protected Sub btnMusic_Click(sender As Object, e As EventArgs) Handles btnMusic.Click
Response.Redirect("Music.aspx")
End Sub
Protected Sub btnCheckSysStat_Click(sender As Object, e As EventArgs) Handles btnCheckSysStat.Click
End Sub
End Class
Explanation / Answer
Under Home.aspx:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Home.aspx.vb" Inherits="JimHawthorneMusic.Home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Jim's Music Home</title>
<link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
<script src="JavaScript.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="home">
<section id="firstsentence">
<br />
<h2>Jim's Music Listings</h2>
<h3>Home Page</h3>
</section>
<section id="buffer" class="auto-style1">
</section>
<section id="Musicbutton" class="auto-style2">
<table class="auto-style9">
<tr>
<td class="auto-style5">
<asp:Button ID="btnMusic" runat="server" Text="Music" ForeColor="Black" Height="30px" Width="100%" />
</td>
<td class="auto-style8"></td>
<td class="auto-style4">
<%--<asp:Button ID="btnCheckSysStat" runat="server" Text="Check System Status" ForeColor="Black" Height="30px" Width="100%" />--%>
<input id="btnCheckSysStat" type="button" value="Check System Status" />
</td>
</tr>
</table>
</section>
</div>
</form>
</body>
</html>
================================================================================
Under Home.aspx.vb:
-------------------------------
Partial Public Class Home
Inherits System.Web.UI.Page
Implements System.Web.UI.ICallbackEventHandler
Public FromServer = "Server val"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsCallback Then
Return
End If
Dim cbReference = Page.ClientScript.GetCallbackEventReference(Me, "arg", "ReceiveServerData", "")
'Putting the reference in the method that will initiate Callback
Dim callbackScript = "function CallServer(arg, context) {" + cbReference + "; }"
'Registering the method
Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), "CallServer", callbackScript, True)
End Sub
Protected Sub btnMusic_Click(sender As Object, e As EventArgs) Handles btnMusic.Click
Response.Redirect("Music.aspx")
End Sub
'Protected Sub btnCheckSysStat_Click(sender As Object, e As EventArgs) Handles btnCheckSysStat.Click
'End Sub
Public Sub RaiseCallbackEvent(eventArgument As String) Implements ICallbackEventHandler.RaiseCallbackEvent
FromServer = "server is online"
End Sub
Public Function GetCallbackResult() As String Implements ICallbackEventHandler.GetCallbackResult
Return FromServer
End Function
End Class
===========================================================================
Under javaScript.js
---------------
function InitiateCallBack() {
CallServer('', '');
}
// Called after the server side processing is done
function CallServer(arg, context) {
alert('Calling server');
}
function ReceiveServerData(arg, context) {
//arg: hold the result
alert(arg);
}
================================
under Music.aspx:
----------------------------
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Music.aspx.vb" Inherits="JimHawthorneMusic.Music" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome Misic Page
<br />
<asp:Button ID="btnCancle" runat="server" Text="Cancle" />
</div>
</form>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.