Link to home
Start Free TrialLog in
Avatar of mcrmg
mcrmg

asked on

Calling a function in different page from another page

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
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

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.
Avatar of mcrmg
mcrmg

ASKER

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

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
Avatar of mcrmg

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mcrmg

ASKER

thank you