setfocus on control

Posted by Venkat | Labels:

Here is the code to set focus on some control , while we use the Master page

ScriptManager.RegisterStartupScript(Me, Me.GetType(), "Focus", String.Format("window.setTimeout('$get(""{0}"").focus()', 300);", ControlToFocus.ClientID), True)

or Refer this article

http://www.dotnetcurry.com/ShowArticle.aspx?ID=275

Messagebox in Vb.Net

Posted by Venkat | Labels:

Showing messagebox like yes , no in vb.net and proceed if yes else exit ..

       Dim button As DialogResult

button = MessageBox.Show _
("Are you sure you want to exit this application?", _
"Message", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1)

If button = Windows.Forms.DialogResult.Yes Then
Me.Close()
Else
'Do Nothing
End If

Show dates on different format through Query

Posted by Venkat | Labels: ,

Here the number of way to show the date ie: extract from the SQL query

select convert(varchar,getdate(),101)
OutPut:- 06/18/2008

select convert(varchar,getdate(),102)
OutPut:- 2008.06.18

select convert(varchar,getdate(),103)
OutPut:- 18/06/2008

select convert(varchar,getdate(),104)
OutPut:- 18.06.2008

select convert(varchar,getdate(),105)
OutPut:- 18-06-2008

select convert(varchar,getdate(),106)
OutPut:- 18 Jun 2008

select convert(varchar,getdate(),107)
OutPut:- Jun 18, 2008

select convert(varchar,getdate(),108)
OutPut:- 10:53:20

select convert(varchar,getdate(),109)
OutPut:- Jun 18 2008 10:53:30:507AM

select convert(varchar,getdate(),110)
OutPut:- 06-18-2008

select convert(varchar,getdate(),111)
OutPut:- 2008/06/18

select convert(varchar,getdate(),112)
OutPut:- 20080618

select convert(varchar,getdate(),113)
OutPut:- 18 Jun 2008 10:54:01:253

select convert(varchar,getdate(),114)
OutPut:- 10:54:08:473

select convert(varchar,getdate(),120))
OutPut:- 2008-06-18 10:54:15 
For Further Reference : http://www.sql-server-helper.com/tips/date-formats.aspx

Could not load file or Assembly

Posted by Venkat | Labels:


Hi, if you got error like this..Could not load file or Assembly for While you adding AjaxToolkit.dll

You have update your ajaxtoolkit from Codeplex.com

Here the link


http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=8513

Avoid execution of code while you refresh the page

Posted by Venkat | Labels:

Hi , here we have to discuss the how to avoid the execution of code While you refresh the page.. suppose if you have written the code for sending email to users.. after clicking the button the code has been executed suppose if you , Refresh the same page once again the Email sent to the user so here we have to avoid

the execution on code on page_Refresh
this is the code in VB.NET and C#

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Session("CheckRefresh") = Server.UrlDecode(System.DateTime.Now.ToString())
End If
End Sub


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
If Session("CheckRefresh").ToString() = ViewState("CheckRefresh").ToString() Then
Label1.Text = "Hello"
Session("CheckRefresh") = Server.UrlDecode(System.DateTime.Now.ToString())
Else
Label1.Text = "Page Refreshed"
End If

End Sub

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As EventArgs)
ViewState("CheckRefresh") = Session("CheckRefresh")
End Sub


Here in this code i m saving system date and time in session varaible when the page gets load
and in the page prerender event , which occurs after page_Load event , i am
assigning the value if session variable to viewstate varaible

Now in Button_Click Event i m checking if both the values in session
variable and in ViewState varaible are same than page in not refreshed
if they are not same that means page has got refreshed

This is code for C#.NET


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
}
}


protected void Button1_Click(object sender, EventArgs e)
{
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
{
Label1.Text = "Hello";
Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
}
else
{
Label1.Text = "Page Refreshed";
}

}

protected void Page_PreRender(object sender, EventArgs e)
{
ViewState["CheckRefresh"] = Session["CheckRefresh"];
}

Upload Large files using asp.net

Posted by Venkat | Labels:

To upload large files in asp.net you have to increase the MaxrequestLength and Executiontimeout of the httpruntime settings of your web.config file.By Default it will upload 4MB

suppose if i want to upload upto 8 MB you have to include this tag in you web.config file , don't change anything in your machine.config files.

httpruntime  maxRequestLength="1048576" executionTimeout="450"


here 1048576 - 1 GB

Validation for FileUploadControl

Posted by Venkat | Labels: ,

To validate the fileupload control use Custom Validator and call this function on ClientValidateFunction property of Custom validator.

You can pass the file extension , Watever you want to allow..

function ValidateSFrontImageUpload(Source, args)
{
var fuData = document.getElementById('<%= FrontSImage_FileUpload.ClientID %>');
var FileUploadPath = fuData.value;

if(FileUploadPath =='')
{
// There is no file selected
args.IsValid = false;
}
else
{
var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();

if (Extension == "jpg" || Extension == "jpeg" || Extension == "png" || Extension == "gif")
{
args.IsValid = true; // Valid file type
}
else
{
args.IsValid = false; // Not valid file type
}
}
}

Code for Logout button

Posted by Venkat | Labels:

If you are not using master pages then you have to paste this code of all the pages (on load event).


Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();

On logout

You have to write

Session.Abandon();
Session.Clear();

Use If condition inside the Gridiview or Datalist

Posted by Venkat | Labels:

Here the Html Code , html was not allowed here so i have conver < - &lt and > - &gt


&lt asp
:HyperLink ID="HyperLink1" Visible=" &lt %# isFilePathEmpty(Eval("filepath")) % &gt " NavigateUrl="~/AddPost.aspx?ForumID=18#" runat="server" &gt
&lt %# Eval("PartNumber") &gt
&lt /asp:HyperLink &gt

then create a method called isFilePathEmpty(string filePath) in the code behind which returns a boolean.

Validation of ViewSate MAC Failed

Posted by Venkat | Labels:

If you are getting this error .

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster

Write the below code..

Update your web.config with following attributes.

pages validateRequest="false" enableEventValidation="false" viewStateEncryptionMode ="Never" enableViewStateMac="false"

PayOffers.in