Posts

Donate

Update ASP.NET Web Forms Label Control Value Using Continuous Mouse Down Click

Starting today, I'm going to contribute source code in vbforums.com( Visual Basic Forum ). The community helped me way back since VB 6.0 and VBA. And in turn, it's time to give back as an experienced member. :) Here's a an ASP.NET application I posted in ASP.NET code bank on how to update label values continuously on mouse hold. Update Label Value using jQuery/Javascript in ASP.NET Reference: Easily do a continuous action on mouse hold using javascript Cheers! :)

Bind XML Node Value To GridView Column In ASP.NET Using XPath

Image
Given in a datasource object where in you have a column which contains an XML string and you want to bind a certain node value instead of the entire XML string to GridView column, here's a solution using XPath. ASPX: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 <asp:GridView ID= "gvPersons" runat= "server" AutoGenerateColumns= "False" BackColor= "White" Width= "400px" BorderColor= "#E7E7FF" BorderStyle= "None" BorderWidth= "1px" CellPadding= "3" > <AlternatingRowStyle BackColor= "#F7F7F7" /> <Columns> <asp:BoundField DataField= "ID" HeaderText= "ID" > <ItemStyle Width= "50px" /> </asp:BoundField> <asp:BoundField DataField= "XMLData" HeaderText= "Name" > <ItemStyle Width= &quo

Retrieve Last Inserted Record In MySQL Database Using C#.NET

To get last inserted unique ID in MySQL, use LAST_INSERT_ID(). C# Code: 1 2 3 4 string insert_product_query = ( "INSERT INTO PRODUCTS (Stock) VALUES (5); SELECT LAST_INSERT_ID()" ); MySqlCommand cmd_query = new MySqlCommand(insert_product_query, objConn); int idResult = Convert.ToInt32(cmd_query.ExecuteScalar()); txtID.Text = idResult.ToString(); MySQL Docs: Getting Last Unique ID in MySQL

ASP.NET Generic Handler Not Downloading .pptx (PowerPoint) And .pdf Files Properly

Hello, There was a question raised in the forums as to why the generic handler doesn't download properly PowerPoint and PDF (.ppt/.pdf) files using Firefox but works perfectly using chrome and IE. The solution is to add a content-disposition header and set the ContentType property of context.Response. VB.NET Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Sub ProcessRequest( ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim documentID As Int32 If Not context.Request.QueryString( "documentID" ) Is Nothing Then documentID = Convert.ToInt32(context.Request.QueryString( "documentID" )) Else Throw New ArgumentException( "No parameter specified" ) End If Dim strm As Stream = ShowDocument(documentID) context.Response.AddHeader( "content-disposition" , "attachment; filename=" &

ASP.NET MVC ActionResult With [HttpPost, HttpPut] Filter Not Executing

Given the ActionResult method and View that executes the controller. [HttpPost, HttpPut] public ActionResult Update(EditModel input) { if (ModelState.IsValid) { var person = Database.People.Find(input.Id); input.ToPerson(person); Database.SaveChanges(); return RedirectToAction( "Edit" , new { id = person.Id }); } return View( "Edit" , input); } View: @model PagedListTableMvcDemo.Models.EditModel @{ ViewBag.Title = "Edit"; } <h2>Update</h2> @using (Html.BeginForm("Update", "People")) { @Html.Partial("_Person") } When the user clicks the submit button rendered by the BeginForm helper, the browser shows an error URL not found or The view does not navigate to the Action with the corresponding Controller supplied in the BeginForm's parameters. The solution is to replace %5BHttpPost, HttpPut%5D with AcceptVerbs attribute. [AcceptVerbs(HttpVerbs.Post | HttpVerbs.

Apply ComboBox Border Color In VB.NET Windows Forms

Image
Here's a simple way to decorate border color in Combobox control. The solution is a conversion of C# code originally developed by a C# Corner forum member. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. AddHandler Me .Paint, AddressOf DrawBorder End Sub Private Sub DrawBorder( ByVal sender As Object , ByVal e As PaintEventArgs) Dim rect As New Rectangle( Me .ComboBox1.Location.X - 1, Me .ComboBox1.Location.Y - 1, Me .ComboBox1.Width + 1, Me .ComboBox1.Height + 1) Dim pen As New Pen(Color.Red, 1) Dim g As Graphics = e.Graphics g.DrawRectangle(pen, rect) End Sub Customized Combobox

Cannot assign <null> to anonymous type property (ASP.NET MVC Object RouteValues)

Image
After reading an article called ASP.NET MVC Partial Rendering by Stewart Leeks, I decided to download the code sample and gave it a spin. As I reviewed each classes and controllers, I needed to implement some changes on saving (ActionResult decorated by [HttpPost]) attribute. The updates would be to pass a value to parameter linkId so that I can add new record after editing a new one. The first solution I have in mind was to pass a -1 to linkID. This would work but, this will append a -1 to the url being requested. return RedirectToAction( "ListAndEdit" , new { linkId = -1 }); Image The second solution was to pass an object to the routeValue. However, this would append a System.Object to the request url. return RedirectToAction( "ListAndEdit" , new { linkId = new object ()}); Image The last solution I cam to think was to pass a null value to the routeValue. Unluckily, you can't assign a null value to an anonymous type property. return RedirectToAc

Validate XML against XSD File In C# And VB.NET

In my nature of work, we dealt with XML files and schema on a daily basis. And here's a cool snippet on validating XML file against and XSD file. C# using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Xml; using System.Xml.Schema; using System.Xml.XPath; public class Form1 { private void Form1_Load(SystemObject sender, SystemEventArgs e) { XmlDocument myDocument = new XmlDocument(); myDocument.Load( "C:\\somefile.xml" ); myDocument.Schemas.Add( "namespace here or empty string" , "C:\\someschema.xsd" ); ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler); myDocument.Validate(eventHandler); } private void ValidationEventHandler( object sender, ValidationEventArgs e) { switch (e.Severity) { case XmlSeverityType.Error: Debug.WriteLine( "Error: {0}" , e.Message); break ; case

Simple Array CRUD Manipulation Using AngularJS Framework

Image
This weekend I decided to create a simple AngularJS CRUD array application. This example was based on Dan Wahlin's AngularJS tutorial. I simply reused the css and js files for simplicity sake. So, let's proceed with the actual scripts and html. Main HTML (Contains the input controls and div with ng-view directive which is the container of the partial view: <div data-ng-controller= "CustomerController" > <h3>CRUD application in AngularJS Array</h3> <hr /> Name:<br /> <input id= "inName" type= "text" data-ng-model= "inputData.name" placeholder= "name" /> <br /> City:<br /> <input id= "inCity" type= "text" data-ng-model= "inputData.city" placeholder= "city" /> <br /> <button class= "btn btn-pr

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory (AngularJS)

Recently interested on AngularJS, I started reading Dan Wahlin's AngularJS material and downloaded the samples in Visual Studio 2012. Upon running the code, I encountered an error which is the title of this post. After days of testing, I noticed that the url doesn't change on runtime since each examples are treated as partial views loaded into a main view. This lead me to the right direction which is a solution from Microsoft on enabling defaultDocument in web.config. Web.config: <system.webServer> <defaultDocument enabled= "true" > <files> <add value= "home.html" /> </files> </defaultDocument> </system.webServer> Where home.html is the main html document which the partial views are loaded.

Donate