Posts

Showing posts with the label ASP.NET Web Forms

Donate

ASP.NET Web Forms Show Tooltip In Gridview Column

Here's how to show tooltip in an asp.net gridview column/cell on mouse hover. This option will set the Tooltip property of a particular gridview cell on RowDataBound event. C# Code: 1 2 3 4 5 6 7 8 protected void grdCustomers_RowDataBound( object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string str = e.Row.Cells[1].Text; e.Row.Cells[1].ToolTip = str; } }

ASP.NET GridView Control CRUD With Bootstrap

Image
Here's a simple CRUD application using ASP.NET GridView control with Twitter Bootstrap as it's css class reference. The code sample used is in VB.NET. Create: Update: Delete: ASPX markup: 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 <div id= "Container" > <div id= "GridContainer" > <div id= "LabelContainer" > <asp:Label ID= "lblHeading" runat= "server" Text= "ASP.NET GridView CRUD with Bootstrap (VB.NET)" > </asp:Label>

ASP.NET GridView RowCommand Event Firing Twice

This issue happened when I migrated an asp.net 3.5 website to an asp.net 4.5 website. Upon clicking Add or Delete linkbuttons in the GridView, the RowCommand event fires twice. After googling for hours, I found a solution that is to remove the Handles GridView1.RowCommand in the event declaration. The code below does not work (event fires twice) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Protected Sub GridView1_RowCommand ( ByVal sender As Object , ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _ Handles GridView1.RowCommand If e.CommandName.Equals( "AddNew" ) Then Dim txtNewName As TextBox txtNewName = CType (GridView1.FooterRow.FindControl( "txtNewName" ), TextBox) Dim cmbNewGender As DropDownList cmbNewGender = CType (GridView1.FooterRow.FindControl( "cmbNewGender" ), DropDownList) Dim txtNewCity As TextBox txtNewCit

Formatting ASP.NET Web Forms Panel as Bootstrap Modal Dialog

Here's how you make use of the asp.net panel container that will serve as modal dialog. During render, panel will be converted to div elements. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <asp:Panel ID= "pnlModal" runat= "server" role= "dialog" CssClass= "modal fade" > <asp:Panel ID= "pnlInner" runat= "server" CssClass= "modal-dialog" > <asp:Panel ID= "pnlContent" CssClass= "modal-content" runat= "server" > <asp:Panel runat= "server" class= "modal-header" > <button type= "button" class= "close" data-dismiss= "modal" > <span aria-hidden= "true" > &times; </span><span class= "sr-only" > Close </span> </button>

ASP.NET Web Forms Using Master Page Not Found On Visual Studio 2012 IDE

When the RTM versions of Visual Studio 2012 were updated to version 4, I noticed that when you Add a New Item in an Asp.net website or project, "Web Form Using Master Page" has gone missing. I soon realized that Web Form Using Master Page is replaced with "Content Page" in the Add New Item Dialog. :)

Databinding ASP.NET 4.5 GridView With jQuery And Ajax

Image
Hi, Here's a simple asp.net program that performs adding of data to GridView control through jQuery and ajax. On page load, perform databinding on dropdown list and gridview using server side and code behind. And on client side, that is a selection change occurs in dropdown list, perform binding by adding table rows and columns to GridView. Page Load (Load All Products): Selection Change (Load Specific Products): The sample code is available for download here: Databinding ASP.NET 4.5 GridView with jQuery and Ajax Code Cheers!

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

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=" &

Simple Knockout.js Example In ASP.NET Web Forms

Image
Intrigued with emerging Javascript framework called knockout, I decided to try a simple example myself. As defined by Wikipedia: Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates. The underlying principles are therefore: 1. A clear separation between domain data, view components and data to be displayed 2. The presence of a clearly defined layer of specialized code to manage the relationships between the view components The features of Knockout are based on Declarative bindings: A. Automatic UI refresh (when the data model's state changes, the UI updates automatically) B. Dependency tracking C. Templating (using a native template engine although other templating engines can be used, such as jquery.tmpl) I come to a conclusion that this has similar approach to WPF MVVM. So, to get started with, download the latest Knockout.js framework here: Knockout Home Page and add reference to your html or aspx markup: Code: <!

The type specified in the TypeName property of ObjectDataSource 'ObjectDataSource1' could not be found (ASP.NET Webservice)

As I was updating one of my ASP.NET Web Forms application to 4.5, running the app generates an error as stated above. I remembered that the Object Datasource control was dependent on a webservice. So, after reviewing the new configuration of the webservice, the port, url and namespace have changed. So, here are the steps to make my app work again. Steps: 1. Update the web service .discomap file through Add Service Reference and then choosing advanced to target it as .NET 2.0 platorm. Though Service Reference should be recommended or WCF service. 2. Change Web.Config setting of the web service including it's IP and Port. Example:<br> <add key="localhost.ECommerceService" value="http://192.168.2.1:1448/WebDeployServer/QuotesPaymentService.asmx"/><br> to<br><add key="localhost.ECommerceService" value="http://192.168.2.1:14070/WebDeployServer/QuotesPaymentService.asmx"/> 3. Configure again the obje

Set GridView Lines And Pager Background Color In ASP.NET Web Forms

Usually, in ASP.NET 2.0, setting the GridView lines through property should work. However in 4.5, it doesn't seem to render correctly. One blog pointed out to set the gridlines through it's row data bound property as demonstrated on the code below: Aspx Markup <asp:GridView ID= "GridView1" runat= "server" DataSourceID= "SqlDataSource1" BorderColor= "Black" BorderStyle= "Solid" PageSize= "2" AllowPaging= "True" OnRowDataBound= "GridView1_RowDataBound" BackColor= "White" CellPadding= "3" > <FooterStyle BackColor= "White" ForeColor= "#000066" /> <HeaderStyle BackColor= "#006699" Font-Bold= "True" ForeColor= "White" /> <PagerStyle BackColor= "White" ForeColor= "#000066" HorizontalAlign= "Justify" Wrap= "True"

Remove Extra Spacing In Between NumericUpDownExtender Default Buttons (ASP.NET Ajax)

Image
When integrating NumericUpDown Extender to your asp.net apps, there's a wide gap in between the up/down buttons as shown below: The trick to remove the extra space in between NumericUpDownExtender Default Buttons is to replace the doctype declaration in master page from: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> to: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> Note: This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font) as described in w3. So, I believe there are presentational elements or deprecated elements incorporated into this extender. Reference: StackOverflow Cheers!

The Controls collection cannot be modified because the control contains code blocks(i.e.<% …%>) (ASP.NET HTML Editor Extender)

After adding an HTML Editor extender to my asp.net page, an error shows when rendering the page to the browser as stated which is the title of this post. I found the solution in asp.net forums which is to wrap aspx markup codes enclosed with <% %> using placeholder control. The code below is in my ASP.NET Master Page: <head runat= "server" > <title></title> <link href= "~/Styles/Site.css" rel= "stylesheet" type= "text/css" /> <asp:PlaceHolder Runat= "server" > <script src= '<%=Page.ResolveUrl("~/Scripts/jquery-1.4.1.min.js") %>' language= "javascript" type= "text/javascript" ></script> </asp:PlaceHolder> <asp:ContentPlaceHolder ID= "HeadContent" runat= "server" > </asp:ContentPlaceHolder> </head> Reference: Handling Ajax Extenders Error :)

