Total Pageviews

Showing posts with label Java Script. Show all posts
Showing posts with label Java Script. Show all posts

Thursday, December 17, 2009

How to dynamically adjust an iframe’s height?

I was looking to display content of the other aspx page inside iframe but i wasnt able to adjust the height of the iframe. so try out this solution to resolve it.

Insert iframe on page
   <iframe scrolling='no' frameborder='0' id='frmid' src=’getad.aspx'
            onload='javascript:resizeIframe(this);'>
   </iframe>


Use this javascript to resize iframe based on the height & width of child page




<script language="javascript" type="text/javascript">
 function resizeIframe(obj)
 {
   obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
   obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
 }
 </script>


What does this code do? When the body of the parent frame loads, it looks up the document element “childframe” which corresponds to the iframe. Then the page calls a function resizeFrame(). The function sets the height of the frame to be the scrollHeight, which effectively removes the scrollbar.

happy programming!

Thursday, September 3, 2009

Open New Tab/Window (Response.Redirect open in new web page)

Hello Friends, Here I am going to explain how to open new tab/window on Button click using asp.net. A week ago, i have to implement that code. I have option to use javascipt windows.open to open new tab. But I have to insert or update some database entry. Yeah i know that there is another way to use client script in code behind to achieve this. But in its simplest form, following code open new tab/window. <asp:Button ID=”btnNewEntry” runat=”Server” CssClass=”button” Text=”New Entry” OnClick=”btnNewEntry_Click” OnClientClick=”aspnetForm.target =’_blank’;”/> <%-- aspnetForm.target =’_blank’ will add handler to open new tab--%> protected void btnNewEntry_Click(object sender, EventArgs e) { Response.Redirect(”New.aspx”); } OR Response.Write( "<script> window.open( 'pageName.aspx' ); </script>"); Response.End(); // Here we can write javascript code to open new tab -------------------- Happy programming.

Monday, August 3, 2009

Call WebService using Javascript

TO call any webservice in javascript use following code... <script> function CallWebService() { PrintService.PrintCode(OnSuccess); // here i m using PrintServer as webservice to print purpose } function OnSuccess(result) { document.getElementId('result').value=result; } </script> ------------------------------------------------------------ Following is my web service public class PrintService : System.Web.Services.WebService { public static string strMyPrintCode = string.Empty; public static string strOfferCode = string.Empty; public PrintService() { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string PrintCode() { string strCode = GetRandomUniqueAlphaNumericCode(8, false); strMyPrintCode = strCode; return strCode; // return unique and random alphanumeric code } } --------------------------- Notice where i m calling webservice...i m passing one argument when calling webservice method named PrintCode, when call to webservice succeeded, Javascript function OnSuccess will be call. You can also create one more function named OnFailure to notify failure of webservice

Friday, June 26, 2009

How to detect browser using JavaScript

var isIE = false; var isFF = false; var isOP = false; var isSafari = false; function DetectBrowser() { var val = navigator.userAgent.toLowerCase(); if(val.indexOf("firefox") > -1) { isFF = true; } else if(val.indexOf("opera") > -1) { isOP = true; } else if(val.indexOf("msie") > -1) { isIE = true; } else if(val.indexOf("safari") > -1) { isIE = true; } }

Saturday, April 25, 2009

Count wordin textbox

TO find the enter text in text box use the following function in javascript Use onkeydown and onkeyup events to call this function

function fnCheckCharacters()    
{         
    var txtcheck=document.getElementById('<%= txtQ11.ClientID %>'); 
    //here txtQ11 is my textbox id       
    var lblLeftCount = document.getElementById('<%=lblCharCounter.ClientID %>'); 
    //lblCharCounter is a labed on which i printed the remaing word                
    var len=300;       
    var Lchar = 0;           
    if (txtcheck.value.length > 300)       
    {           
        alert ("You can enter atmost 300 characters");           
        txtcheck.value=txtcheck.value.substring(0,300);       
    }
    else       
    {           
        lblLeftCount.innerHTML=txtcheck.value.length;       
    }          
}   

in this function, i fixed the length of textbox to 300. user can enter only 300 char.after inserting each char, reaming one is displayed on label.


thnx

Thursday, April 16, 2009

Browser detection javascript

heres a javascript for the detection of the web browser used by the end user:


if(navigator.userAgent.indexOf(’Safari’)!=-1)
{ 
    alert(’safari’); 
} 
else if(navigator.userAgent.indexOf(’Gecko’)!=-1) 
{ 
    alert(’mozilla’); 
}  
else 
{ 
    if(navigator.userAgent.indexOf(’MSIE 7.0′)!=-1) 
    { 
        alert(’ie 7′); 
    } 
    else 
    { 
        alert(’ie 6′); 
    } 
}         
       

now i’ll explain you the above script: navigator.userAgent returns the full description of the user agent or web browser used by the client or end user. indexOf() function returns the character position [...]

Blog Archive

Ideal SQL Query For Handling Error & Transcation in MS SQL

BEGIN TRY BEGIN TRAN --put queries here COMMIT; END TRY BEGIN CATCH IF @@TRANCOUNT>0 BEGIN SELECT @@ERROR,ERRO...