Blazor | ComponentOne
Controls / Input Controls / TextBox / Quick Start
In This Topic
    Quick Start
    In This Topic

    The following quick start guide is intended to get you up and running with the TextBox control. In this quick start, you'll start with creating a new application, add two TextBox controls and a Window control to it, bind the TextBox controls with the Window control and set the text for OK and Cancel buttons of the popup dialog.

    TextBox Input Control in Blazor

    Create a Blazor App

    1. In Visual Studio, select Create a new project from the Get started pane.
    2. In the Create a new project dialog, select Blazor Server App, and click Next. Alternatively, you can also create a Blazor WebAssembly App.
      Note: Blazor Client-side app or WebAssembly app can be created using the Blazor WebAssembly App template. For details, check the Blazor WebAssembly topic in Blazor templates.
    3. In the Configure your new project dialog, provide name of the project you want to create in the Project name field and location for the project in the Location field. Click Next.
    4. In the Additional information dialog, select the target framework from the Framework dropdown, if required and click Create. By default, the selected framework is .NET 6.0. A new server-side Blazor app is created.

    Back to Top

    Configure References

    1. From the Project menu, select  Manage NuGet Packages.
    2. In the NuGet Package Manager window, select nuget.org as the Package source.
    3. Search for C1.Blazor.Input package and click Install.  
    4. Navigate to the Pages folder, open _Layout.cshtml file and register the client resources by adding the following lines of code.
    5. Add the following code to the <head> tag.
      HTML
      Copy Code
      <link rel="stylesheet" href="~/_content/C1.Blazor.Core/styles.css" />
      <link rel="stylesheet" href="~/_content/C1.Blazor.Input/styles.css" />
      

    6. Add the following code to the <body> tag.
      HTML
      Copy Code
      <script src="~/_content/C1.Blazor.Core/scripts.js"></script>
      <script src="~/_content/C1.Blazor.Input/scripts.js"></script>
      

    7. Right-click on Pages folder, click Add | Razor Component to add a new Razor page and then provide a name, say TextBoxQuickStart.
    8. Add the required directives to initialize and use the Tooltip control in the new Razor page.
      Razor
      Copy Code
      @using C1.Blazor.Input
      

    Back to Top

    Configure the TextBox and Window controls

    Display the text you enter in the text boxes as the text for OK and Cancel buttons of the popup dialog using the following code. In this example, we added two TextBox, a Button and a Window control. Here, we have already provided text in both the text boxes using Text property of the C1TextBox class. The string value provided to the Text property of the first text box is bound to the corresponding OkText property and the value provided to the Text property of the second text box is bound to the corresponding CancelText property of the C1Window class that represents the popup window. This allows the text in the text boxes to be displayed as the text for OK and Cancel buttons of the popup dialog on a button click.

    Index.razor
    Copy Code
    <!--Text boxes to set text for Window dialog buttons-->
    <C1TextBox @bind-Text="Oktxt"></C1TextBox>
    <br/>
    <br />
    <C1TextBox @bind-Text="Canceltxt"></C1TextBox>
    <br />
    <br />
    <button @onclick="@OpenPopup">Show Dialog</button>
    
    <C1Window @ref="myPopup" Style="@("width: 500px; top: 15")" IsModeless="true"
              IsDialog="true" OkText="@Oktxt" CancelText="@Canceltxt" DialogType="DialogType.Confirm">
        <PopupHeader>
            Window PopUp Header
        </PopupHeader>
        <PopupContent>
            Hello. This is the Window control.
        </PopupContent>
    </C1Window>
    
    @code{
        C1Window myPopup;
        string Oktxt = "Okay", Canceltxt = "Close";
    
        void OpenPopup()
        {
            myPopup.Open();
        }
    
        void ClosePopup()
        {
            myPopup.Close();
        }
    }
    

    Back to Top

    Build and Run the Project

    1. Click Build | Build Solution to build the project.
    2. Press F5 to run the project.

    Back to Top