0

hi guys

I have heard that for displaying message we generally use MSGBOX function in VB.NET and
we use ScriptManager.RegisterStartscript in ASP.NET to display message box...
but I have tried to use Msgbox function in ASP.NET and it works here also...
So is it ok to use Msgbox function in websites to display message or
there are some problems or issues related to it?
If yes then pls let me know..
:)

7
Contributors
11
Replies
13
Views
7 Years
Discussion Span
Last Post by serkan sendur
0

Actually here is an example with an alert on a server side control. This will cause an alert then a postback:

Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Alerter.aspx.cs" Inherits="daniweb.web.Alerter" %>
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    	<asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

Code behind:

using System;

namespace daniweb.web
{
  public partial class Alerter : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      Button1.Attributes.Add("onclick", "javascript:alert('hello');");  
    }
  }
}
0

ya i know that we should use alert function to display client side script in asp.net
but
i have msgbox function in my website and when I RUN the webpage it gives no error ..it works fine... ..
I want to know will that will it problems in real time deployment..??
I my PC that page runs well with MSGBOX function... but will it cause problems in realtime when website will be deployed to SERVER?

0

hey sknake,can u tell me one thing,that instead of writing Button1.Attributes.Add("onclick", "javascript:alert('hello');"); on button click event,Y we write it in Page Load event!

0

hey sknake,can u tell me one thing,that instead of writing Button1.Attributes.Add("onclick", "javascript:alert('hello');"); on button click event,Y we write it in Page Load event!

What?

0

ya i know that we should use alert function to display client side script in asp.net
but
i have msgbox function in my website and when I RUN the webpage it gives no error ..it works fine... ..
I want to know will that will it problems in real time deployment..??
I my PC that page runs well with MSGBOX function... but will it cause problems in realtime when website will be deployed to SERVER?

I don't know the answer to that -- go ahead and test it out. The MsgBox() call lies in the System.VisualBasic namespace and I do my best to avoid that namespace for compatibility reasons.

0

i agree with snake...

but i'm curious why do u need a feature like MessageBox..?

or there is another way but it's a long way..

0

'hey sknake,can u tell me one thing,that instead of writing Button1.Attributes.Add("onclick", "javascript:alert('hello');"); on button click event,Y we write it in Page Load event! '

This is used in the form load so that the Javascript is applied to the control once the form loads, otherwise this will only be applied to the control once you click on a button , therefore you will have to click the button twice.

1. to apply the JavaScript
2. to fire the javaScript

0

The form_load event fires server side to create the page -- not when the form loads at the browser end. Its just adding a client side event to the button -- the asp:button's click event is normally server side.

Is this what you are asking?

0
Create a class and add these two methods to it :

// for postback events
public static void ShowMessageBox(string _message)
    {
        Page page = HttpContext.Current.Handler as Page;
        page.RegisterStartupScript("key2", "<script>alert('" + _message +  "');</script>");
    }

// for async postback events
 public static void ShowMessageBoxForAsync(string _message)
    {
        Page page = HttpContext.Current.Handler as Page;
        ScriptManager.RegisterClientScriptBlock(page,page.GetType(), "key2", "alert('" + _message + "');", true);
    }

// 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) :
protected void myButton_Click(object sender, EventArgs e)
{
Utilities.ShowMessageBox("you entered a wrong password");
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.