Translate

Home > July 2012

July 2012

ASP.NET JavaScript to C# Execute

Monday, July 30, 2012 Category : 0

Java script to C# parameter pass and run function

In ASPX FILE
 <script type="text/javascript">
                        var myResult  = 'PurchaseID';
                     __doPostBack('PaidHandler',myResult);
 </script>


IN C#

protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                string target = Request.Form["__EVENTTARGET"];
                string value = Request.Form["__EVENTARGUMENT"];
              
                if (!string.IsNullOrEmpty(target) && target.Equals("PaidHandler"))
                {
                    HiddenFieldTempPayID.Value = value;
                 }
            }
        }


Here doPostBack take two parameter first is target and second is if you want to pass value

ASP.NET GridView row click open a new window and update value of parent window

Tuesday, July 17, 2012 Category : 0

IN PARENT PAGE

IN C# CODE 
protected void gvIndent_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes[
                "onmouseover"] = "this.style.cursor='hand';this.style.textDecoration='underline';";

                e.Row.Attributes[
                "onmouseout"] = "this.style.textDecoration='none';";

                e.Row.Attributes[
                "onclick"] = ClientScript.GetPostBackClientHyperlink(this.gvIndent, "Select$" + e.Row.RowIndex);

                e.Row.Attributes.Add(
                "onclick", "openPopUp('" + DataBinder.Eval(e.Row.DataItem, "indent_no") + "');");
            }
        }

In Page Load Event 
 string updateValuesScript = @"function updateValues(popupValues)
                    {
                         document.getElementById('ctl00_PlaceHolderLeft_txtIndentNo').value = popupValues[0];
                    }";

            this.ClientScript.RegisterStartupScript(Page.GetType(), "UpdateValues", updateValuesScript.ToString(), true);
 

IN ASPX
    <script type="text/javascript">
        function openPopUp(strUser) {
           
            var popUrl = 'indent_status.aspx?Value='+strUser;
          
            var name = 'popUp';
            var appearence = 'dependent=yes,menubar=no,resizable=yes,' +
                                          'status=no,toolbar=no,titlebar=no,' +
                                          'left=100,top=80';
            var openWindow = window.open(popUrl, name, appearence);
            openWindow.focus();
        }
    </script>


IN CHILD ASPX PAGE

protected void Page_Load(object sender, EventArgs e)
        {

            string updateParentScript = @"function updateParentWindow(ides)
                              {                                                                              
                               var ide=ides;
                               var arrayValues= new Array(ide);
                               window.opener.updateValues(arrayValues);      
                               window.close();
                              }";
            //document.getElementById('lblID.ClientID').value;
            this.ClientScript.RegisterStartupScript(this.GetType(), "UpdateParentWindow", updateParentScript, true);



btnClose.Attributes.Add("onclick", "updateParentWindow(parameter value)");          
        }

Converting Image To Byte Array

Saturday, July 14, 2012 Category : 0

#region Converting Image To Byte Array


    private void byteArrayToImage(byte[] byteArrayIn)
    {
        System.Drawing.Image newImage;

        string strFileName = GetTempFolderName() + "yourfilename.gif";
        if (byteArrayIn != null)
        {
            using (MemoryStream stream = new MemoryStream(byteArrayIn))
            {
                newImage = System.Drawing.Image.FromStream(stream);

                newImage.Save(strFileName);

                img.Attributes.Add("src", strFileName);
            }

            lblMessage.Text = "The image conversion was successful.";
        }
        else
        {
            Response.Write("No image data found!");
        }
    }

    #endregion

Image not showing on Crystal Report

Category : 0

Use This.
 
<httpHandlers> 
     <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers> 

OR

<httpHandlers> 
     <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers> 

Cookie Error

Tuesday, July 10, 2012 Category : 0

System.Web.HttpException: Request is not available in this context

use HttpContext.Current.Response instead of Response.Cookie[""] = ....

Modify Master Page Conrol

Category : 0

use this code in your child page
<%@ MasterType VirtualPath="~/MasterSite.Master" %>


Add this code in your Master Page

public void FeatureVisibility(bool value)
        {
            PanelFeaturePro.Visible = value;
        }


Now in Child Page
 use :       Master.FeatureVisibility(false);

Select Random Record From DataBase (SQL)

Monday, July 9, 2012 Category : 0

DECLARE @Random INT;
DECLARE @Upper INT;
DECLARE @Lower INT

---- This will create a random number between 1 and 999
SET @Lower = 0 ---- The lowest random number
SET @Upper = (SELECT     COUNT(ItemID) AS Expr1 FROM dbo.basicSetupItem) ---- The highest random number
SELECT @Random = ROUND(((@Upper - @Lower -1) * RAND() + @Lower), 0)
--SELECT @Random;

