Link to home
Create AccountLog 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
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of mcrmg

ASKER

thank you