Wednesday, January 30, 2008

ASP.Net FileUpload size limit

By default, The maximum size of a file to be uploaded to a server using the ASP.NET FileUpload control is 4MB. You cannot upload anything that is larger than this limit.

To change this size limit, you have to make some changes in the application's web.config:

<system.web>

<httpRuntime maxRequestLength="1048576" executionTimeout="360"/>

</system.web>

maxRequestLength - Attribute limits the file upload size for ASP.NET application. This limit can be used to prevent denial of service attacks (DOS) caused by users posting large files to the server. The size specified is in kilobytes. As mentioned earlier, the default is "4096" (4 MB). Max value is "1048576" (1 GB) for .NET Framework 1.0/1.1 and "2097151" (2 GB) for .NET Framework 2.0.


 

executionTimeout - Attribute indicates the maximum number of seconds that a request is allowed to execute before being automatically shut down by the application. The executionTimeout value should always be longer than the amount of time that the upload process can take.

Thursday, January 17, 2008

ClientScript.RegisterStartupScript

We can run javascript on server side events by using ClientScript.RegisterStartupScript

The sample code shows sample use of the feature.

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 System.Text;


 

public
partial
class
_Default : System.Web.UI.Page

{


protected
void Page_Load(object sender, EventArgs e)

{


StringBuilder sb = new
StringBuilder();


string myMessage = "Hello world!!";

sb.Append("<script language='javascript'>");

sb.Append("alert('" + myMessage + "');<");

sb.Append("/script>");

ClientScript.RegisterStartupScript(this.GetType(), "MsgSummary1", sb.ToString());


 

}

}

Thursday, January 3, 2008

JavaScript: execScript

The function allows u to run scripts at run time

Sample is as below:

<html>
<body>
<script language="JavaScript">
function function1() {
    var m = window.execScript("alert('test');""JavaScript");
    alert("The method returns always "+'"'+m+'"'); 

</script>
<input type="button" value="Click to execute the script" onclick="function1();">
</body>
</html>

javaScript : document.execCommand

By using document.execCommand of javascript,

  1. You can print the current page that is showing in browser.

Javascript for this is : document.execCommand('Print');

  1. You can refresh the page

    Javascript for this is : document.execCommand('Refresh');


     

There are certain set of this kind of commands that can be used in conjution with document.execCommand function are as below:


 

2D-Position

Allows absolutely positioned elements to be moved by dragging.


 

AbsolutePosition

Sets an element's position property to "absolute."


 

BackColor

Sets or retrieves the background color of the current selection.


 

BlockDirLTR

Not currently supported.


 

BlockDirRTL

Not currently supported.


 

Bold

Toggles the current selection between bold and nonbold.


 

BrowseMode

Not currently supported.


 

ClearAuthenticationCache

Clears all authentication credentials from the cache. Applies only to execCommand.


 

Copy

Copies the current selection to the clipboard.


 

CreateBookmark

Creates a bookmark anchor or retrieves the name of a bookmark anchor for the current selection or insertion point.


 

CreateLink

Inserts a hyperlink on the current selection, or displays a dialog box enabling the user to specify a URL to insert as a hyperlink on the current selection.


 

Cut

Copies the current selection to the clipboard and then deletes it.


 

Delete

Deletes the current selection.


 

DirLTR

Not currently supported.


 

DirRTL

Not currently supported.


 

EditMode

Not currently supported.


 

FontName

Sets or retrieves the font for the current selection.


 

FontSize

Sets or retrieves the font size for the current selection.


 

ForeColor

Sets or retrieves the foreground (text) color of the current selection.


 

FormatBlock

Sets the current block format tag.


 

Indent

Increases the indent of the selected text by one indentation increment.


 

InlineDirLTR

Not currently supported.


 

InlineDirRTL

Not currently supported.


 

InsertButton

Overwrites a button control on the text selection.


 

InsertFieldset

Overwrites a box on the text selection.


 

InsertHorizontalRule

Overwrites a horizontal line on the text selection.


 

InsertIFrame

Overwrites an inline frame on the text selection.


 

InsertImage

Overwrites an image on the text selection.


 

InsertInputButton

Overwrites a button control on the text selection.


 

InsertInputCheckbox

Overwrites a check box control on the text selection.


 

InsertInputFileUpload

Overwrites a file upload control on the text selection.


 

InsertInputHidden

Inserts a hidden control on the text selection.


 

InsertInputImage

Overwrites an image control on the text selection.


 

InsertInputPassword

Overwrites a password control on the text selection.


 

InsertInputRadio

Overwrites a radio control on the text selection.


 

InsertInputReset

Overwrites a reset control on the text selection.


 

InsertInputSubmit

Overwrites a submit control on the text selection.


 

InsertInputText

Overwrites a text control on the text selection.


 

InsertMarquee

Overwrites an empty marquee on the text selection.


 

InsertOrderedList

Toggles the text selection between an ordered list and a normal format block.


 

InsertParagraph

Overwrites a line break on the text selection.


 

InsertSelectDropdown

Overwrites a drop-down selection control on the text selection.


 

InsertSelectListbox

Overwrites a list box selection control on the text selection.


 

InsertTextArea

Overwrites a multiline text input control on the text selection.


 

InsertUnorderedList

Toggles the text selection between an ordered list and a normal format block.


 

Italic

Toggles the current selection between italic and nonitalic.


 

JustifyCenter

Centers the format block in which the current selection is located.


 

JustifyFull

Not currently supported.


 

JustifyLeft

Left-justifies the format block in which the current selection is located.


 

JustifyNone

Not currently supported.


 

JustifyRight

Right-justifies the format block in which the current selection is located.


 

LiveResize

Causes the MSHTML Editor to update an element's appearance continuously during a resizing or moving operation, rather than updating only at the completion of the move or resize.


 

MultipleSelection

Allows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys.


 

Open

Not currently supported.


 

Outdent

Decreases by one increment the indentation of the format block in which the current selection is located.


 

OverWrite

Toggles the text-entry mode between insert and overwrite.


 

Paste

Overwrites the contents of the clipboard on the current selection.


 

PlayImage

Not currently supported.


 

Print

Opens the print dialog box so the user can print the current page.


 

Redo

Not currently supported.


 

Refresh

Refreshes the current document.


 

RemoveFormat

Removes the formatting tags from the current selection.


 

RemoveParaFormat

Not currently supported.


 

SaveAs

Saves the current Web page to a file.


 

SelectAll

Selects the entire document.


 

SizeToControl

Not currently supported.


 

SizeToControlHeight

Not currently supported.


 

SizeToControlWidth

Not currently supported.


 

Stop

Not currently supported.


 

StopImage

Not currently supported.


 

StrikeThrough

Not currently supported.


 

Subscript

Not currently supported.


 

Superscript

Not currently supported.


 

UnBookmark

Removes any bookmark from the current selection.


 

Underline

Toggles the current selection between underlined and not underlined.


 

Undo

Not currently supported.


 

Unlink

Removes any hyperlink from the current selection.


 

Unselect

Clears the current selection.


 

Reference from : http://msdn2.microsoft.com/en-us/library/ms533049(VS.85).aspx