say i have form 1 with a method SHOWME() and i want to call this method from form 2 (seperate window) cant his be done?

Dani AI

Generated

This depends on what you mean by "form." If these are browser windows (ASP.NET pages) the problem and solutions are very different from desktop Windows Forms. asked the right question; and pointed at two different directions — one is a direct in-memory call, the other is moving logic out of a single page — but each approach has constraints worth calling out.

For web pages: HTTP is stateless, so you cannot remotely execute server-side code inside another browser window's page instance. Two pragmatic options work better long-term: move the shared business/UI logic into a central place the pages both call (shared class or service), or use client-side messaging between windows. If the popup and opener are same-origin you can use the opener reference; for cross-origin communication use postMessage (see MDN for details). Centralizing server logic also makes testing and reuse much easier than trying to force cross-page calls.

For desktop (Windows Forms) applications: forms are real objects and you can invoke a public method on another form instance if you hold a reference. Prefer decoupling with events or a shared controller rather than tight coupling. When calling across threads, marshal back to the UI thread (Invoke/BeginInvoke) to avoid exceptions. Also check that the target instance is not null/disposed and that access modifiers allow the call.

Quick troubleshooting checklist: confirm whether the environment is web or desktop; verify you have an actual instance reference; check access modifiers; observe same-origin/security rules in the browser; watch for cross-thread UI calls; and prefer extracting shared behavior into a reusable component or API for maintainability. This keeps the design clean and avoids brittle, hard-to-debug cross-form hacks.

References: Window.opener and cross-window messaging (postMessage) on MDN — https://developer.mozilla.org/en-US/docs/Web/API/Window/opener and https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage.

Recommended Answers

All 2 Replies

form2.showme()

Though it seems that classes of different forms do not see each other. It may be more reasonable to create some additional class in AppCode and put method showme() there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.