Hello All,
I am Prashant More
I have one problem about MessageBox in ASP.NET
I have a textbox in which i want to put only digits and if any character appears then a messagebox must have to open showing a perticular message.Please someone send me the code its hurry for me.
My Email Ids are
Thanks & Regards
Prashant S.More

Niradhip ChakrabortyRank #429 · 5.8K reputationPosted May 8, 2008, 4:37 AM EDT
Say u have created a text box txtcphone and it doesnt allow user to enter character. Use the java script function as
follows and call it in pagebehind:
.aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ContactUs.aspx.cs" Inherits="Contents_ContactUs" %>
<%@ Register Src="../UserControls/Bottom1.ascx" TagName="Bottom" TagPrefix="uc2" %>
<%@ Register Src="../UserControls/Top1.ascx" TagName="Top" TagPrefix="uc1" %>
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">
function ValidatePhoneNo(Obj){
if(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))){
var Value = Obj.value;
var len = Value.length;
}
else{
alert("Phone No Cannot be a Character");
return false;
}
}
.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtCphone.Attributes.Add("OnKeyPress", "return ValidatePhoneNo(this)");
}
}
Prashant More87 reputationPosted May 9, 2008, 11:47 PM EDT
Thanks for reply sir its working but again i have a problem to validate only characters i.e. if any digit will be entered then a textbox must show the messagebox.I tried this like the following but it could not working.Please sir send me the code for character validation.Its hurry for me.
function ValidateName(Obj){
if(((window.event.keycode<48)&&(window.event.keycode>57))){
var Value=Obj.value;
var len=Value.length;
}
else
{
alert("Please Enter Name In Digits Only");
return false;
}
Thanks & Regards
Prashant S. More
Bechir BejaouiRank #144 · 15.9K reputationPosted May 10, 2008, 11:28 AM EDT
1. Create a class and add these two methods to it :
2.
3. // for postback events
4. public static void ShowMessageBox(string _message)
5. {
6. Page page = HttpContext.Current.Handler as Page;
7. page.RegisterStartupScript("key2", "");
8. }
9.
10.// for async postback events
11. public static void ShowMessageBoxForAsync(string _message)
12. {
13. Page page = HttpContext.Current.Handler as Page;
14. ScriptManager.RegisterClientScriptBlock(page,page.GetType(), "key2", "alert('" + _message + "');", true);
15. }
16.
17.// Then you can call this in, let's say , button_click event handler like this ( i assume that your class name is Utilities without any namespace definition) :
18.protected void myButton_Click(object sender, EventArgs e)
19.{
20.Utilities.ShowMessageBox("you entered a wrong password");
21.}