From: JB on
Hello Community

Using ASP.NET, C# and SQLServer code behind checks whether data
is entered into textbox.

If data was entered into a textbox then the next line of code executes.

If data was not entered into a textbox then I want to call a javascript
alert from the code behind that tells the user to enter data into the textbox
then executes the next line of code in the code behind.

I can use Response.Write to do that but it is not acceptable in this
case because the alert must appear on the same page.

How can I call a javascript alert from within my web page code behind
and still
execute the next line of the code in the code behind after calling the
javascript alert
has been called?

Thanks
Jeff
--
JB
From: Cubaman on
On Aug 1, 10:53 pm, JB <J...(a)discussions.microsoft.com> wrote:
> Hello Community
>
>     Using ASP.NET, C# and SQLServer code behind checks whether data
> is entered into textbox.  
>
>     If data was entered into a textbox then the next line of code executes.  
>
>     If data was not entered into a textbox then I want to call a javascript
> alert from the code behind that tells the user to enter data into the textbox
> then executes the next line of code in the code behind.
>
>     I can use Response.Write to do that but it is not acceptable in this
> case because the  alert must appear on the same page.
>
>     How can I call a javascript alert from within my web page code behind
> and still
> execute the next line of the code in the code behind after calling the
> javascript alert
> has been called?
>
>     Thanks
>     Jeff
> --
> JB

ClientScript.RegisterStartupscript(Type, Script, bool)
http://msdn.microsoft.com/en-us/library/aa479390.aspx

Also you can get the same results using asp.net validation controls..

http://www.w3schools.com/aspnet/aspnet_refvalidationcontrols.asp

Best regards
From: Brian Cryer on
"JB" <JB(a)discussions.microsoft.com> wrote in message
news:B79E8E41-EE8A-4CCA-AA8E-2429B5986C89(a)microsoft.com...
> Hello Community
>
> Using ASP.NET, C# and SQLServer code behind checks whether data
> is entered into textbox.
>
> If data was entered into a textbox then the next line of code executes.
>
> If data was not entered into a textbox then I want to call a javascript
> alert from the code behind that tells the user to enter data into the
> textbox
> then executes the next line of code in the code behind.
>
> I can use Response.Write to do that but it is not acceptable in this
> case because the alert must appear on the same page.
>
> How can I call a javascript alert from within my web page code behind
> and still
> execute the next line of the code in the code behind after calling the
> javascript alert
> has been called?

Will the built in validators do what you want (RequiredFieldValidator,
RangeValidator etc)? I know they don't generate an alert but they will
display a message.

If you go the route of writing your own custom "validators" then do be sure
to validate server side as well because if JavaScript is disabled in the
browser then your custom validators won't fire.
--
Brian Cryer
http://www.cryer.co.uk/brian