TO CONVERT DATAGRID DATA TO EXCEL & WORD DOC

Labels:

DATAGRID TO EXCEL

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

DATAGRID TO WORD DOC

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

CONFIRMATION OF DELETE BUTTON IN GRID

Labels: ,

private void grd_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.FindControl("Delete") != null)
{

((LinkButton) e.Item.FindControl("Delete")).Attributes.Add("onClick", "return confirm('Are you sure to delete this item?');");;

}
}

findcontrol() method searches the current naming container for a server control with the specified id parameter.using the findcontrol we find the delete link button and give the confirmation box using javascript when the button in the grid is clicked.

Changing Link Text

Labels:

<html>
<head>
<script>
function ChangeLinkText(obj)
{
var element = document.getElementById(obj);
element.innerHTML = 'Link Text Changed';
}
</script>
</head>
<body>
<a id="Link" href="javascript:ChangeLinkText('Link');">Click to Change
Link Text</a><br>
<a id="OrdinaryLink" href="http://geeksdotnetcorner.blogspot.com"> Enter
GeeksDotNetCorner </a>
</body>
<html>

To view source of a SHOW MODAL DIALOG PAGE

Labels:

This function is used to view the source of showmodaldialog page .

function viewSource()
{
show=window.open();
show.document.open('text/plain').write(document.documentElement.outerHTML);
return false;
}

Authentication For Beginners

Labels:

Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against some authority. If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity. Once an identity has been authenticated, the authorization process determines whether that identity has access to a given resource.

There are three types of Authentication :

  • Forms authentication
  • Passport authentication
  • Windows authentication

Namespace used for authentication System.Web.Security

Example web config syntax:

<authentication mode="Forms">

<forms name="DBACookie" loginUrl="Login.aspx" protection="All" timeout="90" path ="/">

<credentials passwordFormat="Clear">

<user name="test" password="test"></user>

<user name="test1" password="test2"></user>

</credentials>

</forms>

</authentication>

Code Behind

if (FormsAuthentication.Authenticate(txtUser.Text,txtPass.Text))

{

FormsAuthentication.RedirectFromLoginPage(txtUser.Text,false);

Response.Redirect("./Home.aspx");

}