WITH paging AS
(
  SELECT
  ROW_NUMBER() OVER (order by ItemID) AS rowid, *
  FROM vBasicSetupItem
)
select *
from paging
where rowid = @Random

Use Limit in SQL 2005 , SQL 2008

Sunday, July 8, 2012 Category : 0

declare @FROM int
declare @TO int
--set @offset = 2;
--set @limit = 5;
--declare @idxini int
--declare @idxfim int
--select @idxfim = @offset * @limit -- 2 * 5 = 10
--select @idxini = @idxfim - (@limit-1); -- 10 - (5-1) = 7
WITH paging AS
(
  SELECT
  ROW_NUMBER() OVER (order by ItemID) AS rowid, *
  FROM vBasicSetupItem
)
select *
from paging
where rowid between @FROM and @TO
order by rowid;

ASP.NET Custome Error Page

Friday, July 6, 2012 Category : 0

<system.web>
    <customErrors mode="On" defaultRedirect="UI/ErrorPage.aspx" redirectMode="ResponseRewrite"/>
</system.web>

protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                HttpContext ctx = HttpContext.Current;

                Exception exception = ctx.Server.GetLastError();

                string errorInfo =
                   "<br>Offending URL: " + ctx.Request.Url.ToString() +
                   "<br>Source: " + exception.Source +
                   "<br> <b> Message: " + exception.Message + "</b>" +
                   "<br>Stack trace: " + exception.StackTrace;
                lblMsg.Text = errorInfo;
            }
            catch (Exception ex)
            {
               
            }
        }

Stored Procedure Check wheather a row is inserted or not

Thursday, July 5, 2012 Category : 0

DECLARE @SQL nvarchar(2000)

SET @SQL = 'INSERT INTO ----------------------'

Exec sp_executesql @SQL

    IF @@ROWCOUNT = 1
    BEGIN
        SET @SQL = 'UPDATE [BuyCentral] SET [BalQty]=[BalQty]-' + @SQty + ' , [SQty]=[SQty]+'     +     @SQty + ' Where [ItemID]=' +@ItemID + ''

        Exec sp_executesql @SQL
    END




[Here @@ROWCOUNT a builtin variable which store if a insert or update or delete statement execute successfully]

Barcode Print Using CURSOR , For Loop and store procedure

Tuesday, July 3, 2012 Category : 0

CREATE PROCEDURE [dbo].[sp_BarcodePrint]
    -- Add the parameters for the stored procedure here
 @ChallanNo VARCHAR(256) -- filename for backup 

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @QTY int
    DECLARE @Barcode VARCHAR(256)

CREATE TABLE #temp (
ChalanNo VARCHAR(256),
QTY int,
ProductName VARCHAR(256),
BrandName VARCHAR(256),
LineName VARCHAR(256),
ModelName VARCHAR(256),
ColorName VARCHAR(256),
SizeName VARCHAR(256),
Barcode VARCHAR(256),
CostPrice VARCHAR(256),
SalesPrice VARCHAR(256),
VAT decimal,
Serial VARCHAR(256) )


DECLARE db_cursor CURSOR FOR 
    SELECT        RChallan.QTY,basicSetupItem.Barcode
    FROM            RChallan INNER JOIN
                             basicSetupItem ON RChallan.ItemID = basicSetupItem.ItemID
    WHERE        (RChallan.ChalanNo = @ChallanNo)

DECLARE @Flag INT

    OPEN db_cursor 
    FETCH NEXT FROM db_cursor INTO @QTY,@Barcode
   
   
    WHILE @@FETCH_STATUS = 0
    BEGIN
        SET @Flag = 1
        WHILE (@QTY >= @Flag) 
        BEGIN 
                 
                  INSERT INTO #temp (ChalanNo,QTY,ProductName,BrandName,LineName,ModelName,ColorName,SizeName,Barcode,CostPrice,SalesPrice,VAT,Serial)
                 
                   SELECT        RChallan.ChalanNo, RChallan.QTY, vBasicSetupItem.ProductName, vBasicSetupItem.BrandName, vBasicSetupItem.LineName, vBasicSetupItem.ModelName,
                             vBasicSetupItem.ColorName, vBasicSetupItem.SizeName, vBasicSetupItem.Barcode, vBasicSetupItem.CostPrice, vBasicSetupItem.SalesPrice,
                             vBasicSetupItem.VAT,@Flag
                    FROM            RChallan INNER JOIN
                             vBasicSetupItem ON RChallan.ItemID = vBasicSetupItem.ItemID
                    WHERE        (RChallan.ChalanNo = @ChallanNo) AND (vBasicSetupItem.Barcode =@Barcode)
                   
                    SET @Flag = @Flag + 1
        END
           FETCH NEXT FROM db_cursor INTO @QTY,@Barcode 
    END 

CLOSE db_cursor 
DEALLOCATE db_cursor

select * from #temp

drop table #temp

END

Powered by Blogger.