hai friends,

i cannot create the message box. the syntax i used is "MessageBox" . it gives the errror that namespace system.windows is not found. i searched with System.Windows i cannot found anything there.
so plz help

Dani AI

Generated

Short answer: a Windows "message box" is a desktop UI feature, not a browser feature. and were correct — server-side dialogs belong to desktop apps. The namespace confusion saw (System.Windows vs. System.Windows.Forms) explains the lookup error, but referencing System.Windows.Forms from an ASP.NET app is the wrong approach: any MessageBox.Show call would run on the server machine (and may hang the worker process), not on the visitor’s browser. ’s example therefore compiles only in special cases and is not a solution for web UIs.

Recommended patterns:

  • For quick, transient feedback use client-side notifications (JavaScript alert or a toast/modal library for better UX).
  • For server-generated messages in WebForms, set a hidden field or label on the server and let a small client script display it. This keeps encoding and lifecycle simple and avoids calling desktop APIs from server code.

Example (safe, simple WebForms pattern):

<!-- ASPX -->
<asp:HiddenField ID="hfMessage" runat="server" />

// Code-behind (C#)
hfMessage.Value = Server.HtmlEncode("Voter added successfully");

// In the page markup -->
<script>
document.addEventListener('DOMContentLoaded', function() {
  var msg = document.getElementById('<%= hfMessage.ClientID %>').value;
  if (msg) alert(msg);
});
</script>

Notes and troubleshooting:

  • If using UpdatePanel/partial postbacks, use the AJAX lifecycle (or ScriptManager) so the client code runs after an async update — and pointed to that idea.
  • Always escape/encode server text before placing it into HTML/JS to prevent injection (Server.HtmlEncode or JSON-serialize the string).
  • Prefer non-blocking UI (inline messages, toast libraries, or Bootstrap/SweetAlert) instead of alert() for production UX.
  • Never rely on System.Windows.Forms for browser interaction; it is for desktop apps only.

Recommended Answers

All 9 Replies

msgbox?

what messagebox? This is asp.net ... web pages.. what messagebox? message box is in windows forms projects not web pages.

Do you want to pop up a message to a user? you can use the javascript alert. Are you sure you understand the concept of asp.net? If not say so and we will try and explain it a bit

f1_fan is right
u can use msgbox in asp.net coz it will run on the server and not on the client side.
u can use alert fuction in the javascript, coz its client-side.

sorry, i mean "u can't use msgbox"

ok, i manage it. thanks for ur reply

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

System.Windows.Forms.MessageBox.Show("Voter is added to Voter List Sucessfully");

There is no message box in asp.net.
You can use this one.

Page pageCurr = HttpContext.Current.Handler as Page;
        if (pageCurr != null)
        {
            ScriptManager.RegisterStartupScript(pageCurr, pageCurr.GetType(), "aKey", "alert('" + "you message" + "');", true);
        }

use this instead of msgbox

ClientScript.RegisterStartupScript(Me.GetType(), "OhNo", "alert('Your Message');", True)

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.