Library sample chapters

ASP.NET Web Forms

Introduction

This is a sample chapter from Pure ASP.NET.

At the most basic level, an ASP.NET Web form looks remarkably like a regular HTML page. It is a text file that contains markup language that can be edited in a simple text editor such as notepad. However, an ASP.NET Web form has several "distinguishing elements, which are discussed in this chapter:

  • Web forms contain blocks of code that are processed on the server.

  • The first time a Web form is requested, the entire page is compiled. Subsequent requests are served from this compiled page.

  • Web forms can contain page directives, which are global settings for the page. Common page directives enable you to turn off session state and ViewState management.

  • Web forms can contain both server-sides, including SSIs, which enable you to dynamically insert the contents of a file into your Web form, and user controls. User controls are object oriented and use a more programmatic approach to code encapsulation than SSIs.

  • As mentioned previously, Web forms can also contain as much HTML and client-side script, such as JavaScript, as desired.

Comments

  1. 23 Aug 2005 at 16:15

    Peter: You are using an alert box.  I'm pretty sure that only the exclamation icon is your only option.


    svkoli: I get the following error when I try to use your box:


    CS0122: 'testresults.Button1_Click(object, System.EventArgs)' is inaccessible due to its protection level


    Any idea what I need to do?

  2. 28 Jul 2005 at 08:01

    Use window.confirm()

  3. 28 Jul 2005 at 06:32

    Quote:
    [1]Posted by surendar on 10 Jan 2005 11:47 PM[/1]
    what the code to create a messagebox in asp using c# language ?


    http://www.developerfusion.co.uk/show/4700/
    see this.

  4. 28 Jul 2005 at 05:59

    anyone can please tell me  how to create a message box with ok & cancel buttons on a web page using asp.net using code behind ? Actually i am new to .NET. i reqire it urgently.

  5. 24 Jun 2005 at 09:39
    string message = strConn;
    string alertScript = "<script language=JavaScript>";
    alertScript += "alert('" + message +"');";
    alertScript += "</script" +">";

    if (!IsClientScriptBlockRegistered("alert"))
    this.RegisterClientScriptBlock("alert", alertScript);
  6. 04 Apr 2005 at 13:46

    The methods declared in the User Controls can be called directly in a .aspx page by creating an object for the .ascx user contol page.


    Following are the steps:


    Let us consider the names of the usercontrol and web form are myControl.ascx and myPage.aspx and the usercontrol is in the folder named UserControls.



    1. include the .ascx file name in the myPage.aspx by 'using' clause if the usercontrol and the web form are in different folders
          using UserControls;

    2. create an object for the usercontrol
          myControl objControl = new myControl();

    3. call the method using the created object
           objControl.<methodname>

  7. 10 Jan 2005 at 23:47

    what the code to create a messagebox in asp using c# language ?

  8. 19 Nov 2004 at 11:59

    on page1.aspx
    - you have a form with a textbox with id="txtBox"
    - user fills it out and clicks submit
    - do your validation if need be and then System.Web.HttpContext.Current.Server.Transfer("page2.aspx", True)


    on page2.aspx
    - in the Page_Load put RegisterHiddenField("txtBox", Request("txtBox"))
    - you have another form with whatever fields
    - user fills it out and clicks submit
    - do your validation if need be and then System.Web.HttpContext.Current.Server.Transfer("page3.aspx", True)


    on page3.aspx
    - in Page_Load do a response.write(Request("txtBox")
    - the value of the textbox called "txtBox" from page1.aspx should display

  9. 04 Nov 2004 at 06:24

    Hi,


    The examples are fine, they are working. But how about passing the values among 3 or 4 pages ?.


    I mean, if there is any values entered in 1.aspx file, then I should be able to retrieve back in 3.aspx and send it back to 4.aspx file ?. How do I do that ?.


    Is there any better way of doing it ?. Please help.


    Thanks.


    Regards,
    Karthick

  10. 31 Oct 2004 at 04:07

    I used this code:


    <script language="VB" runat="server">
    Sub InfoBox(Mensagem as string)
     Dim NewScript as string
     NewScript = "<script language=JavaScript>"
     NewScript = NewScript & "alert('" & Mensagem  & "');"
     NewScript = NewScript & "</script" & ">"
     If ( Not IsClientScriptBlockRegistered("alert")) then
      RegisterClientScriptBlock("alert", NewScript)
     End If  
    End Sub
    </script>



    invoke =>  InfoBox ("Hello")




    Does anyone know how to change the icon that appears, i want an info icon and not an exclamation icon !



    Many thanks

  11. 11 Oct 2004 at 05:17
    For Passing value from one page to another use this code

    Response.redirect("url of page")


    Make read only property for each value u want send on other page.

    On load event of other

    dim strmain as main (object of that page)

    objmain = CType(context.Current.Handler, main)

    and use all property here.

    Bye & take care
  12. 22 Sep 2004 at 21:58

    I am new to ASP.NET, please help me how use Message Box on ASP.NET Web Form?  I know used in VB.net is (Messagebox("message here"), so what is the declaration and key word use in ASP.NET Web Form.


    Thanks.

  13. 31 Aug 2004 at 21:17
    Do it like below
     <a href="link.aspx?id='"& var &"'>link</a>
    ok?
  14. 02 Aug 2004 at 10:54

    this should do it......


    Dim Message as string = "Alert Box from Code Behind."
    Dim strScript As String = "<script language=JavaScript>"
    strScript += "alert(""" & Message & """);"
    strScript += "</script>"
    If (Not Page.IsStartupScriptRegistered("clientScript")) Then
        Page.RegisterStartupScript("clientScript", strScript)
    End If

  15. 30 Jul 2004 at 22:49

    does anyone know how to creat e a message box on a web page using asp.net using code behind?

  16. 05 Apr 2004 at 08:45

    Quote:
    [1]Posted by kimkakwe on 8 Aug 2003 10:13 AM[/1]
    Hi,


    Hope somebody will assist me. Have been doing ASP but i want to shift to ASP.NET.
    My problem is the software requirement and setting the environment to write ASP.NET websites.


    May somebody help?


    Cheers,
    Nicholas.



  17. 29 Mar 2004 at 06:29

    Quote:
    [1]Posted by bvsuresh_reddy on 28 Feb 2003 03:41 AM[/1]
    Hi,


     I am beginer to ASP.Net. Can u tell how to call new page from the existing page.
     In VB.net by executing the statement "Form2.show()", New page will be loaded. In the same way how to load new page in ASP.Net   ?


    Thank U
    Suresh

  18. 20 Mar 2004 at 20:16
    hi guys, iam just new to asp.net
    could somebody pls tell me how to pass the values of aspx form to another aspx page? it should happen when u click the "submit" button. i know how to do it in asp. but not in asp.net.
    thanks in advance
  19. 12 Mar 2004 at 03:11

    how to access a method declared in a web user control form(.ascx) into a web form(.aspx) in asp.net?

  20. 11 Mar 2004 at 03:30

    You can try this one:


    MessageBox for ASP.NET from  http://www.bassilsoft.com

  21. 11 Mar 2004 at 03:19

    you cann't call "Form2.show()" to let a new WebForm to show up..



    That's the Windows application 's methd, could not work on Webform in ASP.NET.


    You can use Transfer("NewPage2.aspx") or Redirect("xxx.aspx") at server side .vb code.

  22. 08 Mar 2004 at 14:43

    Check out web matrix at http://asp.net/webmatrix/default.aspx?tabIndex=4&tabId=46


    it has a built in web server and database for learning and writing asp.net pages.

  23. 08 Mar 2004 at 14:40

    -A Web Form refers to the .aspx page that inherits from the System.Web.UI.Page class.
    -There is also an HtmlForm class that allows you to create and control an Html <Form> tag on the server.  You can create this in your .aspx page using <form runat="server"> and must place your input related tags/controls (buttons, text boxes, etc.) inside it. This will be rendered to the client as the standard HTML <form> tag.  
    -Web Controls are a group of classes in the System.Web.UI.WebControls namespace, such as labels, repeaters and datagrids, as well as the form related controls such as text boxes and buttons.
    -Html Controls are a group of classes similar to the web controls but they are in the System.Web.UI.HtmlControls namespace and are very simple controls that represent Html tags such as the HTML form mentioned above, buttons, text boxes, etc.  HtmlControls generally are not as feature rich as Web Controls and there are less of them.

  24. 02 Jan 2004 at 04:04

    Hi Aton,
    As SVKoli has said, its always better to comibe the code with client side scripts.
    Java Script or J Script will help you to do this... since Javascript is allmost read by all browsers.


    care
    scienty

  25. 02 Jan 2004 at 04:04

    Hi Aton,
    As SVKoli has said, its always better to comibe the code with client side scripts.
    Java Script or J Script will help you to do this... since Javascript is allmost read by all browsers.


    care
    scienty

  26. 06 Sep 2003 at 11:08

    Hi atan


    there's no keyword for displaying a MessageBox in ASP.NET. You have to register a ClientScriptBlock and Invoke this. Here's an exampla page


    Code:
    <%@ Page Language="C#" %>
    <script runat="server">
       void Button1_Click(object sender, EventArgs e)
       {
           string message = "MessageBoxTest";
           string alertScript = "<script language=JavaScript>";
           alertScript += "alert('" +message +"');";
           alertScript += "</script" +">";


           if (!IsClientScriptBlockRegistered("alert"))
               this.RegisterClientScriptBlock("alert", alertScript);
       }


    </script>
    <html>
    <head>
    </head>
    <body>
       <form runat="server">
           <asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
       </form>
    </body>
    </html>



    There also exists a free MessageBox Server-Component. You'll find it here
    MessageBox

  27. 08 Aug 2003 at 16:18

    I am new to ASP.NET, please help me how use Message Box on ASP.NET Web Form?  I know used in VB is (Msgbox("message here"), so what is the key word use in ASP.NET Web Form.


    Thanks.

  28. 08 Aug 2003 at 10:13

    Hi,


    Hope somebody will assist me. Have been doing ASP but i want to shift to ASP.NET.
    My problem is the software requirement and setting the environment to write ASP.NET websites.


    May somebody help?


    Cheers,
    Nicholas.


  29. 03 Mar 2003 at 03:57


    Hi,


    Please tell me what is the difference between "Web Form" and "HTML Form", and "Web Controls" and "HTML Controls" in ASP.Net.


    Thanx
    Suresh

  30. 28 Feb 2003 at 05:53

    Response.Redirect("newpage.aspx")


    ?

  31. 28 Feb 2003 at 03:41

    Hi,


     I am beginer to ASP.Net. Can u tell how to call new page from the existing page.
     In VB.net by executing the statement "Form2.show()", New page will be loaded. In the same way how to load new page in ASP.Net   ?


    Thank U
    Suresh

  32. 10 Jan 2003 at 15:42
    Hey it was a problem with my web provider, they had to enable asp.net on my site.  Thanks anyways!
  33. 09 Jan 2003 at 00:00

    This is great info and it works superb with IIS, but how are you all getting the files to work on your site?  I uploaded all the files, enabled folder actions did everything I can think of, but still can't seem to get it to work.  The files are here so you can see what I'm doing wrong.  Thanks!

  34. 01 Jan 1999 at 00:00

    This thread is for discussions of ASP.NET Web Forms.

Leave a comment

Sign in or Join us (it's free).

Events coming up

  • Mar 15

    DevWeek 2010

    London, United Kingdom

    DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET 4.0, Silverlight 3, WCF 4, Visual Studio 2010, REST, Windows Workflow 4, Thread Synchronization, ASP.NET 4.0, SQL Server 2008 R2, LINQ, Unit Testing, CLR & C# 4.0, .NET Patterns, WPF 4, F#, Windows Azure, ADO.NET, Entity Framework, Debugging, T-SQL Tips & Tricks, and more.

Want to stay in touch with what's going on? Follow us on twitter!