Featured Posts

Add and Remove ROWS in table using JQuery Sounds hard, but very simple. Say I have a table on a page and a button to add rows to that table. On that button, I have added an ONCLICK to go to the function below. Below, I gave my table a CLASS name because .Net screws up the ID -- and I am able to call that when the button is clicked. Here...

Read more

Create Custom Object In Javascript!  very cool.Create Custom Object In Javascript! very cool. You can define your own objects in Javascript that will hold properties and perform calculations. Additionally, as if that is not cool enough (dang I love Javascript), you can also define methods/functions that are attached to those objects (see below). AND additionally, as if THAT is still not...

Read more

The Panda Game... Full Javascript Panda game I created (i cant for the life of me remember why I chose a PANDA -- but whatever) ... http://toddvance.com/games/panda/ Check it out, it also includes a php login and high score feature. Cool.

Read more

Add JQuery, Javascript, CSS to ASPx User Controls parentAdd JQuery, Javascript, CSS to ASPx User Controls parent This is my preferred method. (Microsoft has controls such as ScriptManager and ScriptManagerProxy but like nearly everything they do, I believe its overkill) To me, this is the simplest method. The Problem: You want to convert or to create a user control that has scripts and/or css. Solution:...

Read more

Get parent div ID with JQuery $(this).parent().attr("id");

Read more

Cannot open database “” requested by the login. The login failed. Login failed for user ‘IIS APPPOOL\DefaultAppPool’.

Category : C#, VB.Net

Cannot open database “” requested by the login. The login failed.
Login failed for user ‘IIS APPPOOL\DefaultAppPool’.

I got this error when I added an app onto IIS 7 and was trying to hit my local Database. Here is the fix:

1) In IIS7 – Click ‘Application Pools’ (left side)


2) On Top Right – Click ‘Set Application Pool defaults’


3) Finally, set ‘Process Model > Identity’ to ‘Local System’

Trying to get the divs within a div by class name? jquery

Category : JQuery/JScript

$('#DIVID > div.CLASSNAME').each(function() {
           numOfColumns++;
                });

This asks for all divs within your holding div that have a certain class name. ** THE ‘ATGT’ after DIVID is a Greater Than sign**

How to tell if a div is visible / hidden using JQuery

Category : JQuery/JScript

You have a DIV and want to check if it is visible

Use the is() function passing “:visible” :

if( $('#myDiv').is(':visible') ) {}

Hidden

This is the same as checking if an element is visible but uses :hidden instead and the logic is the reverse:

if( $('#myDiv').is(':hidden') ) {}


Elements will return TRUE to the Hidden check even if they are not but take up no space!

Make the IS NOT check to combat this.

if( !$('#myDiv').is(':visible') {}
}

You can use the visible parameter to loop through all visible divs

