|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
I have a weird, or probably a simple dumb user error on a simple web application.
The project is created with the wizard. (asp.net core web app with a new controller with EF).
The database has been created and is working.
I have a model (1 string, 2 double values):
public class Person
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public double Poids { get; set; }
public double Glycemie { get; set; }
}
In the generated Create Page.
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Name" class="control-label"></label>
<input asp-for="Name" class="form-control" />
<span asp-validation-for="Name" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Poids" class="control-label"></label>
<input asp-for="Poids" class="form-control" />
<span asp-validation-for="Poids" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Glycemie" class="control-label"></label>
<input asp-for="Glycemie" class="form-control" />
<span asp-validation-for="Glycemie" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
Addition :
in the Create method, the value for the Glycemie is zero, as if it was not entered in the form.
As if the binding did not work ???
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,Poids,Glycemie")] Person person)
{
if (ModelState.IsValid)
{
_context.Add(person);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(person);
}
When I type in the data, name "Max" , poids (weight) "123" and glycemia 4.5 value, I get an error on the glycemia value saying the value is not valid.
See image :
When i just type 4 (instead of 4.5) it works.
I'm not sure where or what validation is done.
Anything stupid or obvious I missed ?
THanks.
CI/CD = Continuous Impediment/Continuous Despair
modified 2 days ago.
|
|
|
|
|
I have 2 dropdowns, DroDownList1 and DropDownList2.
To insert records into the database, I select a value from DropDownList1 and based on specified condition, a value is automatically inserted into DropDownList2.
Then when I select a value, say 1, from DropDownList2, one row is automatically created in Repeater control.
If I select 2, two rows are automatically created.
Finally, if I select 3 again from DropDownList2, three rows are automatically created in Repeater control.
Three rows is the maximum number of rows that can be created because 3 values (1,2,3) are the maximum that can be populated into DropDownList2.
Then we insert the records into the database. This entire operation works great.
Then to retrieve the records we just inserted based on the description above, I use the following method:
Protected Sub btnSearch(ByVal sender As Object, ByVal e As EventArgs)
Dim address As String = Request.Form(txtSearch.UniqueID)
'get the results and fill in the form
Dim sqlStatement As String = "Select ad.returnonly, ad.Assets,ad.NoOfItemsToReplace,ap.MailAddress,o.PrimaryFirst, o.Phone, o.AltPhone,o.Email,o.PrimaryLast, o.ownerID, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip from Applications ap "
sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.Installation = 1 and ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'"
Dim sqlCmd As SqlCommand = New SqlCommand(sqlStatement, myConnection)
Dim reader As SqlDataReader = sqlCmd.ExecuteReader()
If reader.HasRows Then
While reader.Read()
DropDownList1.Text = reader("Assets").ToString()
DropDownList1_SelectedIndexChanged(Nothing, Nothing)
DropDownList2.Text = reader("NoOfItemsToReplace").ToString()
End While
Else
End If
reader.Close()
sqlCmd.Dispose()
End Sub
The above method populates DropdownList1 values and selects the inserted value by default. For instance, if 2 is selected from the list and inserted into the database, during select statements, 2 will be selected as the default value for DropDownList1.
Same is the case with DropDownList2 but more importantly, the below method automatically displays the row or rows based on the value selected for DropDownList2.
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
'Find the DropDownList in the Repeater Item.
Dim Amount As String = (TryCast(e.Item.FindControl("txt_Amount"), TextBox)).Text
Dim ModelNo As String = (TryCast(e.Item.FindControl("ModelNumber"), TextBox)).Text
End If
End Sub
For instance, if value of 1 is selected for DropDownList1, then one row of records with the two columns txt_Amount and ModelNumber is displayed, etc
The issue I am having is that assuming that value 1 is selected by default for DropDownList2, this displays one row of records as described above.
If the user decides to change the value selected for DropDownList2 from 1 to 2, we would like the first row to continue to display with its columns and values but would
like a new blank one added.
Similarly if value of 2 is selected by default for DropDownList2 which displays two rows in repeater, we would like the existing rows to persit when a user changes the
DropDownLit2 value from 2 to 3 while creating a new blank row.
I have been stumped on this now for almost a week and just don't know how to proceed.
Your assistance is greatly appreciated.
<asp:Repeater ID="DynamicRepeater" runat="server" onitemdatabound="DynamicRepeater_ItemDataBound">
<HeaderTemplate>
<table border="1">
<tr>
<td>Water Size</td>
<td>Amount</td>
<td>Model Number Date</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:DropDownList ID="ddlWater" AppendDataBoundItems="true" runat="server" AutoPostBack="true"">
<asp:ListItem Text="Select" selected="True" Value="" />
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="txt_Amount" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="ModelNumber" runat="server"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater><br />
|
|
|
|
|
Can someone please help?
I have attached two screenshots to help explain the issue I am having.
The first screenshot shows what happens when I value is selected from DropDownList2. It automatically displays the row with 5 columns with values.
https://www.kenig-dev.tech/wp-content/uploads/2023/03/1.png[^]
The second screenshot shows when the user changes the value of DropDownList2 from 1 to 2. Rather than retain the first row with values and add a second black row, the first row was reset and replaced with 2 blank rows.
https://www.kenig-dev.tech/wp-content/uploads/2023/03/2.png[^]
How can we retain the first row with its values while adding a second blank row that allows user to enter values into that second row?
|
|
|
|
|
Need to Integrate Swipe Machine in my C# Application for billing
|
|
|
|
|
Well, go ahead; you have our permission to do that.
Feel free to come back if you have an actual question to ask. But bear in mind that the only people who can support your "swipe machine" are the people who supplied it.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Credit card?
And you said C# but this is ASP.NET.
In C#
- You define, in general, how this processing will plugin to your application. You need to learn in general how credit cards work. That will include transactions and batching. You probably also need to look at debit cards.
- You must first have a processor (service that processes credit card transactions.) However in practice you probably need two for a real business since one is a backup. A processor is going to end up needing a bank account to which the company has access. That can limit choices (both bank and processor.)
- You get their specs which includes process for verifying your service.
- You implement to the specs.
- You integrate that code into your application.
- You must figure out a viable way to test the code. Basically you need some credit cards (plural) which can be used as actual cards. Usually with a $0.01 transaction. Obviously whoever has these must be trusted but also there are hard and very low limits on the cards.
- You certify with the processor.
Besides the above it is very important that you understand how error handling works. Both errors that the processor specs might document and those that they do not.
There are services out there besides processors which act as a gateway (and usually called that) which, by their claims, make much of the above easier. Sometimes that is true and sometime perhaps not. But with those you are limited to which processors that they support.
|
|
|
|
|
Silly me - I meant WebForms, of course, not WinForms...
My (admittedly limited) understanding of this class, is that it allows you to override the default HTML rendering code for an ASP.NET web control. It shouldn't, AFAIU, affect any of the properties ro events otherwise asociated with the control - only the HTML markup .NET uses to render it on teh page.
OK - so I've tried this for a the radio button adn checkbox controls. It all seems to work, and the controls render with the markup I want. If I set the AutoPostBack property, the HTML includes the usual
onclick="javascript:setTimeout('__doPostBack('[ctrl ID here]','')', 0)" that we all know and love in such controls... and indeed, the controls will post the page back when clicked/changed, and the "correct" changed state of is shown on the posted back page.
BUT... the control's CheckedChanged server-side event is not being fired. Am I operating unders ome basic misunderstanding of this class?
|
|
|
|
|
I have the following code that is sist make the firs leter of a token uppercase, do not know if this is the correct way to do it.
I only run thos on my local machine
The value of slug is the token name on coinmarketcup
At the moment when I open the page it show me the name of the token that I have click on, but they are all lowercase, so I want it to show the first letter in uppercase.
If i using the code that i have giving it shows CoinDetails (it is my page name)
thiss is the code that is not working
<pre>
<?php
$slug = basename(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));
$slug = preg_replace('/\\.[^.\\s]{3,4}$/', '', $slug);
$slug = ucfirst(strtolower($slug));
?>
Try to use this with this code
<pre><div class="card-header" >
<h5 class="card-title mb-0" ><?php echo $slug; ?></h5>
</div>
|
|
|
|
|
Fix the problem self with this code
<pre><?php echo ucfirst($slug);?>
|
|
|
|
|
how to auto print label in vb to be in the database
|
|
|
|
|
By writing some code.
If you want a better answer, then ask a better question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I know that in OData, we need to provide an API that gets OData queries as url string. Considering I'm working on Blazor Server App, can I use OData without providing an another API app on the server?
modified 18-Feb-23 3:40am.
|
|
|
|
|
I'm using the following controller to get data from database using EF Core:
public class EquipmentsController : ODataController
{
private readonly SqlServerContext _sqlServerContext;
public EquipmentsController(SqlServerContext sqlServerContext)
{
_sqlServerContext = sqlServerContext;
}
[HttpGet]
[EnableQuery]
public ActionResult<IQueryable<Equipment>> Get()
{
IQueryable<Equipment> eqList = _sqlServerContext.Equipments.AsQueryable()
.Include(x => x.CostCenter)
.Include(x => x.EquipmentCategory)
.Include(x => x.equipmentType);
return Ok(eqList);
}
}
My problem is that I cannot get nested result in the final json while I have included CostCenter, EquipmentCategory, and equipmentType entities. I'm using ASP.NET Core 6 API and OData 8.0.12
My ED model is as follows:
static IEdmModel GetEdmModel()
{
ODataConventionModelBuilder builder = new();
builder.EntitySet<Equipment>("Equipments");
return builder.GetEdmModel();
}
How can I fix that?
|
|
|
|
|
Have you included the relevant $expand options in your query?
OData Expand - OData | Microsoft Learn[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Greetings again experts.
Could you please help me out on this one.
I have a very long markup page that is used for various activities.
There is a section that allows users to enter a value into a search box and click the search button.
If there is a hit, a page is populated with the values from the search hit.
This works.
If however, the search turns up nothing, then we would like to popup a section of the page with several form controls which allows user to enter the values that did not turn up during search and submit to the database.
I tried using hide/show panel control but nothing is showing up.
I tried hide and show div but no luck.
I would truly appreciate any assistance with this. I am pasting only the section of the code that needs to be displayed in a popup, perhaps in the middle of the page.
Many thanks in advance.
<ajax:ModalPopupExtender ID="installAddress_MPE" runat="server" TargetControlID="label2" PopupControlID="div5" BackgroundCssClass="modalBackground" />
<div id="div5" runat="server">
<asp:Table ID="Table1" Style="background-color:White; font-size:12pt; color:Black;" runat="server">
<asp:TableRow>
<asp:TableCell ID="TableCell3" Style="background-color:Blue; font-size:14pt; color:White;" runat="server" ColumnSpan="6">
<asp:Label ID="installAddressHeader" runat="server" Text="New Installation Address Entry" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
<div id="divRebatable" class="popupdiv">
<asp:TextBox ID="txt_toiletsizes" placeholder="Enter new Toiltet GPF" Width="150px" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_newAmount" placeholder="Enter amount" Width="100px" runat="server"></asp:TextBox>
<asp:Button ID="btn_add" runat="server" Text="Add It" onclick="btn_add_Click"
Width="100px" />
<asp:Table ID="rebatableTable" Width="100%" runat="server">
<asp:TableRow CssClass="divHeader"><asp:TableHeaderCell ColumnSpan="4">Add Rebatable Toilets</asp:TableHeaderCell></asp:TableRow>
<asp:TableRow ID="allToilets" runat="server">
<asp:TableHeaderCell>How many toilets?</asp:TableHeaderCell>
<asp:TableCell>
<asp:DropDownList ID="ddlNumber" runat="server" OnSelectedIndexChanged="ddlNumber_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="--Select--" Value=""></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
<asp:ListItem Text="3" Value="3"></asp:ListItem>
</asp:DropDownList>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
<div>
<asp:Repeater ID="DynamicRepeater" runat="server" onitemdatabound="DynamicRepeater_ItemDataBound">
<HeaderTemplate>
<table border="1">
<tr>
<td>Toilet Size</td>
<td>Model #</td>
<td>Date Upgraded</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:DropDownList ID="ddlToiletGPF" AutoPostBack="true" runat="server">
</asp:DropDownList>
</td>
<td>
<asp:TextBox ID="ModelNumber" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="DateUpgraded" runat="server"></asp:TextBox>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater><br />
<asp:Label ID="lblSuccess" style="font-weight:bold;" runat="server" Text=""></asp:Label>
</div>
</div>
<asp:Label ID="lblMsg" runat="server" Text="" /><br />
Protected Sub Submit(sender As Object, e As EventArgs)
Dim address As String = Request.Form(txtSearch.UniqueID)
Dim speakerId As String = Request.Form(hfAutoId.UniqueID)
'get the results and fill in the datagrid
Dim sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,o.SecondaryFirst,o.SecondaryLast,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap "
sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'"
Dim sqlCmd2 As SqlCommand = New SqlCommand(sqlStatement, myConnection)
Dim reader As SqlDataReader = sqlCmd2.ExecuteReader()
If reader.HasRows Then
While reader.Read()
div1.Visible = False
installationAddress.Text = reader("InstallAddress").ToString() & " " & reader("InstallCity").ToString() & ", " & reader("InstallState").ToString() & " " & reader("InstallZip").ToString()
waterAccountNumber.Text = reader("WaterAcctNo").ToString()
ownerInformation.Text = reader("PrimaryFirst").ToString() & " " & reader("PrimaryLast").ToString()
dateReceived.Text = reader("dateReceived").ToString()
applicantName.Text = reader("applicant").ToString()
End While
Else
div1.Visible = True
End If
reader.Close()
sqlCmd2.Dispose()
myConnection.Close()
End Sub
modified 17-Jan-23 12:21pm.
|
|
|
|
|
samflex wrote:
Dim sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived,o.SecondaryFirst,o.SecondaryLast,ad.InstallAddress,ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap "
sqlStatement += "inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like '%" & address.Replace("'", "''").Trim() & "%'" Your code is almost certainly vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.
Const sqlStatement As String = "Select o.PrimaryFirst, o.PrimaryLast, ap.applicant, FORMAT(ap.DateReceived, 'd','us') as DateReceived, o.SecondaryFirst, o.SecondaryLast, ad.InstallAddress, ad.InstallCity, ad.InstallState, ad.InstallZip, ad.WaterAcctNo from Applications ap inner Join Addresses ad on ap.WaterAccountNo = ad.WaterAcctNo inner join Owner o on ap.OwnerCode = o.OwnerID Where ad.InstallAddress Like @query"
Using sqlCmd2 As New SqlCommand(sqlStatement, myConnection)
sqlCmd2.Parameters.AddWithValue("@query", address.Trim())
Using reader As SqlDataReader = sqlCmd2.ExecuteReader()
If reader.HasRows Then
div1.Visible = False
While reader.Read()
installationAddress.Text = String.Format("{0} {1}, {2} {3}", reader("InstallAddress"), reader("InstallCity"), reader("InstallState"), reader("InstallZip"))
waterAccountNumber.Text = reader("WaterAcctNo").ToString()
ownerInformation.Text = String.Format("{0} {1}", reader("PrimaryFirst"), reader("PrimaryLast"))
dateReceived.Text = reader("dateReceived").ToString()
applicantName.Text = reader("applicant").ToString()
End While
Else
div1.Visible = True
End If
End Using
End Using
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Hi, I need little help with starting the web API because I am not familiar with web development. My goal is to set up REST API for just one endpoint and some webhook or something to receive callback POST notification. I need to send every day request to subscribe for next day and receive notifications from it.
I created new project c# ASP.NET Core Web App (NET 7) and installed Swashbuckle.AspNetCore package, build it and run. It loads the page locally with no problems but when I publish it and upload to my (paid) hosting server it show me 404 error. In my output I have webroot folder and app.dll app.exe and couple .js files but no index.js or index.php to show startup page, I think it must be something to start. How can I execute or start my app on web page? I created index.php or .html whith "hello world" and after upload it in root folder shows page instantly. Can anyone help me or guide me how to solve this?
|
|
|
|
|
I got information now that my hosting server is not for asp.net, it's for linux not windows. Dummy question: is there any way to bridge it?
|
|
|
|
|
|
Hello,
i use ajax, HtmlEditorExtender to let users writing their own description
i store in database, and in my database i can see properly data store in table like this :
'🔸🖤 DANCE SQUARE 🖤🔸\n📝 LA TRILOGIE :\n3 dates à ne surtout pas manquer\n.\n🟧◾️ 29 Octobre - LA'
but when i read data by sql, in string variable, i lose all the specials characters like hearts in my example, all specials characters are replace by ?
what should i do to keep specials characters ? (correctly store in database.)
i read like this :
if (!res.IsDBNull(i))
ss {
return res.GetString(i);
}
else
{
return string.Empty;
}
|
|
|
|
|
Even money's on this (NOUS VOYON (sp?)):
CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
A blind man could probably use GOOGLE to find this but ... I haven't got a blind man's machine so this is a conjecture on my part.
(Un aveugle pourrait probablement utiliser GOOGLE pour trouver cela mais ... je n'ai pas de machine pour aveugle, donc c'est une conjecture de ma part.)
|
|
|
|
|
Yes, but an intelligent man could understand that I have already found and applied this, but it is not enough
|
|
|
|
|