|
Because I don't think its connected to my code, its something about dynamic controls or viewstate that I don't understand, and therefore can't answer myself..(I think)
but anyway... here is the code of the page
<pre> <%----%>
<div id ="registrationP3" runat="server" visible="false">
<div id="CheckboxProf" class="radios" runat="server" visible="false" Enableviewstate="false">
</div>
</div>
<%----%>
<div id ="registrationP4" runat="server" visible="false">
<div id="CheckboxProg" class="radios" runat="server" visible="false" EnableViewState="false">
</div>
<asp:Button ID="register" runat="server" Text="Register" OnClick="register_Click" />
</div>
<asp:Button ID="next" runat="server" Text="next" OnClick="next_Click" />
here is the code that creates the checkboxes:
<pre>public static void BindProfessions(HtmlControl ctrl, Page thispage)
{
List<Profession> Plist = Profession.GetProfessionList();
foreach (Profession p in Plist)
{
HtmlInputCheckBox rd_button = new HtmlInputCheckBox();
const string GROUP_NAME = "Professions";
rd_button.Name = GROUP_NAME;
string LinkID = "P" + p.ProfessionID.ToString();
rd_button.Attributes["id"] = LinkID;
rd_button.Value = p.ProfessionID.ToString();
RegisterUserControl userprofession = (RegisterUserControl)thispage.LoadControl("~/RegisterUserControl.ascx");
userprofession.imgP = p.ProfPath;
userprofession.fieldName = p.ProfName;
userprofession.IDnum = p.ProfessionID;
userprofession.RadioName = LinkID;
userprofession.EnableViewState = false;
rd_button.EnableViewState = false;
ctrl.Controls.Add(rd_button);
ctrl.Controls.Add(userprofession);
}
}
public static void BindKnowledge(HtmlControl ctrl, Page thispage)
{
List<Knowledge> Plist = Knowledge.RetKnowledgeList();
foreach (Knowledge p in Plist)
{
HtmlInputCheckBox checkBox = new HtmlInputCheckBox();
const string GROUP_NAME = "knowledge";
checkBox.Name = GROUP_NAME;
string LinkID = "Know" + p.ProgramID.ToString();
checkBox.Attributes["id"] = LinkID;
checkBox.Value = p.ProgramID.ToString();
RegisterUserControl userprofession = (RegisterUserControl)thispage.LoadControl("~/RegisterUserControl.ascx");
userprofession.imgP = p.ProgPath;
userprofession.fieldName = p.PName;
userprofession.IDnum = p.ProgramID;
userprofession.RadioName = LinkID;
userprofession.EnableViewState = false;
checkBox.EnableViewState = false;
ctrl.Controls.Add(checkBox);
ctrl.Controls.Add(userprofession);
}
}
here is the code that checkes the checkboxes after the user clicks submit
<pre> public static List<int> GetCheckBox(HtmlControl ctrl)
{
List<int> id_list = new List<int>();
foreach (Control rdButton in ctrl.Controls)
{
if (rdButton is HtmlInputCheckBox)
{
HtmlInputCheckBox bu = (HtmlInputCheckBox)rdButton;
if (bu.Checked)
{
id_list.Add(int.Parse(bu.Value));
}
}
}
return id_list;
}
here is the Page_Load in which I create the checkboxes once again with BindProfession, pay attention to the third if
protected void Page_Load(object sender, EventArgs e)
{
IsPageRefresh = false;
if (!IsPostBack)
{
ViewState["DivID"] = 1;
ViewState["postids"] = System.Guid.NewGuid().ToString();
Session["postid"] = ViewState["postids"].ToString();
}
else
{
if (ViewState["postids"].ToString() != Session["postid"].ToString())
{
IsPageRefresh = true;
}
Session["postid"] = System.Guid.NewGuid().ToString();
ViewState["postids"] = Session["postid"].ToString();
}
if (int.Parse(ViewState["DivID"].ToString()) == 3)
{
BindProfessions(CheckboxProf, Page);
}
else if(int.Parse(ViewState["DivID"].ToString()) == 4)
{
BindKnowledge(CheckboxProg, Page);
}
}
|
|
|
|
|
Hi, I am trying to get some temperature measurement data that I have stored in a SQL data base over on a webpage through asp.net.
Instead of getting timestamp with temperature measurement numbers I am getting some code text.
Here is my C# code in asp.net
This is Measurement.cs file
Am working in Microsoft Visual studio:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Data.SqlClient;
using Microsoft.JSInterop.Infrastructure;
using Microsoft.AspNetCore.Hosting.Server;
using System.Threading.Tasks;
namespace AirHeaterControlSystem.Models
{
public class Measurement
{
public string Timestamp { get; set;}
public string MeasurementValue { get; set; }
public string ControlValue { get; set; }
public List<Measurement> GetMeasurementParameters()
{
List<Measurement> measurmentParameterList = new List<Measurement>();
string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\CITADEL;UID=LAPTOP-1T8PALVT\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
SqlConnection con = new SqlConnection(connectionString);
string sqlQuery = "Select Timestamp,MeasurementValue,ControlValue from MEASUREMENTDATA";
con.Open();
SqlCommand cmd = new SqlCommand(sqlQuery, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr != null)
{
while (dr.Read())
{
Measurement measurementParameter = new Measurement();
measurementParameter.Timestamp = dr["TimeStamp"].ToString();
measurementParameter.MeasurementValue = dr["MeasurementValue"].ToString();
measurementParameter.ControlValue = dr["ControlValue"].ToString();
measurmentParameterList.Add(measurementParameter);
}
}
return measurmentParameterList;
}
}
}
Here is my cshtml file,
@page
@model AirHeaterControlSystem.Pages.MeasurementModel
@{
ViewData["Title"] = "Measurement Parameters";
}
<div>
<h1> Airheater temperature measurement</h1>
<table class="table">
<thead>
<tr>
<th>Timestamp</th>
<th>MeasurementValue</th>
<th>ControlValue</th>
</tr>
</thead>
<tbody>
@foreach (var measurement in Model.measurmentParameterList)
{
<tr>
<td> "measurement.Timestamp</td>
<td> "measurement.MeasurementValue</td>
<td> "measurement.ControlValue</td>
</tr>
}
</tbody>
</table>
</div>
|
|
|
|
|
Well, your view is wrong to start with. You've put:
<td> "measurement.Timestamp</td> when it should be:
<td> @measurement.Timestamp</td>
You should also be wrapping the disposable objects in a using block:
public List<Measurement> GetMeasurementParameters()
{
const string connectionString = "DATA SOURCE=LAPTOP-1T8PALVT\\CITADEL;UID=LAPTOP-1T8PALVT\\AdisP;DATABASE=MEASUREMENTDATA;Integrated Security = True;" ;
const string sqlQuery = "Select Timestamp, MeasurementValue, ControlValue from MEASUREMENTDATA";
List<Measurement> measurmentParameterList = new List<Measurement>();
using (SqlConnection con = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(sqlQuery, con))
{
con.Open();
using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
Measurement measurementParameter = new Measurement();
measurementParameter.Timestamp = dr["TimeStamp"].ToString();
measurementParameter.MeasurementValue = dr["MeasurementValue"].ToString();
measurementParameter.ControlValue = dr["ControlValue"].ToString();
measurmentParameterList.Add(measurementParameter);
}
}
}
return measurmentParameterList;
}
Beyond that, we can't help you. You haven't told us what you mean by "some code text", and you haven't shown us any of the data from your database.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm sorry to bother you, I just have a question regarding how to validate a list of object when is inside other list... I do have a list of cities, each city has another list of zones, an example could be like this:
public class City
{
public int Id { get; set; }
public string CityName { get; set; }
public virtual List<Zone> Zones { get; set; } = new List<Zone>();
}
public class Zone
{
public int Id { get; set; }
public string ZoneName { get; set; }
public int CityId { get; set; }
public virtual City City { get; set; }
}
Now, as you can see, the City is the principal and the Zone is the dependent class. Now I decided to pass what I have into my database to a view with a form to make changes to these Cities and their Zones, so I created a view model like this:
public class SettingsModel
{
public City NewCity { get; set; }
public List<City> CurrentCities { get; set; }
}
The first property is to create a new City that is not in the db. The other list contains the Cities already in the database. So I started by creating a list of forms using a for loop (not foreach) that uses an index. At the end, it produces something like this:
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_0__Id" name="CurrentCities[0].Id" value="7">
<input type="text" id="CurrentCities_0__CityName" name="CurrentCities[0].CityName" value="Austin">
...
</form>
...
<form method="post" action="/Administration/UpdateCity">
...
<input type="hidden" id="CurrentCities_1__Id" name="CurrentCities[1].Id" value="4">
<input type="text" id="CurrentCities_1__CityName" name="CurrentCities[1].CityName" value="Dallas">
...
</form>
as far as I understand, in the receiving action method (POST), I should use the [Bind(Prefix="CurrentCities")] to remove the unnecessary class name of the field name and, should specify a list<city> (or IEnumerable or Array) to tell that the object received is an array. in other words:
public IActionResult UpdateCity([Bind(Prefix = "CurrentCities")]List<City> myCity)
{
...
}
My question is: When I try to add a form in the same way for the Zones property of City, I end with the form fields named as:
<input type="text" id="CurrentCities_0__Zones_0__ZoneName" name="CurrentCities[0].Zones[0].ZoneName" value="Austin Metro Area">
...
<input type="text" id="CurrentCities_1__Zones_0__ZoneName" name="CurrentCities[1].Zones[0].ZoneName" value="San Antonio Metro Area">
As you can see, now all the fields have an extra index indicator like this "CurrentCities[0].Zones[0]" and I was wondering, how can I get this object in the POST action method? how can I specify a Bind Prefix of this kind? and how could I specify that the item is a collection item of other collection item?? Please help and thank you for your patience!
|
|
|
|
|
You don't need to mess around with the binding prefix; just have your update method accept an instance of your view-model, and let the model binder do the rest.
public IActionResult UpdateCity(SettingsModel model)
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Has anyone come across this problem where firefox won't allow file uploads. On IE works fine.
Is there a workaround?
Thank you in advance.
|
|
|
|
|
No. There's almost certainly a problem with your code, which you haven't shown.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
My upload function code.
I did find a solution below you'll notice I force all upload files to be placed in the end user's C:\Temp folder. I also convert pdf files to an image before the encryption.
if (!String.IsNullOrEmpty(btnBrowse.FileName.ToString()))
{
if (fileExt == ".pdf")
{
pdfToJpg = @"c:\temp\" + btnBrowse.FileName.ToString().ToLower();
jpgOut = System.IO.Path.GetFileNameWithoutExtension(btnBrowse.FileName.ToString().ToLower());
jpgOut = @"c:\temp\" + jpgOut + ".jpg";
success = Utilities.Pdf2Jpg(pdfToJpg, jpgOut);
if (!success)
{
hdnFieldAlert.Value = "error; ERROR! File Not Converted.;Document Upload";
return;
}
imagePath = jpgOut;
savePath = appPath + saveDir + System.IO.Path.GetFileNameWithoutExtension(btnBrowse.FileName.ToString().ToLower()) + ".jpg";
}
sqlCmd = new SqlCommand("select legaldocurl from [dbo].[refugee] where [aregnum] = @clientNum", sqlCon);
sqlCmd.Parameters.Add("@clientNum", SqlDbType.VarChar).Value = oARegNum;
sqlCon.Open();
SqlDataReader dr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.Read() && !String.IsNullOrEmpty(dr["legaldocurl"].ToString()))
{
prevUpload = dr["legaldocurl"].ToString();
prevUploadFile = appPath + saveDir + prevUpload;
if (File.Exists(prevUploadFile)) File.Delete(prevUploadFile);
if (File.Exists(savePath)) File.Delete(savePath);
}
string jpgFile = System.IO.Path.GetFileNameWithoutExtension(imagePath) + ".jpg";
fileToEncrypt = imagePath;
img = System.Drawing.Image.FromFile(fileToEncrypt);
Utilities.Encrypt(img, savePath);
img.Dispose();
sqlCon.Close();
sqlCmd = new SqlCommand("update [dbo].[refugee] set legaldocurl = @imgPath where [aregnum] = @clientNum", sqlCon);
sqlCmd.Parameters.Add("@imgPath", SqlDbType.VarChar).Value = jpgFile;
sqlCmd.Parameters.Add("@clientNum", SqlDbType.VarChar).Value = oARegNum;
sqlCon.Open();
sqlCmd.ExecuteNonQuery();
sqlCon.Close();
refugeeSelectByRecordId();
|
|
|
|
|
You mentioned uploading the images, which suggests to me that this is a web application.
You cannot use the FileName property of the FileUpload control to access the file. It returns the path - or sometimes just the name - of the file on the client. That file will not be accessible on the server, where your code is running.
It might appear to work when you debug your code in Visual Studio. But that's only because, in that specific cast, the server and client are the same computer. Once you deploy to a real server, your code will stop working.
Either use the SaveAs method to save the uploaded file to the server, or use the InputStream property to read the content of the uploaded file.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
due to security reasons I researched firefox does not return file location
so to circumvent this - upload files must be placed in the c:\temp folder.
Is there a better workaround?
|
|
|
|
|
You are doing it wrong. Read my previous message. You CANNOT access the client's file system from code running on the server!
Use the SaveAs method to save the uploaded file somewhere on your server. Or use the InputStream property to read the data from the uploaded file.
Trying to use the FileName property to read the file WILL NOT WORK!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
H Richard, I added the function code to my help request.
|
|
|
|
|
I meant to add this.
The problem with FireFox is not, not allowing uploads but rather it does not show the path of the uploaded file just the name. to circumvent this - upload files must be placed in the c:\temp folder
|
|
|
|
|
Hi,
I need help for show datatable in Json
My project is MVC:
My AgendaModel
<pre> public List<AgendaModel> MostrarTodosCalendar()
{
List<AgendaModel> lista = new List<AgendaModel>();
AgendaModel item;
DAL objDAL = new DAL();
string sql = "SELECT id, title, start, end, AllDay, Color, TextColor FROM agenda";
DataTable dt = objDAL.RetDataTable(sql);
for (int i = 0; i < dt.Rows.Count; i++)
{
item = new AgendaModel
{
Id = dt.Rows[i]["Id"].ToString(),
Title = dt.Rows[i]["Title"].ToString(),
Start = dt.Rows[i]["Start"].ToString(),
End = dt.Rows[i]["End"].ToString(),
Color = dt.Rows[i]["Color"].ToString(),
TextColor = dt.Rows[i]["TextColor"].ToString()
};
lista.Add(item);
}
return lista;
}
My View: Index:
function CriarEventosCalendario() {
var events = [];
@{
foreach(var item in (List<AgendaModel>)ViewBag.ListaEventos)
{<text>events.push({
'id': @item.Id,
'title': '@item.Title',
'start': '@item.Start',
'end': '@item.End',
'allDay': false,
'color': '@item.Color',
'textColor': '@item.TextColor'
});</text>
}
}
I want to convert to JSON because fullcalendar is not showing the data as it currently is.
|
|
|
|
|
Change the events declaration in the view to
function CriarEventosCalendario() {
var events = @Html.Raw(Json.Encode(ViewBag.ListaEventos));
|
|
|
|
|
I have error in
Encode
You can help me ?
|
|
|
|
|
|
Erro CS1061 ‘IJsonHelper’ does not contain a definition for "Encode"..
|
|
|
|
|
You're using ASP.NET Core. Instead of:
var events = @Html.Raw(Json.Encode(ViewBag.ListaEventos)); use:
var events = @Json.Serialize(ViewBag.ListaEventos);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
hello , guys I am working on hotel system can any body share source code with me please, its very important!
this's my email "showmore5@gmail.com"
thanks very much
|
|
|
|
|
No, nobody here is going to do your work for you.
And it's not "very important" to anyone other than you.
If you want to hire someone to write some code for you, there are sites where you can do that. This isn't one of them.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I worked on a booking system in the 90s, it took approx 18 months to build, not test just build. Mind you it is in SuperBase!
I can send you that code for a small recompense.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I did laugh out loud at that!
I think I can probably find mine from the 80's - developed for C/PM though so probably a bit more expensive than yours
|
|
|
|
|
HAHAHAHA
Member 14921707 wrote: its very important!
If it was, you'd be paying and not begging.There's free solutions available. What makes you think I take the time to build you a new one, without pay?
How much time (aka money) do you think one needs to put into building one?
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm sort of fuzzy on this here. So I have a HttpPost operation that ends with return Ok(result). I remember reading that I have to add a route to GetOrder in order for CreatedAtRoute to work. I sort of did something stupid and named that api GetAdminOrders so I can secure it with JWT, but added a Route decorator to it so CreatedAtRoute would work.
var result = CreatedAtRoute("GetOrder", new { order.Id }, order);
return Ok(result);
So this didn't work, it didn't return the order back to the client making the call. I just need the order number or Id of the order and not the whole order. Now I'm wondering if I should refactor all of these that I created. I'm really wondering if I got this all wrong here.
[HttpGet("GetAdminOrder/{orderId}"), Authorize(AuthenticationSchemes = AuthSchemes, Policy = AuthPolicies.Admin)]
[Route("{orderId}", Name = "GetOrder")]
public async Task<GetAdminOrder> GetAdminOrder(string orderId)
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|