Thursday, May 6, 2010

How to write conditional statement without using if key word in c# or How to use ternary operator?

The below code is a replacement of if keyword in c#  which you can accomplish by using the the conditional operator (?:)

condition ? first_expression : second_expression;

Ifyou excecute the below code it will print the value 20 .

int i = (2 > 3) ? 10 : 20;
Response.Write(i.ToString());

If we split the above code then (2 > 3) is considered as the condition, the result before : will be returned if the condition is true and the result after the : will be returned if it is false.

More Information can be out in the link below
http://msdn.microsoft.com/en-us/library/ty67wk28(VS.80).aspx

Wednesday, May 5, 2010

Have you used a condition like below in c#?


This above code will print false.
This staement can be further modified for function to return a boolen depending on the calculated values like below

The above function will also return return false if called like below.

Tuesday, May 4, 2010

How to hide a control using javascript in page_load or window.onload event?

The below code will help you to hide a control in page_laod event of javascipt.

How to get the selected text of a microsoft ajax combobox using javascript ?

The belwo example whill show you  how to get the selected text of a ajax combobox.

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


When I sued the above code in my aspx page I was getting the eroor as .

“The Controls collection cannot be modified because the control contains code blocks (i.e. ).”
This error can be solved by just replacing the code as below .

Other wise pass the control’s clientId as a parameter to the javascript function from thes server side code.

Replace your code as below will solve the issue.

You can also find other solution in the bleow link.
http://www.west-wind.com/weblog/posts/5758.aspx

Saturday, May 1, 2010

How to Create stored procedure or View in SQL 2005 with encryption?

You can encrypt a view or an SP in SQL server 2005 by using the key work "with encryption" while creating the SP or View.


Please look into the example below.

create procedure MySp with encryption
as
begin
select * from EmailList
end

Once you created an sp or view with the above option added then it cannot be viewed by any users.if the suer tryes to view the above sp orview then it SQL server will show a message like . The text for object 'MySp' is encrypted.

One note of caution. Save the original text of the stored procedure before encrypting it, as there is no straightforward way to decode the encrypted text. One hack is to attach a debugger to the server process and retrieve the decrypted procedure from memory at runtime


Please look to the below link for how to decrypt the encrypted Sp or view.

http://www.sql-shield.com/decrypt-stored-procedure.html