Anything similar to MessageBox.Show??

carpe2

Freshman
Joined
Jan 16, 2004
Messages
42
Location
Spain
Hi, i would like to know if there is something similar to...

MessageBox.Show("Insert only letters in the textbox");

in ASP.

Thanks.
 
In Web apps you can't use the MessageBox class, the only thing you can do is to use javascript to add this messageboxes "alert('Insert only letters in the textbox');"
 
the same way you do it in a Windows Forms app, but it won't work, you'll get an error inside the Event Viewer, MessageBox class is not intended to be used in a web application due security reasons
 
I see there is an error, but i mean if i can run the javascript from the .cs code and how can i do that if so,and if not what other things could I do...
I call a function to validate the text in the textboxes, and if there is an error, i´d like to show a message...

Thanks.
 
Here It Is...

I saw this in another forum
I think its very useful...

private void ShowMessage(string message)
{
String scriptString = "<script language=JavaScript>";
scriptString += "alert('" + message + "');";
//scriptString += "confirm('" + message + "');";
scriptString += "</script>";
//if(!this.IsStartupScriptRegistered("MessageBox"))
Page.RegisterStartupScript("ShowMessage", scriptString);
}

private void Button3_Click(object sender, System.EventArgs e)
{
ShowMessage("Please enter a user name");
}
 
carpe2 said:
Hi, i would like to know if there is something similar to...

MessageBox.Show("Insert only letters in the textbox");

in ASP.

Thanks.
try this. . .
1. Make a new form
2. Drop a System.Web.UI.WebControls.Literal on your page. . .
3. Set its Text Property to "<BUTTON ID={0}>Click Me!!!</BUTTON>";
4. add this code to the Literal's PreRender Event:

PHP:
private void Literal1_PreRender(object sender, System.EventArgs e)
{
string clickLink = Literal1.UniqueID+"ClickLink"; 
string clickEvent = Literal1.UniqueID+"ClickBlock";
string eventName = Literal1.UniqueID+"OnClick()";
 
//Link a function to the onclick event of the rendered literal
if (!(Page.IsClientScriptBlockRegistered(clickLink)))
	Page.RegisterClientScriptBlock(clickLink,
	 "\n\t<SCRIPT LANGUAGE=javascript FOR=" + Literal1.UniqueID + " EVENT=onclick>\n\t\t"+
	 eventName +";\n\t"+
	 "</SCRIPT>");
 
 
 
//Define the function for the onclick event of the rendered literal
 
if (!(Page.IsClientScriptBlockRegistered(clickEvent )))
	Page.RegisterClientScriptBlock(clickEvent ,
	 "<SCRIPT LANGUAGE=javascript>\n\t"+
	 "function " + eventName + "\n\t{\n\t\t"+
	 "//Perform some functionality here. . .\n\t\t"+
	 "alert(\"Here is your alert\");\n\t}\n\t"+
	 "</SCRIPT>"); 
 
 
 
//Set the HTML ID Attribute for your rendered literal
Literal1.Text = String.Format(Literal1.Text,Literal1.UniqueID);
 
 
}


this will render the following HTML

PHP:
	<SCRIPT LANGUAGE=javascript FOR=Literal1 EVENT=onclick>
Literal1OnClick();
</SCRIPT>
 
<SCRIPT LANGUAGE=javascript>
function Literal1OnClick()
{
	//Perform some functionality here. . .
	alert("Here is your alert"); 
}
</SCRIPT>
 
<BUTTON ID=Literal1>Click Me!!!</BUTTON>
 
Back
Top