C
C#8mo ago
Visual Code

❔ save checkbox value after refresh

Is there a way in Blazor where I save the checkbox after I refresh the page, for example I press a checkbox and I refresh the page and the checkbox sould stayed clicked
No description
9 Replies
Iron
Iron8mo ago
You could save to browser or local storage , session storage would only save it for the current browser session which is what you are probably looking for
Visual Code
Visual Code8mo ago
not really, in my database i have a column with "IsPlannable", "IsPlannable" checks if its true or false, so even it i close the programm an i checked a Checkbox it should show me the enabled checkbox, but i dont know how ti implement that
No description
Iron
Iron8mo ago
Ohh , well do you have wasm with server or ? Because the way i do that in blazor is i make a call to my api to read or write from database using usermanager, if the value is stored in the users table If thats the case you would prob just read the values of the database when rendering the page with the checkboxes and set them to the values of the dB Im talking about if you have users logged in using identity tho might be a better way
Visual Code
Visual Code8mo ago
so about the user log, we use SSO, and i have a class with query about the "IsPlannable" yes ig
Iron
Iron8mo ago
Then yeah would prob be able to read or write from a controller
Visual Code
Visual Code8mo ago
Yes, but I'm not sure how to do it because I also use Telerik and I can't find any documentation for it or maybe i just need a method and but it into the GridBox so i wrote i method, but im not sure where to implement it, i tried in "GridCheckboxColumn" but that doesnt work
private void OnCheckboxChecked(object isChecked, CoreEmployee employee)
{
employee.IsPlannable = (bool)isChecked;
}
private void OnCheckboxChecked(object isChecked, CoreEmployee employee)
{
employee.IsPlannable = (bool)isChecked;
}
Visual Code
Visual Code8mo ago
if you need the hole code
Iron
Iron8mo ago
Not sure, first i would prob let telrik know the isPlannable property is bindable by adding a Bindable tag to it( if one still does that )


[Bindable(true)]
public bool IsPlannable { get; set; }


[Bindable(true)]
public bool IsPlannable { get; set; }
` That tells Telerik grid component to treat this property as bindable. Then it can be bound to a checkbox Im not so used to Telerik tho i might be wrong as i said. Then maybe use this:
<GridCheckboxColumn Field=@nameof(CoreEmployee.IsPlannable) CheckBoxOnlySelection="true" Title="Planbar" />
<GridCheckboxColumn Field=@nameof(CoreEmployee.IsPlannable) CheckBoxOnlySelection="true" Title="Planbar" />
` This will create a checkbox in the grid that is bound to the IsPlannable of each employee. Then modify the SaveData method to update the plannableEmployees list instead of updating allEmployees But as i said, if you have a DB, you prob need to make a API call to that DB to read/write, in my case, i usually create the database write/read stuff in my controllers, then i can access data or change using calls to the API. If you are using entity framework core you can do something like this:
`public class EmployeeService : IEmployeeService
{
private readonly ApplicationDbContext _dbContext;

public EmployeeService(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task UpdateEmployee(CoreEmployee employee)
{
var dbEmployee = await _dbContext.CoreEmployees.FindAsync(employee.Id);
dbEmployee.IsPlannable = employee.IsPlannable;
await _dbContext.SaveChangesAsync();
}

public async Task UpdateEmployees(IEnumerable<CoreEmployee> employees)
{
foreach (var employee in employees)
{
var dbEmployee = await _dbContext.CoreEmployees.FindAsync(employee.Id);
dbEmployee.IsPlannable = employee.IsPlannable;
}

await _dbContext.SaveChangesAsync();
}
}
`public class EmployeeService : IEmployeeService
{
private readonly ApplicationDbContext _dbContext;

public EmployeeService(ApplicationDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task UpdateEmployee(CoreEmployee employee)
{
var dbEmployee = await _dbContext.CoreEmployees.FindAsync(employee.Id);
dbEmployee.IsPlannable = employee.IsPlannable;
await _dbContext.SaveChangesAsync();
}

public async Task UpdateEmployees(IEnumerable<CoreEmployee> employees)
{
foreach (var employee in employees)
{
var dbEmployee = await _dbContext.CoreEmployees.FindAsync(employee.Id);
dbEmployee.IsPlannable = employee.IsPlannable;
}

await _dbContext.SaveChangesAsync();
}
}
` Dont listen to everything i say tho because i am not 100%, prob others in this discord who know way more about this. Im just giving you examples
Accord
Accord8mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
❔ Using Microsoft Graph to verify users exist based on IEnumerable<Guid>I am trying to work with Microsoft Graph to verify that each guid in some list is associated with a ✅ How to register a onNavigate/navigation event callback in Net8 SSR?blazor.web.js replaced the entire html on navigate with the response, but scripts like `<script src=❔ Establishing a connection to SQL Server in Mac (Azure data studio & Docker desktop)Ive been stuck on this error: A network-related or instance-specific error occurred while establish✅ Reading matricies to an output fileI am trying to read the data inside two matricies from an input file firstly in order to add them to❔ How to Deploy WASM Project with .NET Backend in same repo?I have a Blazor frontend with a .NET backend. How do I use Azure to deploy these when they are in th❔ EF Core LINQ translation documentIn the process of upgrading a .NET Core 1.1 to 6 app, our EF Core LINQ queries are now hitting some Is there a better (or more appropriate way) of implementing method overloading for my usecase here?I have two methods of a class I'm writing - in one usecase I want to update the field with no return❔ Referencing new projects with the main projectLet's say I have a main project `CoreProject` and I want to add 2 new projects: a `LoggerService` an❔ Refactoring strategy pattern to a simpler codeI have the following code and I want te refactor it to a less-boiler-plate code. Wha'ts suposed to❔ Avoid "Authorizing..." in Blazor Page (Identity)I am trying to avoid the loading text "Authorizing..." when going to my index.razor page. I have add