Control ‘GridView’ of type ‘GridView’ must be placed inside a form tag with runat=server.

Leave a comment


Please add below functions in code-behind cs file.

  public override void VerifyRenderingInServerForm(Control control)
{
/* Confirms that an HtmlForm control is rendered for the specified ASP.NET
server control at run time. */
}

public override bool EnableEventValidation
{
get { return false; }
set { /*Do nothing*/ }
}

Add an assembly (.dll) to the GAC manually – .NET

Leave a comment


Situation: While Publishing ASP.NET files onto the remote server there will be no visual studio tools like gacutil.exe. So we can get doubt how can we add assemblies into gac folder (C:\windows\assembly\) without using gac. Here is the solution.

Solution:

1) Go to local Security Policy in windows 7.

Localsecuritypolicy

 

2) Goto Local Policies ——> Security Options—> User Account Control: Run All Administrators in Admin Approval Mode

 

UAC

UAC

 

 

3) By Default it will be Enabled . Disable it and Add the dlls into C:\windows\Assembly\

 

UAC Enable

UAC Enable

4) After adding again enable it and enjoy !!!

 

 

Disabling some of the Textboxes in gridview edit

1 Comment


Situation: You need some text boxes disable when gridview is in edit mode.
=======

Solution:
======

1) Bind the Data without Sqldatasource Control
2) In Row Editing write the code:

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
gridbind();
TextBox tx_chdets = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1”);
tx_chdets.Readonly=true;

}

Insert Null values into datetime column of SQL SERVER using asp.net,C#

6 Comments


Sometimes we will get the situation where we must insert NULL into datetime column in sql server.

Follow these steps to do that:

1) First Include the namespace:

using System.Data.SqlTypes;

2)  Declare

System.Data.SqlTypes.SqlDateTime getDate;
getDate = SqlDateTime.Null;

3) Insert using command Parameters

cmd11.Parameters.AddWithValue(“@encashed_date”, getDate);

——————————<>—————————————

How to Print a Gridview in ASP.NET 2.0

3 Comments


“””””””””””””””””””””””””””””””

<script language=”javascript” type=”text/javascript”>
function getconfirm()
{
return confirm(‘Are you sure you want to change the Folio No?’);
}
function Button1_onclick() {
//open new window set the height and width =0,set windows position at bottom
var a = window.open (”,”, ‘ left = ‘ + screen.width + ‘,top=’ + screen.height + ‘,width=0,height=0,toolbar=0,scrollbars=0,status=0’);
//write gridview data into newly open window

//major change here get innerHTML Of the Div

a.document.write(document.getElementById(‘innerData’).innerHTML);
a.document.close();
a.focus();
//call print
a.print();
a.close();
return false;
}

function IMG1_onclick() {
return Button1_onclick()
}

</script>

“””””””””””””””””””””””””””””””

Here the gridview must be placed in a DIV Tag
===================================

<div id=”innerHTML”>

Place Gridview Control here

</div>

<asp:ImageButton ID=”ImageButton1″ ImageUrl=”~/images/Printer-512×512.png” Width=30 Height=30 runat=”server” OnClientClick=”return Button1_onclick()” />

Using Free Text Box in ASP.NET displaying HTML formatted text

16 Comments


Why do we must use FreeTextBox (FTB) control?

This will be useful when we want to display text with HTML formatting with label control.
when you enter the text in FTB it will saves with all the HTML tags in the table.
while displaying the label control along with browser renders HTML.

Before you start with this control you must it in /Bin folder.

Download the Free TextBox at: http://freetextbox.com
In the aspx page put this:

<%@ Register TagPrefix=”FTB” Namespace=”

FreeTextBoxControls” Assembly=”FreeTextBox” %>
But remember add this in <Page> tag of aspx: ValidateRequest=”false”
ex:

<%@ Page Language=”C#” MasterPageFile=”~/MasterPage.master” AutoEventWireup=”true” CodeFile=”EnterFAQs.aspx.cs” Inherits=”EnterFAQs” Title=”Winning Edge :: FAQs” ValidateRequest=”false” %>

<%@ Register TagPrefix=”FTB” Namespace=”FreeTextBoxControls” Assembly=”FreeTextBox” %>

<FTB:FreeTextBox ID=”txt_desc” runat=”server” Width=”300px” Height=”150px”></FTB:FreeTextBox>

Random number generation in ASP.NET

1 Comment


Random number generation in ASP.NET

ఏదో ఒక్క నెంబర్ జనరేషన్ in ASP.NET

Step 1:

write a class file.
eg:

Create a cs file named as rand.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.VisualBasic;

/// <summary>
/// Summary description for random_number
/// </summary>
public class random_number
{
public string GetRandomNumber(int length, string characterSet)
{

string randomData = “”;

int position = 0;

byte[] data = new byte[length];

int characterSetLength = characterSet.Length;

System.Security.Cryptography.RandomNumberGenerator random = System.Security.Cryptography.RandomNumberGenerator.Create();

random.GetBytes(data);

for (int index = 0; (index < length); index++)
{

position = data[index];

position = (position % characterSetLength);

randomData = (randomData + characterSet.Substring(position, 1));

}

return randomData;

}

}

step 2:

use this in codebehind of any aspx page

random_number r1 = new random_number();
string str= r1.GetRandomNumber(5, “ABCDEFGHIJLLMNOPQRSTUVWXYZ_1234567890”);

Older Entries

%d bloggers like this: