Skip to main content

Posts

Showing posts with the label ASP.NET Web Forms

Featured Post

How to create customizable products in Shopify for Free (No coding!)

Creating customizable products in your Shopify store not only increase your customer satisfaction, it also increases your conversion rate.  Here is a method to add custom options for your Shopify product and convert it into personalized product - Go to Shopify store page and search for "Advanced Product Customizer" app or you can directly the the Shopify app page by clicking on this link Advanced Product Customizer . Install  Advanced Product Customizer  app for free in your Shopify store  From the application dashboard, enable to app embed block to complete the installation process Click "Product Custom Options"  From the Shopify products list, select the product on which you want to add custom options. Advanced Product Customizer  offers Image Swatch, Color Swatch, Text box, File Upload, Radio, Checkbox, Date Picker and more. Here is the a demo video for adding custom option for a Shopify product -

Reading RAW Images in .NET applications using C#

Sometimes the photos captured from cameras are saved in a raw format. The RAW files are not ready for editing with any bitmap editor. By default GDI+ in windows application do not support RAW file formats. So while reading a RAW image file in .NET we can get exceptions like "Out of memory". Here we will discuss method to read RAW image file in C# application. Using DCRaw dcraw is an open-source computer program which is able to read numerous raw image formats, typically produced by high-end digital cameras. dcraw converts these images into the standard PPM and TIFF image formats. Here is the sample in C# to extarct image from RAW file using DCRaw executable string PathToDcRawExecutable = "C:\\DcRaw\\dcraw-ms.exe"; var _sourceImage = (Bitmap)Image.FromStream(GetImageFromRaw("c:\\testimage.ORF", PathToDcRawExecutable)); public Stream GetImageFromRaw(string inputFile, string dcRawExe) {     var startInfo = new ProcessStartInfo(dcRawExe)     { ...

Pass byte array from C# to C++ and vice-versa

Pass byte array from C# to C++                           If you want to pass a byte array to native DLL as parameter, you can use the Intptr to do this, please check the demo below. /C++ API code: TestDLL_API void TestArrayPara (BYTE * pArray, int nSize) { for ( int i= 0 ; i<nSize; i++) printf( "%d\n" , pArray[i]); } //C# code: class TestClass { [DllImport(@"TestDll.dll")] public static extern void TestArrayPara (IntPtr pArray, int nSize); public static void Test () { byte [] array = new byte [ 16 ]; for ( int i = 0 ; i < 16 ; i++) { array[i] = ( byte )(i + 97 ); } int size = Marshal.SizeOf(array[ 0 ]) * array.Length; IntPtr pnt = Marshal.AllocHGlobal(size); try { // Copy the array to unmanaged memory. ...

Some image operations in C#.NET

Flip Image Using the Image.RotateFlip method, we can rotate the image by 90/180/270-degrees or flip the image horizontally or vertically. The parameter of RotateFlip is System.Drawing.RotateFlipType, which specifies the type of rotation and flip to apply to the image. Code Snippet: //Specifies a 180-degree rotation without flipping pictureBox1.Image.RotateFlip(RotateFlipType.Rotate180FlipNone); //Specifies no rotation followed by a horizontal flip pictureBox1.Image.RotateFlip(RotateFlipType.RotateNoneFlipX); //Specifies a 90-degree rotation followed by a horizontal and vertical flip pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipXY); Join Two Images Bitmap bitmap = new Bitmap(image1.Width + image2.Width, Math.Max(image1.Height, image2.Height));     using (Graphics g = Graphics.FromImage(bitmap))     {         g.DrawImage(image1, 0, 0);         g.DrawImage(image2, ...

ASP.NET Page Life cycle

ASP.NET Life cycle At higer level, this is a two step process - 1. When user sends a request ASP.NET creates an environment which can process the request. Here ASP.NET creates instances of the core objects that will be used to process the requst. This includes HTTPContext, HttpRequest and HttpResponse object. 2. After creating the environment their is a series of events processed by modules, handlers and page objects to process the request. (I) ASP.NET Environment Creations 1. User sends a request to IIS. IIS first checks which ISAPI (Internet Server Application Programming Interface) extension can server this request. If the request is for an .aspx page then the request will be redirected to ASP.NET (aspnet_isapi.dll) for processing. 2. If this is the first request to the website then a class called as "ApplicationManager" creates a application domian where the website can run.Application domain provides the actual isolation levels so that various website host...