ASP.NET jQuery $find() Not Working In Onclick() Event Of Radio Button

In an application where i want trigger the onclick event of radio button that has a $find() method, which will retrieve the radio button's value, the code below doesn't work. <input type= "radio" id= "rb1" name= "format" value= "format2" runat= "server" onclick= "$find('<%=dpe1.ClientID %>').populate(this.value);" /> d.m.y <input type= "radio" id= "rb2" name= "format" value= "format3" runat= "server" onclick= "$find('<%=dpe1.ClientID %>').populate(this.value);" /> y/m/d where dpe1 is a DynamicPopulateExtender Ajax Extender.The solution I made was to remove the populate logic and transfer it to a javascript function. Here's the revised code: //javascript code function rbFunction() { //$find('<%=dpe1.ClientID %>').populate($("input:radio:c

ASP.NET Gridview Not Getting New Values In RowUpdating() Event

Assuming in your row updating event, you do some editing in your textbox and then click update button. The event in turn saves your modified records to the database. However, when you tried rebinding the datasource of Gridview it seems that you didn't get the newly updated values. The simple trick would be to set the Gridview property EnableViewState to false .

A field or property with the name 'ClassName.Property' was not found on the selected data source In ASP.NET Gridview

As i was running an asp.net application in my local machine, I encountered an exception which is the title of this post. This asp.net app runs perfectly from the other workstation. I tried searching solutions in google but found out that most of the recommendations were to redo the model or the business tier. One option I tried was to replace the BoundField of the gridview with TemplateField with label as the bound control using Eval("expression"). Glad that worked. It could be an IIS issue as stated in other forums. Here's the gridview markup changes: (Windows 7 64 Bit using BoundField) <asp:BoundField DataField= "Product.Name" HeaderText= "Name" > <ItemStyle Width= "350px" /> </asp:BoundField> (Windows 7 32 Bit using TemplateField) <asp:TemplateField HeaderText= "Product Name" > <ItemStyle Width= "350px" /> <ItemTemplate> <asp:Label ID= &quo

Using AutoMapper In Asp.Net Web Forms Database Application

Image
Hello, Based from Scott Millet's Asp.Net Design Patterns , I was curious on the AutoMapper Framework that maps Domain Entities to View Models. So I tried to give it a spin by incorporating the tool in an ASP.NET WebForms application. Here's the code snippets breakdown: Order class: /// <summary> /// One order may contain one or many order details. /// </summary> public class Order { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ; } public string ShipAddress { get ; set ; } public IList<OrderDetails> OrderDetail { get ; set ; } } Order View class: public class OrderView { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ;

AnimationExtender Animation Using JSON Not Working In ASP.NET

When setting animations for AnimationExtender control using JSON/Javascript, setting the AnimationTarget with the explicit control id such as panel ID does not work when rendered to browser specified by the code below: "AnimationTarget" : "panelDescription" The workaround is to get the clientID of the panel control rendered through the browser. Below is the workaround code: //Note: this is just a fragment of the JSON animation //the actual animation might be a little bit specific than this. var animation = "AnimationTarget":"' + '<%= panelDescription.ClientID %>' + '","AnimationChildren"'; //set click behavior animationExtender.set_OnClick(animation); Cheers!

Multiple controls with the same ID '_header' were found. FindControl requires In Asp.net Ajax

Good day! After integrating ajax accordion pane controls in my asp.net app, an exception pops up as stated by the title of the post. The culprit was that I initialized two AccordionPane objects w/o specifying the ID's of each object. The solution is to include ID's in each control.See example below: AccordionPane ap1 = new AccordionPane(); ap1.ID = "ap1" ; ap1.HeaderContainer.Controls.Add( new LiteralControl( "Product Code" )); ap1.ContentContainer.Controls.Add( new LiteralControl(datarow[ "ID" ].ToString();)); AccordionPane ap2 = new AccordionPane(); ap2.ID = "ap2" ; ap2.HeaderContainer.Controls.Add( new LiteralControl( "Product Name" )); ap2.ContentContainer.Controls.Add( new LiteralControl(datarow[ "Prod_Name" ].ToString();)) Cheers!

Donate