Translate

Home > October 2012

October 2012

Jquery , Current Page Address , Page Name, Tag Searching

Tuesday, October 30, 2012 Category : 0

<script type="text/javascript">
        $(document).ready(function () {

            var pathname = window.location.pathname;
            var index = pathname.lastIndexOf("/");
            var filename = pathname.substr(index + 1);

            if (filename == 'Default.aspx' || filename == 'NewSalesUI.aspx' || filename == 'SalesVoid.aspx') {
                $('a[href="' + filename + '"]').attr("class", "main current");
            }
            else {
                index = 0;
                index = pathname.lastIndexOf("Setup");
                if (index > 0) {
                   
                    var elements = $('span .settings');
                    if (elements != null && elements != NaN) {
                        var p = elements.parent().parent();
                        p.attr("class", "main current");
                    }
                    return;
                }

                index = 0;
                index = pathname.lastIndexOf("Operation");
                if (index > 0) {
                    var elements = $('span .operation');
                    if (elements != null && elements != NaN) {
                        var p = elements.parent().parent();
                        p.attr("class", "main current");
                    }
                }

                index = 0;
                index = pathname.lastIndexOf("Account");
                if (index > 0) {
                    var elements = $('span .newsletter');
                    if (elements != null && elements != NaN) {
                        var p = elements.parent().parent();
                        p.attr("class", "main current");
                    }
                    return;
                }

                index = 0;
                index = pathname.lastIndexOf("Report");
                if (index > 0) {
                    var elements = $('span .reports');
                    if (elements != null && elements != NaN) {
                        var p = elements.parent().parent();
                        p.attr("class", "main current");
                    }
                    return;
                }
            }

        });
    </script>

Asp.net - The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

Category : , 0

Introduction: 

Here I will explain how to solve the problem “The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).” when running web application using asp.net. 

Description: 

I created one web application and added some of script files in header section of page like this


<head id="head2" runat="server">
<title>Lightbox Page</title>
<link href="aspdotnetsuresh.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%= ResolveUrl("~/js/LightBox.js") %>"></script>
</head>
After add script file to header section i tried to run the application during that time I got error like The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Server Error in 'ASP.Net' Application.


The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

To solve this problem we have different methods
First Method
Remove JavaScript from the header section of page and add it to body of the page and run your application it will work for you.
Second Method
Replace the code block with <%# instead of <%=
<head id="head2" runat="server">
<title>Lightbox Page</title>
<link href="aspdotnetsuresh.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%# ResolveUrl("~/js/LightBox.js") %>"></script>
</head>
After replace code block with <%# instead of <%= add following code in page load

protected void Page_Load(object sender, EventArgs e)
{
Page.Header.DataBind();    
}
After add code run your application it will work for you.

Happy Coding………

Crystal Report Parameter Pass C# , C-sharp

Thursday, October 18, 2012 Category : , 0

        ParameterField paramerterField = new ParameterField();
        ParameterFields parameterFields = new ParameterFields();
        ParameterDiscreteValue pdvReprint = new ParameterDiscreteValue();

        private void setParameter()
        {
            string rep = "";

            try
            {
                rep = Request.QueryString["Rep"].ToString();
            }
            catch (Exception ex)
            {
                rep = "";
            }
            if (rep != "")
            {
                paramerterField.ParameterFieldName = "@Reprint";
                pdvReprint.Value = rep;
                paramerterField.CurrentValues.Add(pdvReprint);
                parameterFields.Add(paramerterField);
                CrViewer.ParameterFieldInfo = parameterFields;
            }
            else
            {
                paramerterField.ParameterFieldName = "@Reprint";
                pdvReprint.Value = "";
                paramerterField.CurrentValues.Add(pdvReprint);
                parameterFields.Add(paramerterField);
                CrViewer.ParameterFieldInfo = parameterFields;
            }
        }

ASP.NET Master Page Active Menu Highlight

Wednesday, October 17, 2012 Category : 0

Use this course on you child page content place holder

<script language="javascript">
        document.getElementById("setupmenu").className = "main current";
    </script>

do not use in header contenet place holder , it will generate error.


OR

 Using Jqery in Master page

 <script type="text/javascript">
        $(document).ready(function () {
           
            var pathname = window.location.pathname;
            var index = pathname.lastIndexOf("/");
            var filename = pathname.substr(index + 1);
            $('a[href="' + filename + '"]').attr("class", "main current");

        });
    </script>

sql server string split

Sunday, October 7, 2012 Category : 0

Use a table valued function like this,

CREATE FUNCTION Splitfn(@String varchar(8000), @Delimiter char(1))     
returns @temptable TABLE (items varchar(8000))       as       begin     
    declare @idx int     
    declare @slice varchar(8000)     

    select @idx = 1     
        if len(@String)<1 or @String is null  return     

    while @idx!= 0     
    begin     
        set @idx = charindex(@Delimiter,@String)     
        if @idx!=0     
            set @slice = left(@String,@idx - 1)     
        else     
            set @slice = @String     

        if(len(@slice)>0)
            insert into @temptable(Items) values(@slice)     

        set @String = right(@String,len(@String) - @idx)     
        if len(@String) = 0 break     
    end   return    
end

and get your variable and use this function like this,

 SELECT i.items FROM dbo.Splitfn(@a,'|') AS i


===============================================================================
Optional
use this function to generate a relation data with other table



create function getTeacherDepartmentSplit()
returns @tempTeacher table (TeacherID nvarchar(50),DepartmentID nvarchar(50))
as
begin

 DECLARE @TeacherID nvarchar(50)
 DECLARE @DepartmentIDs nvarchar(50)

 declare dbCursor cursor for
 SELECT     dbo.Teacher.TeacherID, dbo.Teacher.DepartmentIDs FROM  dbo.Teacher
 open dbCursor
 FETCH NEXT FROM dbCursor INTO @TeacherID,@DepartmentIDs

 While @@FETCH_STATUS = 0
 begin
  insert into @tempTeacher (TeacherID,DepartmentID)
  SELECT @TeacherID,i.items FROM dbo.Splitfn(@DepartmentIDs,',') AS i
 
  FETCH NEXT FROM dbCursor INTO @TeacherID,@DepartmentIDs
 
 end
 close dbCursor
 return
end

 select T.TeacherID,T.DepartmentID from getTeacherDepartmentSplit() as T 

Powered by Blogger.