Adding AJAX HTMLEditorExtender control in webform

Here are the steps to add ajax HMTLEditorExtender control in webform. 1. In VS 2013 open Tools > Library Package Manager > Package Manager Console. 2. Enter command : PM> Install-Package AjaxControlToolkit . This will download and add AjaxControlToolkit.dll reference with your website. 3. Add following tags in web.config  - <configSections>     <sectionGroup name="system.web">       <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit" />     </sectionGroup>   </configSections> <sanitizer defaultProvider="HtmlAgilityPackSanitizerProvider">       <providers>         <add name="HtmlAgilityPackSanitizerProvider" type="AjaxControlToolkit.Sanitizer.HtmlAgilityPackSanitizerProvider"></add>       </providers>     </sanitize...

Implementing Validation group in ASP.NET

Sometimes we have multiple sections in our web forms for validation. These sections need their separate validation. For example I have two sections - one to insert a category and other one to update existing category name. For inserting category the  text box is txtNewCategory and for updating category text box is txtUpdateCategory. Both have RequiredFieldValidator validation control. In this case we want that when validation of txtNewCategory happens then txtUpdateCategory should not be validated and vice versa. This can be achieved by creating Validation Group. Here is the example  - <asp:TextBox ID="txtNewCategory" runat="server"> </asp:TextBox> <asp:RequiredFieldValidator ID="reqFieldCategory" runat="server"  ValidationGroup="GrpNewCategory" ControlToValidate="txtNewCategoryName" ErrorMessage="Please enter new category name"> </asp:RequiredFieldValidator>  <asp:Button ID...

ASP.NET 4.0 Web forms URL Routing

Hi, while working on a ASP.NET project I saw that URLs of the application were quite large and were not much meaningful to the user. Also they were showing the actual folder structure in the project that I found a bit unsecured. So, here I get the requirement to configure application to accept URL of webpages which are meaningful and short. To fulfill this requirement I used URL routing feature of ASP.NET. URL routing lets you to configure your application to accept URL which do not point to physical files. Instead of this we can show some semantically meaningful URL to user. For example - Initial URL - http://www.yoursite.com/products.aspx?category=laptop Using routing you can configure your application render same page using following URL - http://www.yoursite.com/products/laptop You can also find that new URL is SEO - friendly and can help in search engine optimization (SEO). Implementing URL routing in ASP.NET web forms In the implementation part of routing we n...

Dynamically adding controls to web form and their event handling in ASP.NET using C#

Add control dynamically using code on web form Sometimes in web form we need to add controls using code. Following C# code can be used to add button control dynamically to web form.     Button btn1 = new Button();     btn1.Text = "New Button";     this.Controls.Add(btn1); To add the dynamically created button control to a Panel control use following code -     Panel1.Controls.Add(btn1); Event Handler for dynamically added control We can use following code to declare click event for dynamically added button code-   btn1.Click += new EventHandler(btnClick); After declaring the click event, define the event handler using C# - private void btnClick(object sender, EventArgs e) {       Button btn = (Button)sender;  //get the button which is                                     ...

Display images using Datalist in ASP.NET C#

A Datalist control can be used to display images. We can bind the data from database to datalist. Here is the code to display images using datalist. Page source:   <asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal">             <ItemTemplate >                 <asp:Image ID="imglst" runat="server" ImageUrl ='<%#Eval("image")%>' Width="70" Height="50" />             </ItemTemplate>  </asp:DataList> C# code:  protected void Page_Load(object sender, EventArgs e)         {             DataSet ds = new DataSet();             string strcon = ConfigurationManager.ConnectionStrings["con"].ConnectionString;             SqlConnection conn = new SqlConnection(strcon);     ...