Msgbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • totomalas
    New Member
    • Aug 2009
    • 31

    Msgbox

    I am developing a website that uses ASPX and CS files...

    I have three check boxes and a button... if the user presses a button without checking any checkbox then i want to give a warning message to the user "Please select atleast one".

    in VB i used to write

    MsgBox("Please select atleast one")

    but i dont know how i can do it in the web... please help on how to give the messagebox...
  • sanjib65
    New Member
    • Nov 2009
    • 102

    #2
    Validation Control

    You can specify that a user must provide information in a specific control on an ASP.NET Web page by adding a RequiredFieldVa lidator control to the page and linking it to the required control.
    The steps are:
    1) Add a RequiredFieldVa lidator control to the page and set the following properties:

    ControlToValida te: The ID of the control for which the user must provide a value.

    ErrorMessage, Text, Display: Properties that specify the text and location of the error or errors that will appear if the user skips the control. For details, see :

    http://http://msdn.microsoft.com/en-.../1ze30x3t.aspx

    Code:
    <asp:CheckBox id="SomeThing" runat="server"></asp:CheckBox>
    <asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server"
      ControlToValidate="txtLastName"
      ErrorMessage="You have to select a field."
      ForeColor="Red">
    </asp:RequiredFieldValidator>
    For further reading you can check this link:

    http://http://msdn.microsoft.com/en-.../bwd43d0x.aspx

    Comment

    • sanjib65
      New Member
      • Nov 2009
      • 102

      #3
      Validation Control

      I have forgotten to add one more thing. Besides Framework Validation controls you can Validate Programmaticall y for ASP.NET Server Controls. You can learn about that in:

      http://http://msdn.microsoft.com/en-.../hxet6xwx.aspx

      Secondly, you can create custom validation logic on the client. To read further:

      http://http://msdn.microsoft.com/en-.../f5db6z8k.aspx

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        I just want to add to Sanjib65 response.

        You have to use JavaScript to display a "MsgBox" in ASP.NET

        MsgBox isn't going to work very well for you. You could force it to use MsgBox (quite easily) but in order for MsgBox to work it has to use the Windows.Forms message box component. In order to use this component you'll have to run an ActiveX component in your web page.

        ActiveX components only run in Internet Explorer and they are commonly prevented from running because they access the client's operating system. This can be very dangerous: the ActiveX control could be malicious in nature and anything from the web should be considered unsafe. Even if the ActiveX control is not malicious, it could be insecure and could open security vulnerabilities just by sitting on the client's computer.

        So, ActiveX controls are always advised against. In a secure, well designed web application, web page should never be accessing the operating system. Especially if it's something as simple as displaying a message window.

        JavaScript is a client-side scripting language that runs in the web browser. It does things that the server can't, like displaying a message box.

        To display a message box using JavaScript you use: alert().

        So, if your page doesn't validate you need to display a JavaScript alert with the message that you want to display to the user.

        Please check out this article on how to use JavaScript in ASP.NET for more information.

        Please know that it is easy to get around JavaScript (client-side) validation.
        You should Always validate data provided by the user server side.

        -Frinny

        Comment

        Working...