Sunday 29 March 2015

How to open a web page in new window in ASP.NET?


Sometimes you may need to open a web page in new window when user clicks at some link or on some action. In those cases you can use the following in code behind:


It will open webpage.aspx in new window having height=700 and width=1024 and with scrollbars. If you don't want scrollbars you can skip the statement(scrollbars=1). You can specify your own height and width. Here mywindow is name given to the window.

Friday 27 March 2015

Program to print rhombus in C


#include<stdio.h>
int main( )
{

            int n = 5, inc = 1, i, j,k;     //n is number of stars to be printed in middle row
            for (i = 1; i <= n && i >= 1; i = i + inc)
            {

                for (j = 1; j <= n - i; j++)
                   printf(" ");     //prints a space

                for (k = 1; k <= i;k++ )
                    printf("* ");   //prints star and space

                printf("\n");   //prints a new line

                if (i == n)
                    inc = -1;
            }

             return 0;
}

Program to find missing elements in an array in C


#include<stdio.h>
int main( )
{

        int a[ ]={2,4,7};    //array to be tested
        int n=sizeof(a)/sizeof(a[0]);    //length of array
        int i,j,match;

        for(i=1;i<=9;i++)    //here we are testing the missing elements from 1 to 9
        {
                 match=0;
                 for(j=0; j<n | | (match==0);j++)    //it will loop until the array ends or we found a match
                           if(a[j] = = i)
                                  match=1;
   
                  if(match==0)   //no match found
                         printf("%d  ",i);
         }
     
          return 0;
}

How to find length of an array in C or C++?


To find the length of an array in C or C++, you can use the following:

int n=sizeof(a)/sizeof(a[0]);

Here, a is array

Thursday 26 March 2015

How to disable copying of text from a webpage?


To disable copying of text from a web page write the following script in HEAD section of web page:




Monday 23 March 2015

How to show a alert box in ASP.NET by code behind?


Sometimes, you may need to show a message after a successful insertion of record or after some action...

So you can use the following code to show a alert box in ASP.NET:

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);


This will show an alert box with the message: Record Inserted Successfully

or you can also use the following:


ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Insert is successfull')", true);

STQA Assignment 2 solved


Click here to download it

Questions:

Short questions :
Q1: What is stress testing?
Q2: What is Cyclomatic complexity?
Q3: Define Object Oriented Testing
Q4: What is regression testing? When it is done?
Q5: How loop testing is different from the path testing?
Q6: What is client server environment?
Q7: What is graph based testing?
Q8: How security testing is useful in real applications?
Q9: What are main characteristics of real time system?
Q10: What are the benefits of data flow testing?

Long Questions:
Q1: Design test case for: ERP, Traffic controller and university management system?
Q2: Assuming a real time system of your choice, discuss the concepts. Analysis and design factors of same, elaborate
Q3: How testing in multiplatform environment is performed?
Q4: Explain graph based testing in detail
Q5: Differentiate between Equivalence partitioning and boundary value analysis


Tuesday 17 March 2015

Artificial Intelligence Assignment 2 -Solved


Click here to download it

Short Questions
Q1: Mention the types of knowledge 
Q2: What is monotonic reasoning?
Q3: When A* is optimal?
Q4: What are the various types of informed search?
Q5: Name any two AI languages
Q6: What are semantic nets?
Q7: What is non-monotonic reasoning?
Q8: What is FOPL?
Q9: What is A* Search?
Q10: Give examples for heuristic search

Long Questions
Q1: Define heuristic search. Discuss benefits and short coming.
Q2: Discuss the following heuristic search techniques. Explain the algorithm with the help of example.
Best First Search 
A* Algorithm
Q3: Explain non-monotonic reasoning and discuss various logic related to it.
Q4: Explain the difference between forward and backward reasoning and under what conditions each would be best to use for given set of problems.
Q5: Write A* algorithm and explain how it is used to find minimal cost path

Sunday 8 March 2015

How to get value of any server control in javascript?

To get value of any server control (for example, to get the Text of Textbox, SelectedValue of DropDownList etc) follow these steps

  • Find the ID of server control: To get ID of any server control select it and goto Properties(by pressing F4 or right click it & select Properties).

Here, I have selected a Textbox whose ID is: txtText

  • Write function: Now you can write the following javascript function(in head section or body section) to get Text in txtText:
 <Script type="text/javascript">
        function getValue() {
            var value= document.getElementById("<%= txtText.ClientID%>").value;
                //Display the value
                alert("Text in txtText is: "+value.toString());
        }
</Script>

By this way you can get value of any server control and can make your own validations, as you can check whether a value is null or not

Sunday 1 March 2015

How to produce hash password or how to prevent SQL Injection?


In your website, you may have a login page which asks things like User id and password. You have to type correct User id and password to get access. But these User id and password is stored somewhere in database in simple text format, which is prone to SQL Injection i.e. by typing some string in place of password, one may get access without using correct password. One solution to this is that always store your passwords in Encrypted or Hashed form. So here is the procedure which tells you, how to produce hash password in ASP.NET:


Step 1
Add namespace:

Using System.Web.Security;

Step 2
On Sign Up or Registration page, you may have a textbox for password say txtPassword, Now use the following statement to generate the hashed password from password typed in txtPassword:

FormsAuthentication.HashPasswordForStoringInConfigFile(string password, string passwordFormat);

Summary:
        // Produces a hash password suitable for storing in a configuration file based
        // on the specified password and hash algorithm.
        //
        // Parameters:
        // password:
        //  The password to hash.
        //
        // passwordFormat:
        // The hash algorithm to use. passwordFormat is a String that represents one
        // of the System.Web.Configuration.FormsAuthPasswordFormat enumeration values.
        //
        // Returns:
        // The hashed password.
        //
        // Exceptions:
        // System.ArgumentNullException:
        // password is null-or-passwordFormat is null.
        //
        // System.ArgumentException:
        //  passwordFormat is not a valid System.Web.Configuration.FormsAuthPasswordFormat
        //  value.


There are basically two passwordFormat used:
  • MD5
  • SHA1
So you can write any one of these statements:

string pass=FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword"MD5");
string pass=FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword"SHA1");

Now you can use variable pass to save the encrypted password to database.


Step 3

Now at  your Login page you may again have field for password say txtPassword. Now again use these statements:
string pass=FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword"MD5");
string pass=FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword"SHA1");

Now compare this encrypted password against the password stored in database. If both are matched then the login is successful otherwise not.