Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
0
Get IgbButton Value?
posted

How do you assign the IgbInput to the value in the source?  I've tried the @ref and the @bind-CourceNameRef, but I can't get it to work?  The value is always empty?

<IgbInput @ref="CourseNameRef" Class="" DisplayType="@InputType.Text" Size="SizableComponentSize.Medium" Label="Required" Value="" Required="true" />

@code {

public IgbInput CourseNameRef { set; get; }

void OnCourseSaveClick(EventArgs e)
{
    string Test = CourseNameRef.Value;
}

Thanks

Sean

Parents
No Data
Reply
  • 29085
    Verified Answer
    Offline posted

    Hello Sean, 

    Thank you for contacting Infragistics. I see the Value is an empty string in your markup. The IgbInput will not update the Value property when the text changes by the user. To keep track of what the user enters, you need a binding. Try @bind-value rather than the Value. 

    eg. The example below shows a button and h1 tag that outputs the value entered during LostFocus. I've bolded the key areas of importance. Let me know if you have any questions.

    @using IgniteUI.Blazor.Controls
    @inject IIgniteUIBlazor IgniteUIBlazor

    <div class="container sample center">
    <h1>Greetings, @userName</h1>
    <IgbInput @ref="InputRef" @bind-value="userName" DisplayType="@InputType.Email" Label="Input Name" Placeholder="eg. John Doe">
    <span slot="prefix">User</span>
    </IgbInput>
    <IgbButton @onclick="onClick"></IgbButton>
    </div>

    @code {

    string userName = "Bradley";
    public IgbInput InputRef {get; set;}
    protected override void OnInitialized()
    {
    IgbInputModule.Register(IgniteUIBlazor);
    IgbButtonModule.Register(IgniteUIBlazor);
    }

    public void onClick()
    {
    Console.WriteLine(userName);
    }
    }

Children
No Data