|
Thank You. its really work..
|
|
|
|
|
Hello!
I have created a project intended to get a better understanding of how to create an admin panel for users and seed data. It seems to me that seeding is now working as intended, but the admin panel for users is a bit more complicated than I thought it would be.
Let's start by saying I have already looked at this
tutorial on the topic but I find it's geared to such a different workflow than mine that trying to adapt it without having a firm grasp on the topic would be a lot more work than having something basic working for my own. The main issues I have with that article is that it is entirely based on the idea that users cannot register from the outside(which I instead want) and it is a preparation for another article to manage user groups (that I do not need at the moment).
From Googling, I realised that I need a couple of ViewModels, so I created them:
public class UserViewModel
{
[Required]
[Display(Name = "Email")]
[EmailAddress]
public string Email { get; set; }
[Required]
[Display(Name = "Enabled")]
public Boolean Enabled {get; set; }
[Required]
[Display(Name ="Active")]
public Boolean Active { get; set; }
[Required]
[Display(Name = "Lockout date and time")]
public DateTime? LockoutEndDateUtc { get; set; }
[Required]
[Display(Name ="Lockout enabled")]
public Boolean LockoutEnabled { get; set; }
}
public class UserListViewModel
{
private ICollection<UserViewModel> _UserList = new List<UserViewModel>();
public UserListViewModel( ApplicationDbContext ctx)
{
UserViewModel User;
foreach (var user in ctx.Users)
{
User = new UserViewModel();
User.Email = user.Email;
User.Active = user.Active;
User.Enabled = user.Enabled;
User.LockoutEnabled = user.LockoutEnabled;
User.LockoutEndDateUtc = user.LockoutEndDateUtc;
}
}
Trying to create a controller, however, resulted in VS kicking and screaming that there is no key. Googling again, it appears that VS thinks I am creating new database entities(something that I am not trying to do, promise!!!).
My understanding is that at least part of the reason for this is that I have a dbcontext in the constructor.
I am fairly a newbie in ASP.NET MVC, so I would like you to please show me the error of my ways.
Thanks!
A
|
|
|
|
|
I am working on HandelBar js to load data into Aps.net controls. can we use Ajax controls in handlebar template?
i tried but it is not working for me
<table id="tblPeriodDateRanges" style="overflow: auto">
<thead class="dark_blue_header">
<tr>
<td style="width: 50px;">
<asp:Label runat="server" Text="Edit"></asp:Label></td>
<td style="width:200px;">
<asp:Label runat="server" Text="Standard Season Name"></asp:Label></td>
<td style="width: 200px;">
<asp:Label runat="server" Text="From"></asp:Label></td>
<td style="width: 200px;">
<asp:Label runat="server" Text="To"></asp:Label></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script id="PeriodDateRangeTemplate" type="text/x-handlebars-template"">
{{#each this}}
<tr>
<td>
<asp:HiddenField runat="server" ID="RowID" />
<asp:ImageButton runat="server" ID="btnDelete" ImageUrl="~/App_Themes/Default/images/remove_16x16.png" AlternateText="Remove" OnClientClick="return DeleteRow(this.parentElement.parentElement);" />
</td>
<td>
<asp:HiddenField runat="server" ID="hdnSeasonID" Value="{{this.SeasonTypeID}}" />
<asp:TextBox runat="server" ReadOnly="true" ID="txtSeasonName" value="{{this.SeasonTypeName}}" class="readOnlycss txt" />
<asp:DropDownList runat="server" ID="ddlSeasonName" CssClass="class_Season_ddlCP"></asp:DropDownList>
</td>
<td>
<asp:TextBox runat="server" ID="txtFromDate1" Text="{{this.DateRangeStartDate}}" CssClass="txt readOnlycss" />
<cc1:CalendarExtender ID="CalendarExtendertxtFromDate" runat="server" TargetControlID="txtFromDate1"></cc1:CalendarExtender>
</td>
<td>
<asp:TextBox runat="server" ID="txtToDate1" Text="{{this.DateRangeEndDate}}" CssClass="txt readOnlycss" />
<cc1:CalendarExtender ID="CalendarExtendertxtToDate" runat="server" TargetControlID="txtToDate1"></cc1:CalendarExtender>
</td>
</tr>
{{/each}}
</script>
|
|
|
|
|
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:\Users\Probing\Desktop");
FileInfo[] Files = dinfo.GetFiles("*.txt");
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
I have the source code but its not displaying anything in the listbox..
can anyone help me why is this so?
|
|
|
|
|
If I understand the question correctly, the problem is that you have placed the code that adds items into the listbox inside a SelectedIndexChanged event handler. So the code will only be run when an item from the list box is selected so if you have no items, the code is never run.
Try moving the code to a place which is executed when the listbox is shown. For example if this is Windows Forms, you can use load event:
public Form1() {
InitializeComponent();
this.Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e) {
DirectoryInfo dinfo = new DirectoryInfo(@"C:\Users\Probing\Desktop");
FileInfo[] Files = dinfo.GetFiles("*.txt");
foreach (FileInfo file in Files)
{
ListBox1.Items.Add(file.Name);
}
}
|
|
|
|
|
ya, its worked.
Thank you so much for the kind share.
|
|
|
|
|
I have one more question.
is the files can be download to local from listbox?
I have looked for it but I did not get any source code for it.
|
|
|
|
|
I'm sorry but I don't quite understand the question.
Also this seems to be a separate issue, so I suggest posting a new question with relevant details.
|
|
|
|
|
|
So I have a Webforms Web Project. I have these backend master pages that I'm converting to bootstrap.css, and I thought it would be nice to support 3 languages for the rest of the backend already is set to go.
I guess this error, now on a DLL or Windows App, I would use the root namespace and then the name of the file. ???? Maybe that's what I'm missing to register the file, a namespace.
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "login.master.en-us.resources" was correctly embedded or linked into assembly "App_Web_dubrzsw3" at compile time, or that all the satellite assemblies required are loadable and fully signed.
So I made this folder call App_GlobalResources and put 3 files in it.
login.master.en-us.resx
login.master.fr-ca.resx
login.master.ex-mx.resx
Then in the master code behind page, I put this in pre-render, does the same thing page load
Imports System.Resources
Imports System.Globalization
Imports System.IO
Imports System.Reflection
Partial Class Masterpages_Admin_Login
Inherits System.Web.UI.MasterPage
Protected rm As ResourceManager
Protected ci As CultureInfo
Protected Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
Dim m_context As HttpContext = HttpContext.Current
Dim m_localization As String = "english"
If Not (m_context.Request.QueryString("language") Is Nothing) Then
m_localization = m_context.Request.QueryString("language")
Select Case m_localization.ToLower
Case "english"
rm = New ResourceManager("login.master.en-us", Assembly.GetExecutingAssembly())
ci = New CultureInfo("en-US")
Case "french"
rm = New ResourceManager("login.master.fr-ca", Assembly.GetExecutingAssembly())
ci = New CultureInfo("fr-CA")
Case "spanish"
rm = New ResourceManager("login.master.es-mx", Assembly.GetExecutingAssembly())
ci = New CultureInfo("es-MX")
Case Else
rm = New ResourceManager("login.master.en-us", Assembly.GetExecutingAssembly())
ci = New CultureInfo("en-US")
End Select
Else
rm = New ResourceManager("login.master.en-us", Assembly.GetExecutingAssembly())
ci = New CultureInfo("en-US")
End If
End Sub
On the master page in Html, I put this in
<li class="pull-right"><a href="#top"><% rm.GetString("txtTop")%></a></li>
|
|
|
|
|
I figured it out, but the solution is long and complex
Basically, I'm going to create a new DLL that has nothing but resource strings
And call that DLL Assemby in Page Load of the Master Page.
Then use a Label Control, and populate that Label in Code Behind.
Partial Class Masterpages_Admin_Login
Inherits System.Web.UI.MasterPage
Public rm As ResourceManager
Public ci As CultureInfo
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim m_context As HttpContext = HttpContext.Current
Dim Assembly As System.Reflection.Assembly = System.Reflection.Assembly.Load("Admin_Standard")
If Not (m_context.Request.QueryString("language") Is Nothing) Then
Dim m_localization As String = m_context.Request.QueryString("language")
Select Case m_localization.ToLower
Case "english"
rm = New System.Resources.ResourceManager("Admin_Standard.labels_en", Assembly)
ci = New CultureInfo("en-US")
Case "french"
rm = New System.Resources.ResourceManager("Admin_Standard.labels_fr", Assembly)
ci = New CultureInfo("fr-CA")
Case "spanish"
rm = New System.Resources.ResourceManager("Admin_Standard.labels_es", Assembly)
ci = New CultureInfo("es-MX")
Case Else
rm = New System.Resources.ResourceManager("Admin_Standard.labels_en", Assembly)
ci = New CultureInfo("en-US")
End Select
Else
rm = New System.Resources.ResourceManager("Admin_Standard.labels_en", Assembly)
ci = New CultureInfo("en-US")
Dim m_string As String = rm.GetString("Back to top")
End If
lbl_BackToTop.Text = rm.GetString("txtTop")
End Sub
End Class
HTML
li class="pull-right"><a href="#top"><asp:Label ID="lbl_BackToTop" runat="server" Text="Back to top" /></a></li>
|
|
|
|
|
i have a one post then i wantto set for this post displaydate and display off date
from backend when i create post for ex title photos content displaystartdate and displayenddate input then save it
displaystartdate : 2015/10/2
displaystartdate : 2015/10/5
and front end when date 2015/10/2 my post automatically show up and when date is 2015/10/5 my post automatically off
there is my code who can check for me this something is wrong ~
thanks `
Protected Sub BindData(dt As Data.DataTable, SiteID As Long)
If dt.Rows.Count > 0 Then
litList.Text = ""
For i As Integer = 0 To dt.Rows.Count - 1
Dim Title As String = dt.Rows(i).Item("Title").ToString
Dim Targets As String = ""
Dim Targetsdes As String = ""
Dim ImgURL As String = ""
Dim ImgURLs As String = ""
Dim now As DateTime = DateTime.Now
Dim startTime As DateTime = dt.Rows(i).Item("DisplaySDate").ToString()
Dim endTime As DateTime = dt.Rows(i).Item("DisplayEDate").ToString()
If ((startTime <= DateTime.Now) And (endTime >= DateTime.Now)) Then
Me.Visible = True
Else
Me.Visible = False
End If
Dim URL As String = dt.Rows(i).Item("URL").ToString
If URL = "" Then
URL = "#"
Else
If dt.Rows(i).Item("Targets").ToString = True Then
Targets = " target=""_blank"" "
Targetsdes = Resources.RsAll.OpenNW
End If
End If
If dt.Rows(i).Item("Files").ToString <> "" Then
ImgURL = ViewState("Roots") & "WebTools/Thumbnail.ashx?Siteid=" & SiteID & "&MmmID=99&fd=Benner_Files&NW=696&NW=249&Pname=" & dt.Rows(i).Item("Files").ToString
End If
litList.Text &= "<li><a href=""" & URL & """ title=""" & Title & Targetsdes & """" & Targets & " ><img src=""" & ViewState("Roots") & "" & ImgURL & """ alt=""" & Title & """ /></a></li>"
litLists.Text &= "<li>"
litLists.Text &= "<div>"
If dt.Rows(i).Item("Files").ToString <> "" Then
ImgURLs = ViewState("Roots") & "WebTools/Thumbnail.ashx?Siteid=" & SiteID & "&MmmID=99&fd=Benner_Files&NW=71&NW=71&Pname=" & dt.Rows(i).Item("Filess").ToString
End If
litLists.Text &= "<a href=""#"" title=""" & Title & """><img src=""" & ViewState("Roots") & "" & ImgURLs & """ alt=""" & Title & """ title=""" & Title & """/></a>"
litLists.Text &= "<h4>" & dt.Rows(i).Item("contents").ToString & "</h4>"
litLists.Text &= "</div>"
litLists.Text &= "</li>"
Next
Else
Me.Visible = False
End If
dt.Dispose()
End Sub
|
|
|
|
|
In this kind of case the best and quickest way to find out the problem is to use the debugger. Place a breakpoint on the line
Dim startTime As DateTime = dt.Rows(i).Item("DisplaySDate").ToString()
and go through the line one-by-one. Investigate what are the values for
dt.Rows(i).Item("DisplaySDate")
and
dt.Rows(i).Item("DisplayEDate")
Could it be that that either one is empty or has a value you wouldn't expect.
Also I'd suggest using DirectCast instead of implicitly converting the string date to datetime.
|
|
|
|
|
I wanted to upload Multiple Files With ListBox in ASP.NET but there is an error at specific place....
The error on :
File.Add(FileUpload1);
It showing error on 'File.Add'
asp:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" style="z-index: 1; left: 420px; top: 315px; position: absolute; width: 285px; height: 22px" />
<asp:Button ID="btnUpload" Text="Add" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg, application/exe" style="z-index: 1; left: 425px; top: 535px; position: absolute" />
<hr />
<asp:Label ID="lbl_text" runat="server" ForeColor ="Red" style="z-index: 1; left: 701px; top: 495px; position: absolute" />
<asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 415px; top: 371px; position: absolute; width: 280px; height: 147px; margin-left: 3px; margin-top: 0px"></asp:ListBox>
<asp:Button ID="btn_remove" runat="server" OnClick="btn_remove_Click" style="z-index: 1; left: 500px; top: 535px; position: absolute" Text="Remove" />
c#:
protected void UploadMultipleFiles(object sender, EventArgs e)
{
try
{
if (FileUpload1.HasFile)
{
if (FileUpload1.PostedFile.ContentLength > 0)
{
if (ListBox1.Items.Contains(new ListItem(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))))
{
lbl_text.Text = "File already in the ListBox";
}
else
{
File.Add(FileUpload1);
ListBox1.Items.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName));
lbl_text.Text = "Add another file or click Upload to save them all";
}
}
else
{
lbl_text.Text = "File size cannot be 0";
}
}
else
{
lbl_text.Text = "Please select a file to add";
}
}
catch (Exception ex)
{
}
}
protected void btn_remove_Click(object sender, EventArgs e)
{
if (ListBox1.Items.Count > 0)
{
if (ListBox1.SelectedIndex < 0)
{
Label1.Text = "Please select a file to remove";
}
else
{
File.RemoveAt(ListBox1.SelectedIndex);
ListBox1.Items.Remove(ListBox1.SelectedItem.Text);
lbl_text.Text = "File removed";
}
}
}
|
|
|
|
|
|
The name 'Files' does not exist in the current context
|
|
|
|
|
Thank you so much for your help.
I got the answer.
I did not declare file, that's why it shows error. now I'm done.
|
|
|
|
|
Hi,
Struggling at the moment to retrieve an image (I'm successfully putting the image into the database) and place into a webpage - I've done a lot of reading without success.
I've tried things like :-
Dim connection As New SqlConnection(access.SQLstrconn)
Dim command As New SqlCommand("Select additionaldiagram from bluediagram where ID = 24", connection)
connection.Open()
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
connection.Close()
Dim picture As System.Drawing.Image = Nothing
Using stream As New IO.MemoryStream(pictureData)
picture = System.Drawing.Image.FromStream(stream)
Image1 = picture
End Using
To no avail
Any help would be most appreciated
|
|
|
|
|
|
Thank you, I'll have a read
|
|
|
|
|
That's c# anyone got a vb example ?
|
|
|
|
|
|
I got the source code but there is no output coming out.
there is no any error too. can you please help me..
This is the source code I used in asp:
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" style="z-index: 1; left: 420px; top: 315px; position: absolute; width: 285px; height: 22px" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg, file/exe" style="z-index: 1; left: 420px; top: 341px; position: absolute" />
<hr />
<asp:Label ID="lblSuccess" runat="server" ForeColor ="Red" style="z-index: 1; left: 518px; top: 344px; position: absolute" />
c#:
foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
{
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
}
lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count)
|
|
|
|
|
file/exe is not the MIME type for executable files. It will most likely come through as application/octet-stream , but it depends on the browser and the client OS.
NB: Uploading executable files to the web server is rather dangerous. If you haven't configured your server properly, there's a possibility that the uploaded file could be executed on your server, which would be a major security vulnerability.
How to configure uploads for IIS Web applications[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for your kind info.
This is my company requirement to do so. I will discuss about it with the authority person.
Thank You
|
|
|
|