Trek Innovations

Thoughts For You

Archive for the 'ASP.NET' Category

Regular Expression To Allow only 2 Decimal Places in the Textbox Control

Regular Expression To Allow only 2 Decimal Places in the Textbox Control :

In order to allow only 2 decimal places in the textbox use the regular expression validator. In the validator control there will be a property called ValidationExpression,use this property to assign the valid expression as shown below.

<asp:TextBox ID=”_tbCost” runat=”server” TabIndex=”4″></asp:TextBox>

<asp:RegularExpressionValidator ID=”_ReqExpressionPhoneNo” runat=”server” ErrorMessage=”Enter numbers & ‘.’ only,should contain only 2 decimal places.” ControlToValidate=”_tbCost” Display=”none” ValidationExpression=”(?!^0*$)(?!^0*\.0*$)^\d{1,18}(\.\d{1,2})?$”>

</asp:RegularExpressionValidator>

Read more

Share This Post No comments

Export NestedGridView To Excel

In order to export the nested gridview please follow the code below.

SalesReport.Ascx

<%@ Control Language=”C#” AutoEventWireup=”true” Codebehind=”SalesReport.ascx.cs”
Inherits=”Epod.UserControls.SalesReport” %>
<div id=”divgridView” class=”grid”>
<asp:GridView ID=”gvProducts” runat=”server” AllowSorting=”false” AllowPaging=”false” AutoGenerateColumns=”False”
CellPadding=”4″ GridLines=”None” ShowFooter=”false” OnRowCommand=”gvProducts_RowCommand”
Width=”100%”>
<Columns>
<asp:TemplateField ItemStyle-HorizontalAlign=”Left”>
<ItemTemplate>
<tr>
<td>
<asp:LinkButton ID=”_btnExpandandCollapse” runat=”server” Text=”<img src=’../images/expand.gif’ alt=’Expand to see detailed report’ border=’0′ />”
CssClass=”GridViewDataHyperLink” CommandArgument=’<%# Container.DataItemIndex %>’
CommandName=’<%# Eval(“ProductId_pk”) %>’ ToolTip=”Expand to see the detailed report”></asp:LinkButton>&nbsp;&nbsp;
<asp:Label ID=”_lblEmployeeName” Font-Bold=”true” runat=”server” Text=’<%# Eval(“ProductName”) %>’></asp:Label>

Read more

Share This Post No comments

Export Data from Data Table to Excel File Format using C#.NET

In order to achieve this first, you need to add a component known as Excel.dll (Microsoft excel 11.0 Object Library) into your .NET project references.

To do above follow below instructions:

Add a reference to the Microsoft Excel Object Library. To do this, follow these steps:

a. On the Project menu, click Add Reference.

b. On the COM tab, locate Microsoft Excel 11.0 Object Library, and then click Select.

c. Click OK in the Add References dialog box to accept your selections. If you receive a prompt to generate wrappers for the libraries that you selected, click yes.

Read more

Share This Post No comments

Validating Controls within Ajax Tab Panels/Tab Control

Normally when we are using Ajax TabContols in aspx page with validation controls enabled on each and every TabPanel. Suppose if iam having 3 tab panels in TabControl and every tabpanel has some validations enabled and if iam in 1st panel and I submitted the form by clicking the button and in the 1st panel every thing is ok i.e. I filled all my required fields on the 1st TabPanel. But I left some fields blank on the 2nd and 3rd TabPanel; when you click on submit button the validations will be enabled on 2nd and 3rd panel but the tab index of the TabControl will be still on the 1st TabPanel only. But we want TabIndex to automatically change based on the validation failed on the TabPanel. In order to do that we have to write a piece of JavaScript as show below:

<script type=”text/javascript”>

var handleTabChange = true;

function ValidatePage()

{

if(handleTabChange)

{

if (Page_ClientValidate(‘Tab1′) == false)

{

$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(0);

}

else if (Page_ClientValidate(‘Tab2′) == false)

{

$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(1);

}

else if (Page_ClientValidate(‘Tab3′) == false)

{

$find(“<%=TabContainerAddEnquiry.ClientID%>”).set_activeTabIndex(2);

}

}

else

{

handleTabChange = true;

}

}

</script>

Read more

Share This Post No comments

Exporting GridView to Excel Problem When Using Web UserControl:

This article explains how you can export your GridView control to Excel files. If you are working with web user control. Suppose if you are having your gridview in your User Control and you are trying to export the gridview data to some other format some thing like this

protected void _btnReports_Click(object sender, EventArgs e)

{

Response.Clear();

Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);

Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);

Response.Charset = “”;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = “application/vnd.doc”;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

//Render(htmlWrite);

_gvViewresults.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

Read more

Share This Post No comments

Exporting GridView to Excel ‘GridView’ must be placed inside a form tag

This article explains how you can export your GridView control to Excel files. If you are working with GridView.

Exporting Grid View to Excel Files:

The approach is pretty much the same as it was in Gridview. The following code executes on a button click event.

protected void _btnReports_Click(object sender, EventArgs e)

{

Response.Clear();

Response.Write(@”<!DOCTYPE HTML PUBLIC “”-//W3C//DTD HTML 4.0 Transitional//EN”">”);

Response.AddHeader(“content-disposition”, “inline;filename=search_topicarea.doc”);

Response.Charset = “”;

Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = “application/vnd.doc”;

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

//System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

//Render(htmlWrite);

_gvViewresults.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

}

Read more

Share This Post No comments

Programming XML with C# & Connecting Data and XML via ADO .NET

Connecting Data & XML via ADO.NET

In this article you can see how to work with XML documents with the help of ADO.NET. In this there are two approaches to work with XML and ADO.

1. You can use ADO.NET to access XML documents.

2. You can use ADO.NET and XML to access XML. Apart from this, you can access RDBMS using ADO.NET and XML.NET.

Read more

Share This Post 1 comment

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

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

Error Page

Error Page

 

Basically this error occurs when a code block is placed in the MasterPage like this

Read more

Share This Post No comments

Concurrence Mode Instance using WCF

Concurrence Mode Instance specifies a service class supports single/multi-threaded modes of operation or not.

WCF follows an asynchronous messaging. It makes extensive use of asynchronous I/O, and as a result, each received message may be dispatched to a receiving object by different threads. Because of this feature allows WCF to use the CPU efficiently, and as a result, allows WCF applications to scale.

Below given example make clear the concurrence mode instance, how service class works with ConcurrencyMode instance property on the ServiceBehaviorAttribute type with respect to the client requests.

Read more

Share This Post 4 comments

What’s new on .Net 3.5 Framework & Visual Studio 2008

Visual Studio 2008 & .Net Framework 3.5 Features 

The newley introduced .NET Framework 3.5 with Visual Studio 2008  provides developers to rapidly create applications that deliver high quality and rich user experiences. Visual Studio 2008 and .NET 3.5 contains a ton of new functionality and improvements which enables organizations of every size to rapidly create secure, manageable, and reliable applications that are optimized for Windows Vista™, SQL Server and the Web.

Visual Studio .NET based Windows application benefits from increased WPF designer performance.  Web development improvements include enhanced features like JavaScript IntelliSense, JavaScript Debugging,supports SQL Server 2008, ADO.NET Entity Framework, ADO.NET Data Services. It provides more powerful new graphics for the development and provides very rich data scaffolding. 

Read more

Share This Post 1 comment

Next Page »