Solved

Calling a function in different page from another page

Posted on 2016-10-05
6
39 Views
Last Modified: 2016-10-13
Hi,

I understand that a class needs to be created in order to do this.  But what if there is nothing to return? Say, I just want to have a msg box popup?

thanks
0
Comment
Question by:mcrmg
  • 3
  • 3
6 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 41830035
But what if there is nothing to return? Say, I just want to have a msg box popup?
In general, you can do "whatever" you want in the class, you can call a method in a class to do a message pop up, or return some objects, or variables if you want to,or you can even call a method of a class to accomplish something but without return anything.

all depends on what you want to do with your self-defined class.
0
 

Author Comment

by:mcrmg
ID: 41830040
I am testing a method. But I am getting error

CS1520: Method must have a return type

public class test
{
	public test1()
	{
        protected void test_Click(object sender, EventArgs e)
        {

             System.Windows.Forms.MessageBox.Show("HERE");



        }
	}
}

Open in new window

0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 41831077
are you trying to do this in asp.net? if yes, try this:

web front:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="test" %>
...
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

Open in new window

code behind:
public partial class test : System.Web.UI.Page
    {
        protected void Button1_Click(object sender, EventArgs e)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "msg", "alert('HERE')", true);
        }
    }

Open in new window


MessageBox is used for window applications
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mcrmg
ID: 41840193
Sorry for the late reply.

It works.  thank you.

What if there are a few function I would like to share across the board?  Is there a way to do it?  thanks
0
 
LVL 51

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41841381
What if there are a few function I would like to share across the board?  Is there a way to do it?
yes, you can similarly. but you probably need to defined shared (static) classes then.

as a start, you can refer to:

Static Classes and Static Class Members (C# Programming Guide)
https://msdn.microsoft.com/en-us/library/79b3xss3.aspx
0
 

Author Closing Comment

by:mcrmg
ID: 41842628
thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question