- string sPagePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
- System.IO.FileInfo oFileInfo = new System.IO.FileInfo(sPagePath);
- string sPageName = oInfo.Name;
Wednesday, 2 May 2012
Get Page Name in asp.net
Controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-ie
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.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Cause
While working with one if my applications where I was adding some controls to the head section of my page. Reason, I used the following JavaScript which had the <% %> tags to get the ClientID of a control
<head runat="server">
<title>Untitled Page</title>
<script type = "text/javascript">
function GetValue()
{
var txt = document.getElementById("<%=TextBox1.ClientID%>");
alert(txt.value);
}
</script>
</head>
As you can see above I have used ASP.Net Server tags to get the ClientID of textbox hence I cannot add controls dynamically to the head section
Solution
Remove the part which has server tags and place it somewhere else if you want to add dynamic controls from code behind
I removed my JavaScript from the head section of page and added it to the body of the page and got it working
Wednesday, 25 April 2012
Check Database Collation
Syntax:
DATABASEPROPERTYEX(Database, Property);
SELECT DATABASEPROPERTYEX('dbname', 'Collation') as
Collation ;
Result:
Collation
Latin1_General_CI_AI
To Change Collate
ALTER DATABASE dabasename COLLATE Collatename ;
1)ALTER DATABASE Test COLLATE French_CI_AS ;
0r
2)Right Click database, choose properties -> options
select Collation
Sys.WebForms.PageRequestManagerTimeoutException
when I tried to export an image, i got
this error: "Sys.WebForms.PageRequestManagerTimeoutException
The server request timed out"
from the Ajax Extension framework. Its occurred
because the export operation was relatively long (something like 2 minutes) and
the Ajax Extension Callback framework had a timeout.
How to solve this problem?
To solve this problem we can increase
the timeout. You can change the timeout time by adding a new property to the script
manager control. This property is called AsyncPostBackTimeOut and it can help
us to define the number of seconds before the request will throw a request
timeout exception.
For example if you want that the
timeout will take maximum 10 minutes your code should be look like this:
<asp:ScriptManager
ID="ScriptManager1" runat="server" AsyncPostBackTimeOut="600"
></asp:ScriptManager>
Sunday, 22 April 2012
Capitalise the first letter of each word
create function ProperCase(@Text
as varchar(8000))
returns varchar(8000)
as
begin
declare
@Reset bit;
declare @Ret
varchar(8000);
declare @i int;
declare @c char(1);
select
@Reset = 1, @i=1, @Ret = '';
while (@i <= len(@Text))
select @c= substring(@Text,@i,1),
@Ret =
@Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
@Reset =
case when @c like '[a-zA-Z]' then 0 else 1 end,
@i =
@i +1
return @Ret
end
Result
select dbo.ProperCase('test’)
Test
Get column names and datatypes in particular table using SQL Server
SELECT
column_name as ColumnName,
data_type as DataType,
character_maximum_length as MaximumLength
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name
= 'Employee_Details'
Result:
ColumnName DataType MaximumLength
id bigint NULL
username varchar 50
firstname varchar 50
lastname varchar 50
city varchar 50
designation varchar 50
Salary decimal NULL
Subscribe to:
Posts (Atom)