$("#mydiv div:visible").each( function() {}

JQUERY Select a Hidden input within a Div

Category : JQuery/JScript

Had a div with a hidden input holding a value, wanted to get it… wanted a good way to select it… here is what I found.

$('input:hidden:first','#mydiv'); // get first one using first
$('input:hidden:last','#mydiv'); // get last one using last
$('input:hidden','#mydiv').eq(0); // get first one using eq
$('input:hidden','#mydiv').eq(1); // get second one using eq
$('input:hidden','#mydiv').eq(2); // get third one using eq
$('input:hidden:eq(0)','#mydiv'); // get first one using eq in selector

The options are:
  • first - get the first matched element in the collection.
  • last - get the last matched element in the collection.
  • eq(N) - get the Nth matched element, 0 based.
  • :eq(N) - get the Nth matched element, 0 based, inside the selector string.
However, using Hidden this way could also give you elements within your div that are NOT VISIBLE -- you could also use this;
$('input[type=hidden]', '#mydiv').eq(0);

Worked well for me, thanks StackOverflow!

How to get the parameters from your Stored Procedures in code behind.

Category : ADO / SQL, ASP.Net, C#

THE KEY LINE BELOW IS : SqlCommandBuilder.DeriveParameters(cmd);

SqlConnection c = new SqlConnection(TextboxConnString.Text);
 
//NAME OF STORED PROC
string sql = DropdownStoredProcs.Value.ToString();
 
SqlCommand cmd = new SqlCommand(sql, c);
cmd.CommandType = CommandType.StoredProcedure;
 
c.Open();
SqlCommandBuilder.DeriveParameters(cmd);
foreach (SqlParameter param in cmd.Parameters)
{
     if ((param.Direction == ParameterDirection.Input) || (param.Direction == ParameterDirection.InputOutput))
     {
         //Notice that I can get the Name of the parameter as well as it's DBType...
         string paramDescription = param.ParameterName + " | " + param.SqlDbType.ToString();
         DropdownSPParameters.Items.Add(paramDescription, param.ParameterName);
     }
}
c.Close();

How to get a list of your databases Stored Procedures from code behind.

Category : ADO / SQL, C#

This particular example fills a dropdown list with the list of Stored Procedures and takes it’s connection string from a textbox.

SqlConnection c = new SqlConnection(TextboxConnString.Text);
 
c.Open();
 
string sql = "SELECT name AS spname FROM sysobjects WHERE (xtype = 'p') ORDER BY name";
SqlCommand cmd = new SqlCommand(sql, c);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dtStoredProcs = new DataTable();
adapter.Fill(dtStoredProcs);
 
if (dtStoredProcs.Rows.Count > 0)
  {
       DropdownStoredProcs.Items.Clear();
 
        foreach (DataRow dr in dtStoredProcs.Rows)
                      DropdownStoredProcs.Items.Add(dr["spname"].ToString(), dr["spname"]);
   }
 
c.Close();

Javascript Is Numeric? Use parseInt() to test!

Category : JQuery/JScript

You can use JavaScript’s built-in parseInt() function to easily test for a numeric value:

if (myTextboxValue != parseInt(myTextboxValue))
alert(myTextboxValue + ' is not a whole number');

parseFloat will also allow you to get test if the data is a number (including floats)

Adding multiple controls programattically. C#

Category : Uncategorized

It is easy to add one new control to your page but after that you may have troubles.  Here is one option that uses Postbacks and Session.

Basically,  I save a list of textboxes as a session variable and then check them on button click and add them to the form — I also give them unique ID’s so I can do something with them later on in the process…. Here is the code:

        protected void Button1_Click(object sender, EventArgs e)
        {
            //This will be changed if we have controls in session.
            int tbId = 1;
 
            List seshTextboxes = new List();
 
            if (Session["controlsList"] != null)
            {
                List list2 = (List)Session["controlsList"];
 
                //Change the newest Id to the new tb
                tbId = list2.Count + 1;
 
                //Get controls out of session
                foreach (ASPxTextBox tbSesh in list2)
                {
                    seshTextboxes.Add(tbSesh);
                    form1.Controls.Add(tbSesh);
                }
            }
 
            ASPxTextBox tb = new ASPxTextBox();
            tb.ID = "Column" + tbId;
            tb.Text = tbId.ToString();
            seshTextboxes.Add(tb);
            form1.Controls.Add(tb);
 
            Session["controlsList"] = seshTextboxes;
        }

Screenshot:

Dynamic Controls

You can create any number of dynamic controls to your form this way.

Testing if a Javascript function exists….

Category : JQuery/JScript

Believe it or not, you may come up against a situation where you do not whether a Javascript function exists in your page or not…. here is my scenario.

I am using usercontrols that are added to the page IF certain settings are set in the webconfig (something you might do if someone has one of your apps installed or has purchased a certain portions of your app) … so its possible this usercontrol has not been added to my page.

SO I need to know if I have a certain javascript function so that I can call it…. however if I call it or test for it WRONG I will get a Javascript error.

Here is the simple way to test this situation:

if(window.myJavascriptFunction) {
//do whatever I want to do now… like just CALL IT!
myJavascriptFunction();
}

hope this helps!
t