Hi guys, I have an urgent question: i built a form in html and past it to an aspx file. After that i went to aspx.cs and added a button , it should make a messegebox to appear after the onclick event in cs. there are two problems: the first: the messegebox doesn't appear after the button has been cliked . the second: how come the cs file doesn't recognize the controls i made in html? how can i manipulate the data from my text fields to other controls in cs... thanx a lot and this is the code in cs: public partial class Default2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void FormGO_Click(object sender, EventArgs e) { messegbox.show("plain text");/// it isn't recognizeble to the compiler } } Code (markup): and this is the code from aspx file: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <input type="text" id="FirNam"/> <input type="text" id="SurNam"/> <asp:Button ID="FormGO" runat="server" Text="Button" OnClick="FormGO_Click" /> </form> </body> Code (markup):
Could it be the misspelling of messagebox? Or perhaps it should be MessageBox.Show("plain text");? Nearly everything in C# is UpperCamelCase.
when i start writeing the word m the program usually uses the autocomplicity and gives the list of the objects and method that are relevent but this isn't the case.. is there anything else that can be possible?
You cannot display message box this way in web site based on asp.net. You must use client scripting http://www.beansoftware.com/ASP.NET-Tutorials/Message-Box.aspx
Why not? I think you guys are wrong... You can use MessageBox.Show("text") in ASP.NET Web forms, but firstly you have to put using System.Windows.Forms; It can be used for example like in the following way: if (MessageBox.Show("Are you sure you want to proceed?", "Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) { MessageBox.Show("You have clicked YES") // do some more actions } else { MessageBox.Show("You have clicked NO") }
Yea like hajan said it works. The messagebox shows in Firefox and IE. However if you have two screens and you show the website on the second screen the message box pops up on the first screen.
MessageBox.Show() will only work when you are using visual studio .... It will not work once you deploy the application , you will need to use client side code
Yes. The MessageBox.Show() will work but won't be shown to the user if the application is deployed because it will prompt and show up only in the Server, so the user (Client side) won't see it at all. This occurs because as I said previously, MessageBox.Show() uses 'using System.Windows.Forms;' ... so won't work on ASP.NET Applications when deployed. Instead, you can use JavaScript.
yes you can display messagebox in the asp.net you need to use or include "using System.Windows.Forms;" before it ypu have to add refernce by right click on the projct and the from option"Add reference"and the add System.Windows.Forms then you can get result.
You try, Response.write() function instead of MessageBox.Show(). MessageBox.Show() will not work in the web development...
For client side code.. I have another good method... If you have ASP Button Server Control... You can add attributes to this button with JavaScript client-side code.. Something like the following code: In progfrog case we have: <asp:Button ID="FormGO" runat="server" Text="Button" OnClick="FormGO_Click" /> Just remove this OnClick="FormGo_Click" <asp:Button ID="FormGO" runat="server" Text="Button" /> and in your code-behind the page (C# or VB.NET) add: (C#) FormGo.Attributes.Add("onclick", "javascript:if(confirm('Are you sure?')==true) return true;"); I think using this code, you will implement complete client side validation with MessageBox and asking the user to proceed with CLICKING THE BUTTON or NOT... Try it.. u will find it useful
Like the others said, you cannot use messagebox.show at all when deployed. I would stop using it all together when developing web apps with asp.net. Bad habit. You can create messages and javascript from your codebehind. (Somepage.vb) Try this to see how it works. I feel it's the best and proper method. http://msdn.microsoft.com/en-us/library/system.web.ui.page.registerclientscriptblock.aspx