Category: "Programming"
ASP.Net Core MVC Validations are not working , after added a click event in the submit button
I added a click event in the submit button to display a confirmation message:
$("#btnSubmit").click(function () {
alert("An event is clicked");
});
That broke all client-side validations of ASP.Net Core MVC, however, the server side validations is still working. You cannot submit an event with invalid data, but it won't display the errors messages.
I tried to add the javascript code in the submit event in form instead of the click event of the event, that is not working too. Even I added another invisible submit button, after the confirmation message is displayed, then the code will trigger the click event of that invisible submit button. That is still not working.
I randomly placed the script tags. I found the script file which contains the click event needs to place after the validation scripts:
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script><script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
Custom ASP.NET Identity MVC 5 - Part 1
I am working a new version of AdvGen CMS. I found the ApplicationUserManager has to use their Entity Framework. I cannot just build our own ApplicationUserManager to switch a different ORM layer. You have to build your own IUserStore like this:
public class AdvGenUserStroe : IUserStore
-->
And then build your own ApplicationUserManager which is using this custom user store.
This is the only way to have a Custom ASP.NET Identity in MVC 5
WPF: How to access a control in style
Source:Open Clip Art Using Under Public Domain Attribution
I got a control in style template at one of my custom controls, Like this:
<Style TargetType="{x:Type advgenControls:CollapsibleControl}" x:Key="LeftPanel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type advgenControls:CollapsibleControl}">
<Grid>
<ContentPresenter x:Name="PART_ContentPresenter"/>
<ResizeGrip Grid.Row="1" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" HorizontalContentAlignment="Right" Margin="0,0,2,2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I just want to call that "PART_ContentPresenter". But that is xaml living in resources.
That is easy I can use GetTemplateChild("PART_ContentPresenter" ) and call at the OnApplyTemplate(). Please remember don't use it at OnInitialized(EventArgs e). At that time, styles has not loaded yet, you get a null object.:
Code
public override void OnApplyTemplate() | |
{ | |
base.OnApplyTemplate(); | |
if (this.IsInitialized) | |
{ | |
ContentPresenter cp = GetTemplateChild("PART_ContentPresenter" ) as ContentPresenter; | |
if(sections.Count >0){ | |
cp.Content = sections[0]; | |
} | |
} | |
} |
WPF Error:cannot set name attribute value '{control}'
Source:Open Clip Art Using Under Public Domain Attribution
I found the wpf user control cannot have any child has a name attribute, such as:
<advgenControls:CollapsibleControl> <TreeView x:Name="treeView" Style="{StaticResource MainLeftPanel}" /></advgenControls:CollapsibleControl>
It will have the error like this:
Cannot set Name attribute value 'treeView' on element 'TreeView'. 'TreeView' is under the scope of element 'CollapsibleControl', which already had a name registered when it was defined in another scope. Line 93 Position 5. (MC3093) - D:\Projects\AdvGenContact\AdvGenContact\AdvGenContact.WPF\MainWindow.xaml:93,5
I did a research on internet, I even tried some suggestions in internet, it doesn't work at all. I found that is no way to do that. I believe that is because User Control is not for that purpose. The user control is to hold some repeatable content across the applications. For example, I got a status bar which it need to place all every window in my application. Then I should create a user control for my own status bar and place into every window. In my case mentioned above, I wish to build a collapsible panel which has a different content in each window, even I will reuse that in other project. User Control is not my best. I should find an existing control to override. In this case, I should use HeaderItemsControl.
Note that: when I finish this control, I will put on my open source probject, AdvGen Contact Manager.
Running SQL Backup in .Net
If you are using SQL Express, you have sql agent to do the backup for you. The only way is using T-SQL in a application code to do that.
I have a C# library to do and winfrom application to do the scheduled task as the example, click here to buy it. That is only AUD$3! It can save you few hours of programming, That is very easy, just like the example below
Code
AdvGenSQLBackup backup = new AdvGenSQLBackup(); | |
backup.DBName = txtDBName.Text; | |
backup.Server = txtServerName.Text; | |
backup.UserName = txtUserName.Text; | |
backup.Password = txtPassword.Text; | |
backup.File = txtFile.Text; | |
backup.Run(); |
Moreover, you can use it in your web application. Then your web application can generate a backup file to your users for downloading.That is very useful.