I cant use javascript because i need server side script.
It's pointless trying to raise alerts on the server. No one will ever see it unless they are in the datacenter with a monitor plugged into the (probably) virtual server that your hosted site will be running on.
Well basically what I am trying to do is whenever a user inputs wrong information on input field a messagebox appears alerting them the input field is not right. I dont know if that functionality is present in CSHTML.
There is no need for message boxes for form input. That is all handled much more elegantly by standard functionality in the starter site template.
Are you using the starter site template? If not play with that first because it does have a worked out example of the validation rules for the login in form.
In the upper link, you can see that there are alot of examples that you can use to check that is the user inserting the exact value that you want him to!
All you need to do is to place an alert("") at the end of the code and the code will be handled by server!
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
Marked as answer by Angie xu - MSFT on Feb 18, 2013 01:43 AM
sub2013
0 Points
15 Posts
Messagebox in CSHTML
Feb 01, 2013 12:01 AM|LINK
Hi guys I ran into problem. I would appreciate your advice/suggestion.
Is there messagebox like in c# in CSHTML?? I am writing a code in Webmatrix. I have a if statement..Below is the example.
If(Dateinput != mydate){
Messagebox("This is a blkout Date")
}else{
// some code
}
thaicarrot
Contributor
5130 Points
1464 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 12:22 AM|LINK
What are your problem? Should not using the JavaScript?
Weera
sub2013
0 Points
15 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 12:30 AM|LINK
I cant use javascript because i need server side script. Also, I am querying my database. Is there a alert or messagebox method I can implement.?
wavemaster
Participant
1279 Points
1127 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 01:18 AM|LINK
The server side functionality is provided by Razor C #, is it not?
Here is how it works on one of my pages.
In the code section I query the database and massage the information so I can be displayed in the client section.
In the client section (HTML + Razor) I display the information. In my case a dialog box that says you cannot do this, because....
Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: Messagebox in CSHTML
Feb 01, 2013 05:02 AM|LINK
It's pointless trying to raise alerts on the server. No one will ever see it unless they are in the datacenter with a monitor plugged into the (probably) virtual server that your hosted site will be running on.
See this article on Validation for ideas about how you present "alerts" to users when they provide the wrong information: http://www.mikesdotnetting.com/Article/191/Validation-In-Razor-Web-Pages-2
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Afzaal.Ahmad...
Contributor
2660 Points
1039 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 09:00 AM|LINK
For you this block is a server side block
@{ var userGreeted = "Hi, You are greeted!"; }Right?
So Javascript blocks can be used there too. They won't be shown to the user, if you are afraid to loose your hard work to a user! Here do this
@{ if(Dateinput != mydate){ alert("This is not the Date being expected!"); }else{ // some code }This would be prefered if you use
@{ if(Dateinput != mydate){ alert("This is not the Date being expected!"); }else{ alert("This is exact Date"); } }Note: This code is server side. So for this you will need to execute the code to get the result for Dateinput! By requesting the Form.
~~! FIREWALL !~~
sub2013
0 Points
15 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 12:36 PM|LINK
Well basically what I am trying to do is whenever a user inputs wrong information on input field a messagebox appears alerting them the input field is not right. I dont know if that functionality is present in CSHTML.
wavemaster
Participant
1279 Points
1127 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 12:52 PM|LINK
There is no need for message boxes for form input. That is all handled much more elegantly by standard functionality in the starter site template.
Are you using the starter site template? If not play with that first because it does have a worked out example of the validation rules for the login in form.
Robert
wavemaster
Participant
1279 Points
1127 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 01:07 PM|LINK
When you run the starter site, go to the register page and then put in fewer than 6 character in password and click on register.
Afzaal.Ahmad...
Contributor
2660 Points
1039 Posts
Re: Messagebox in CSHTML
Feb 01, 2013 04:36 PM|LINK
That can be handled by Validation too. Like if you want a user to input something like a number but he inputs words you can tell him DO NOT DO THIS.
For example if you want a field to be written. But user leaves it. You can tell the user that this is required with this code
http://www.asp.net/web-pages/tutorials/working-with-pages/validating-user-input-in-aspnet-web-pages-sites
In the upper link, you can see that there are alot of examples that you can use to check that is the user inserting the exact value that you want him to!
All you need to do is to place an alert("") at the end of the code and the code will be handled by server!
~~! FIREWALL !~~