, , , , , , , ,

How to pass server values to Javascript using Eval()

In my application I have a target to show message if user does not have permission to navigate to another page. I can do this by using server code but it will make a round trip to server and make a bad user experience so, I decided to use java script.

Following is the function of Java Script

<script language="javascript" type="text/javascript">
function func_Message(obj)
{
if (parseFloat(obj)>0)
{
return true;
}
else
{
alert("Please assign a value before viewing the details");
return false;
}
}
</script>


And following is the code of Link Button from where I am passing value to Java Script Function

<asp:LinkButton ID="lnk_Details" runat="server" Text="Details" CommandArgument='<%# Eval("festi_id") +"~" + Eval("user_id") %>'
CommandName="ViewDetails" OnClientClick='<%# "return func_Message(" + Eval("user_id") + ");"%>'></asp:LinkButton>
Share:
Read More
, , , , , ,

Disbale JIT in .net / Application level Exception handling in .net

downloadDownload Code Example

I was developing windows application for a well known company of World. This application was in C#.net 2005.

As per requirement I have to show user defined message whenever an Exception occurs in the application.

The answer is very simply write a simple Try{},Catch{} statement to handle exception.
Suppose I have a code of 1000 line unwanted code and error handling creates extra thread while executing the application. I had search on the internet and found a solution to disable the JIT debugger. It works but still it is showing the application information related to functions etc. used in the code.

Now, a major issue had risen from client, i.e. he don’t want to show JIT information to user he wants to show his own message whenever any Exception occurs.

Offf…. Now that’s the task to which needs to done. I cannot use Try{},Catch{} as this decrease the application performance. Finally I came to the solution. I had wired an event with application to handle application error. Here is the code.

static void Main()
{
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}

static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
MessageBox.Show("Illegal operation or command.", "Illegal operation", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
Now, run your code and click on the button, it will show are exception while you are running the application within the .net environment.

Now browser the directory and Run you EXE file and again click in the button, now it will not show exception rather show the message which you wants to display.

This is a good approach it will show exception and source in while debugging and show and user defined message in EXE



Share:
Read More
, , , , , ,

How to alter Auto Increment field in Sql server

It is not possible to remove Auto Increment field using Alter command in Sql Server.

What we can use is SET IDENTITY_INSERT

Take this following example this creates a table with auto increment field and still insert data to the same.

Generally if you try to insert the data into auto increment field it will through error.

But if we use SET IDENTITY_INSERT <Table Name>ON it will allow you to insert data into auto increment field.

Note: Make sure after completing this operation you set the value to SET IDENTITY_INSERT <Table Name>OFF

--Create table and its columns
CREATE TABLE [test].[Table_1] (
[Id][int] NOT NULL IDENTITY (1, 1),
[Name][nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL);
GO

ALTER TABLE [test].[Table_1] ADD CONSTRAINT [PK_Table_1] PRIMARY KEY CLUSTERED ([Id])
GO

SET IDENTITY_INSERT [test].[Table_1] ON
GO
INSERT INTO [test].[Table_1] ([Id], [Name])
VALUES (1, 'Narender')

GO
INSERT INTO [test].[Table_1] ([Id], [Name])
VALUES (3, 'Rohit')

GO
INSERT INTO [test].[Table_1] ([Id], [Name])
VALUES (4, 'Mohit')

GO
INSERT INTO [test].[Table_1] ([Id], [Name])
VALUES (5, 'Shipra')

GO
SET IDENTITY_INSERT [test].[Table_1] OFF
GO

The above example simply insert the data into table without incrementing the values and keep the error shut..

If you try to insert any data after SET IDENTITY_INSERT [test].[Table_1] OFF it will through an error.
Share:
Read More