Wednesday, May 29, 2013

how to validate images from customer control?

public void user(object sender, ServerValidateEventArgs args)
{
if (Path.GetExtension(pp.PostedFile.FileName) == ".png" || Path.GetExtension(pp.PostedFile.FileName).ToUpper() == ".gif".ToUpper() || Path.GetExtension(pp.PostedFile.FileName).ToUpper() == ".jpg".ToUpper())
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}


<input type=file id="pp" runat="server" />

<asp:CustomValidator ID="CustomValidator1"

ControlToValidate="pp"

OnServerValidate="user" ValidationGroup="l"

Text="only Images Format!"

runat="server"/>

<asp:Button ID="btm" runat="server" ValidationGroup="l" Text="submit"

onclick="btm_Click" />

How to print partial pages?

<script type="text/javascript">

function CallPrint(strid) {

debugger;

var prtContent = document.getElementById(strid);

var productinfo = document.getElementById('divProductInfo');

var WinPrint = window.open('', '', 'letf=0,top=0,width=400,height=400,toolbar=0,scrollbars=0,status=0');

if (productinfo == null) {

WinPrint.document.write(prtContent.innerHTML);

} else {WinPrint.document.write(productinfo.innerHTML + prtContent.innerHTML);}

WinPrint.document.close();

WinPrint.focus();

WinPrint.print();

WinPrint.close();

} </script>

<input type="button" style="font-size: 13px; font-weight: bold" width="75px" value="Print copy"

id="btnPrint" runat="Server" onclick="javascript:CallPrint('divPrint')" />

<div id="divProductInfo" class="pro-price" runat="server">
//Your print material here

</div>



 

Tuesday, May 28, 2013

How to prevent back from javascript?


only code  put in the body...

<script type = "text/javascript" >
   function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
</script>

HttpRuntimeSection Property

HttpRuntimeSection.MinFreeThreads Property

Gets or sets the minimum number of threads that must be free before a request for resources in this configuration scope can be serviced.

The minimum number of free threads in the common language runtime (CLR) thread pool before a request in this configuration scope will be serviced.
The default value is 8.


==========================

HttpRuntimeSection.MaxQueryStringLength Property




 You can set this value in a configuration file by setting the maxQueryStringLength attribute of the httpRuntime element

Extremely small values can make a Web site unusable.

The maximum length of the query string, in number of characters.
The default is 2048.

The value of the MaxQueryStringLength property can be any integer, zero or larger. If the length of a query string exceeds the size limit, ASP.NET returns an HTTP 400 (Bad Request) status code.

There is also an IIS setting that controls query string length


HttpRuntimeSection.MaxUrlLength Property



Gets or sets the maximum possible length, in number of characters, of the URL in an HTTP request.
The length of the URL, in number of characters. The default is 260.

You can set this value in a configuration file by setting the MaxUrlLength attribute of the httpRuntime
 
 
 


 

Wednesday, May 15, 2013

Calender

<asp:TextBox ID="txtFrom" runat="server" CssClass="textbox4" Width="150px"></asp:TextBox>

<rjs:PopCalendar ID="cal1" runat="server" BackColor="Yellow" BorderColor="Black"

BorderStyle="Solid" BorderWidth="1px" Buttons="[<][m][y] [>]" Control="txtFrom"

ControlFocusOnError="True" Culture="en-US English (United States)" Fade="0.5"

Format="dd mmm yyyy" From-Message="From" InvalidDateMessage="Invalid Date" Move="True"

RequiredDate="false" RequiredDateMessage="Date is required" Separator="-" Shadow="True"

ShowWeekend="True" TextMessage="" To-Control="txtTo" To-Message="From Date Should be less than To Date" />



<asp:TextBox ID="txtTo" runat="server" CssClass="textbox4" Width="150px"></asp:TextBox>
<rjs:PopCalendar ID="Cal2" runat="server" BackColor="Yellow" BorderColor="Black"
BorderStyle="Solid" BorderWidth="1px" Buttons="[<][m][y] [>]" Control="txtTo"
ControlFocusOnError="True" From-Control="txtFrom" Culture="en-US English (United States)" Fade="0.5"
Format="dd mmm yyyy" From-Message="From" InvalidDateMessage="Invalid Date" Move="True"
RequiredDate="false" RequiredDateMessage="Date is required" Separator="-" Shadow="True"
ShowWeekend="True" TextMessage="" To-Control="txtTo" To-Message="To Date Should be greater than From Date" />

Friday, May 3, 2013

Difference between ViewState and ControlState?

ViewState and ControlState are both mechanisms used in ASP.NET for maintaining data across postbacks. Both are preserved in a hidden field known as _VIEWSTATE.
The differences are:
1)ViewState can be disabled while the Control State cannot be disabled.
2)ViewState is implemented by using EnableViewState property of a control to true.
Control State works even when EnableViewState is off.

To use Control State (for example in a custom control) we have to override OnInit method,call RegisterRequiresControlState method in OnInit method and then override the SaveControlState and LoadControlState methods.

Custom Controls code is written in classes derived from WebControl.

3)Control State is used for small data only.
eg: maintain clicked page number in a GridView even when EnableViewState is off

How to protect the view state from tampering?

We can protect the view state from tampering by encrypting the contents of the view state as well as we need to make the enableviewstatemac = true in the page level which will do the complete encryption

By Default ViewState Data is encrypted so No need to extra encryption