I'm afraid that the only way to do that is using client-side functionality.
MsgBox will only work if you use VBScript, which will work in Internet Explorer only
<script type="text/vbscript">
Function showMsgBox()
MsgBox("Hello")
End Function
</script>
If you do not want to add it as an attribute of a control, this will work:
private void someFunction()
{
string javaScript = "<script type=text/javascript>alert('Hello');</script>";
RegisterStartupScript("AlertScript", javaScript);
}
Create a function like this... in ur cs file
public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "<script language=JavaScript>alert('" + strMessage + "')</script>";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}
And then call this function like this where ever you want to show your msgbox..
My problem is not yet solved. I have a masterpage and an update panel. I have to show the message form this update panel. Your code work nicely in a simple page but not in my page.
I think none of above answer will meet your need as all they are using javascript any way, either regestering the script or directly writing javascript function.
Better way is to use AJAX tookit confirm button as I told you if you can use.
Nepster from India [Yes]
Mark this post answer if it clear your doubts.
Hope this will help!
Nepster from India Note: Please mark this post as answer if it help you.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: MessageBox in asp.net
Mar 19, 2008 12:48 PM|LINK
I'm afraid that the only way to do that is using client-side functionality.
MsgBox will only work if you use VBScript, which will work in Internet Explorer only
<script type="text/vbscript">
Function showMsgBox()
MsgBox("Hello")
End Function
</script>
Similar JavaScript functions are:
window.alert:
http://www.w3schools.com/htmldom/met_win_alert.asp
window.confirm:
http://www.w3schools.com/htmldom/met_win_confirm.asp
window.prompt
http://developer.mozilla.org/en/docs/DOM:window.prompt
If you do not want to add it as an attribute of a control, this will work:
private void someFunction()
{
string javaScript = "<script type=text/javascript>alert('Hello');</script>";
RegisterStartupScript("AlertScript", javaScript);
}
Note that RegisterOnSubmitStatement, RegisterStartupScript, RegisterClientScriptBlock, etc have changed since version 1.1 and you will get a compiler warning with the above.
See http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx for more info.
NC...
Careed
All-Star
18764 Points
3637 Posts
Re: MessageBox in asp.net
Mar 20, 2008 03:50 AM|LINK
"The oxen are slow, but the earth is patient."
khushiS
Member
42 Points
25 Posts
Re: MessageBox in asp.net
Mar 20, 2008 04:05 AM|LINK
You can try this....
Create a function like this... in ur cs file
public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "<script language=JavaScript>alert('" + strMessage + "')</script>";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}
And then call this function like this where ever you want to show your msgbox..
string strMessage = "Your message goes here";
CreateMessageAlert(this.Page, strMessage, "strKey1");
It works very nicely.
Let me know if this resolves your problem or not.
Regards,
Khushi
shihab_alraj...
Member
9 Points
27 Posts
Re: MessageBox in asp.net
Mar 20, 2008 05:18 AM|LINK
Hi Khushi,
My problem is not yet solved. I have a masterpage and an update panel. I have to show the message form this update panel. Your code work nicely in a simple page but not in my page.
Can u help me.
Dont forgot to mark as answer
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: MessageBox in asp.net
Mar 20, 2008 08:34 AM|LINK
Hi,
if you are using Update panel try below one...
Page.ScriptManager.RegisterStartupScript(this, this.GetType(),"ale","alert('Hi');",true);
Software Engineer.
nepster_from...
Member
334 Points
63 Posts
Re: MessageBox in asp.net
Mar 20, 2008 10:18 AM|LINK
Hi
I think none of above answer will meet your need as all they are using javascript any way, either regestering the script or directly writing javascript function.
Better way is to use AJAX tookit confirm button as I told you if you can use.
Nepster from India [Yes]
Mark this post answer if it clear your doubts.
Nepster from India
Note: Please mark this post as answer if it help you.
Sam.Dev
Participant
1390 Points
342 Posts
Re: MessageBox in asp.net
Mar 20, 2008 10:30 AM|LINK
You are about to redirect to some other page are you sure want to do
it?<br /> <asp:Button ID="btnCancel" runat="server" Text="Cancel" /> <asp:Button ID="Button5" runat="server" OnClick="Button5_Click" Text="OK" /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></asp:Panel>u can put any thing in the panel like images in ur case u want to show.
hope this helps
--Mark the post as Answer if the Post helps you--
shihab_alraj...
Member
9 Points
27 Posts
Re: MessageBox in asp.net
Mar 20, 2008 10:41 AM|LINK
I have got the following error
Error: 'System.Web.UI.Page' does not contain a definition for 'ScriptManager'
Dont forgot to mark as answer
vasanth.kuma...
Contributor
5324 Points
1041 Posts
Re: MessageBox in asp.net
Mar 20, 2008 10:56 AM|LINK
Hi,
soryy .. no need for page in that...
simply use ..
ScriptManager
.RegisterStartupScript(this, this.GetType(), "ale", "alert('Hi');", true);Software Engineer.
Talib_dotnet
Contributor
2162 Points
458 Posts
Re: MessageBox in asp.net
Mar 20, 2008 11:00 AM|LINK
Hi Shihab,
Just add the following code at the top of the code i.e;
<div>
<
asp:ScriptManager ID="ScriptManager1" runat="server" /></div>
Because for using AJAX Controls , you need to have a ScriptManager .
Hope this helps you. If not then please let me know.
------
TALIB ALI KHAN
MICROSOFT CERTIFIED TECHNOLOGY SPECIALIST
Chief Technology Architect
MCTS
OnlineASP.Net
A-S-P Arabia...Consult Us