?
Solved

Need a recommendation for ASPX code – a message to the user.

Posted on 2013-01-05
5
Medium Priority
?
296 Views
Last Modified: 2013-01-05
Dear experts

I’m a professional programmer with 10+ years in business, but new to ASPX coding and need little help. When my user click on Submit button I do some check with such kind of code:
            if (byteState == 2)
            {
                Page.RegisterStartupScript("codice", "<script>alert('User with such email already extist! Probably this mean that this user is already register and do not need new registration!');</" + "script>");
                txtMail.Focus();
                return;
            }

It works, but I get warning that this metod is decprated. Could you recommended me what code I should use? Also, please give me example how I’m possible to show new line in the message.

 Other metod I use for message to the customer is with this code:
                    CustomMessage = "alert('Unexpected error in spUsers save record to local DB');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "CustomMessage", CustomMessage, true);

It is provided from this library:
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

Is this a good option? It look to me that it require to load a whole script library between 10 and 15 kb. In size, is that true???

 My primary dermands is
1)      To use a standart commands, which will be supported in next 5 years from all WEB brousers.
2)      To save internet traffic.
0
Comment
Question by:dvplayltd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Expert Comment

by:alhalama
ID: 38746943
You can accomplish this without the AJAX Extensions by using a Literal on your page that you can put script into:

<Literal runat="server" EnableViewState="false" id="javaScriptPlaceHolder"/>

In code you would then set the text of the Literal to be your script:

javaScriptPlaceHolder.Text = CustomMessage;

To control when you show the script you can either move it on the page or put it within a function that you call from the onload event of the body.
0
 

Author Comment

by:dvplayltd
ID: 38746987
Do not seem very practical ... how, where to move code? I prefer to use a solution in c# code only.
0
 

Assisted Solution

by:alhalama
alhalama earned 400 total points
ID: 38747133
It doesn't seem very practical to show an alert to a user from C# code at all since that is running on the server and this is disconnected from the client.  How many websites do you see that actually show alerts?  Wouldn't it be better to display a message to the user in the page in which case you wouldn't need to dynamically generate JavaScript at all.

If you still want a C# only solution, you could create a Literal control in code and add it to the pages control collection and it will be at the end of your page.  Note that you will want to make sure that you set EnableViewState to false or set the Text before adding the control to the pages controls collection to avoid having extra data being stored in ViewState.

As far as your current method being deprecated an needing to work in all web browsers for five years, consider what is deprecated and what is running on the server.  The method to register the client side script is a server side method so it relies on the .NET assemblies that you put on the web server and those will continue to work as long as you don't upgrade the assemblies used by your application on the server.  As far as what is running in the client (web browser), it is the script that you dynamically generate plus some other script to call your script at the appropriate time.

I would recommend taking time to learn the platform that you are on and understand what you are doing.
0
 
LVL 18

Accepted Solution

by:
dj_alik earned 1600 total points
ID: 38747194
Answers:
1.Replace  Page.RegisterStartupScript to Page.ClientScript.RegisterStartupScript:
ClientScriptManager Class
2.How to alert multiline in RegisterStartupScript?
0
 

Author Closing Comment

by:dvplayltd
ID: 38747515
To alhalama

"I would recommend taking time to learn the platform that you are on and understand what you are doing. "

 You are damm right, but who and for what have enoght time to go to details??? In our world where the final result should be done for impossible short time ...

To dj_alik

Your answer is very precise, thank you! I'll use it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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