?
Solved

I need help using message boxes in ASP.Net 3.5

Posted on 2011-05-03
8
Medium Priority
?
258 Views
Last Modified: 2012-05-11
Hi Experts,
How are MessageBoxes used in ASP.Net 3.5?  Can anyone please provide

Thanks in advance,
mrotor
0
Comment
Question by:mainrotor
8 Comments
 
LVL 7

Expert Comment

by:JosephEricDavis
ID: 35515181
Maybe we need a little more detail on what your after.

Here is a page that might be on track with what your after.
http://www.codeproject.com/KB/webforms/AspNetMsgBox.aspx

Let us know if this is what you're going for of if it is something else.  If it is something else, please elaborate.
0
 
LVL 9

Expert Comment

by:sarabhai
ID: 35515314
you can use

Response.write("<script>alert('successfully');</script>");
0
 
LVL 13

Accepted Solution

by:
Rick earned 1000 total points
ID: 35515377
Here's an example:
Sub UpdateValues()

' Validate user input...
' Update values ...

' If bolUpdateSuccess = True Then

Response.Write("<script language='JavaScript'>alert('Update Successful.');window.location=self.location;</script>")

' End If

End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:JosephEricDavis
ID: 35515403
If all you are going for is a javascript alert to pop up on the page that you trigger from the code behind, then a cleaner way of doing it is like this...

ScriptManager.RegisterStartupScript(this, this.GetType(), "showPopupMessage", "alert('Your Message');", true);

You would just need to include a ScriptManager control in the markup of your page in order to do this.
<asp:ScriptManager runat="server" ID="scrptMngr"></asp:ScriptManager>
0
 

Author Comment

by:mainrotor
ID: 35632477
In my application I have a TextBox where the user enters a Record Number.  When the user clicks on a button, I query the DataBase using the Record Number provided by the user.  If the Record Number is not found, I want to use a PopupMessage that Prompts the user to enter a correct Record Number, wiith the "OK" button.

regards,
mrotor
0
 
LVL 14

Assisted Solution

by:dejaanbu
dejaanbu earned 1000 total points
ID: 35688183

Have a general function
Public Sub MessageDialog(ByVal sPage As Page, ByVal msg As String)
     
            Dim sb As New StringBuilder()
            sb.Append("alert('")
            sb.Append(msg)
            sb.Append("');")

            sPage.ClientScript.RegisterStartupScript(sPage.GetType, "showalert", sb.ToString(), True)
    End Sub

Open in new window


And call this function, whenever u need message box in ur webpage as
MessageDialog(Me,"My Message Text")

Open in new window


This is in vb code..if u need C#, let us know


0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 35688191
the reason why i didnt use Response.write is, if u r going to use updatepanel, response.write wil make problems
0
 
LVL 7

Expert Comment

by:JosephEricDavis
ID: 35690983
An update panel would definitely be the right way to go in this case.

In the aspx file you can add mark up similar to this...

<asp:ScriptManager runat="server" ID="scrptMngr" />
<asp:UpdatePanel runat="server" ID="upCheckID" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:TextBox runat="server" ID="txtID" />
        <asp:Button runat="server" ID="btnCheckID" OnClick="btnCheckID_OnClick" />
    </ContentTemplate>
</asp:UpdatePanel>

Then in the code behind you can add code similar to this...

protected void btnCheckID_OnClick(object sender, EventArgs e)
{
    //Code to check the database id
    if (your conditional logic)
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "showPopup", "alert('Your Message');", true);
    }
}

The update panel will capture the button click and fire off the asynchronous request to your sever to run your database query and then if necessary return the startup script to display your message box.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question