Tuesday, March 11, 2014

How to change css from Code Behind

Normally css is changed though jQuery but in this tutorial I will show you how you can change a control css from code behind.

First we need to find the control

HtmlControl myControl1 = (HtmlControl)Page.Master.FindControl("Label1");
         
            myControl1.Attributes.Add("style", "display:none");


In the above example we are first finding an element Label1 which is inside our master page, after finding the control we are saving it in myControl1 who's type is HtmlControl

Now using Control1.attributes.Add()

We can add any css

I hope it was informative for you and I would like to Thank you for reading         

Tuesday, March 4, 2014

Insert default text in TextBox ASP.NET

You can insert default text in TextBox to assist your users what value to insert in the Textbox


            onBlur="if (this.value=='') this.value = 'Default Value'" onfocus="if (this.value=='Default Value') this.value = ''

When the Textbox looses focus it's value will automatically changes to Default Value and when the focus is inside the control its Default value will change so that user can type

I hope it was informative for you and I would like to Thank you for reading.

Monday, March 3, 2014

Make Email address unique in create User Wizard ASP.NET

in createuserwizard the userid is unique by default

But in some cases we want to make both user id and email address unique so that a single user don't create multiple account.

we have 2 options

First option is that we can either edit the aspnet membership database and make userId and email as composite key which is not easy

2nd option is to this membership rule in web.config of our project

I will be using option number 2 for this tutorial

add the following taf in your web.config replace the name of connectionStringName as per your requirement

    <membership defaultProvider="CustomizedMembershipProvider">
      <providers>
        <add name="CustomizedMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" minRequiredPasswordLength="8" minRequiredNonalphanumericCharacters="1"/>
      </providers>
    </membership>


I hope it was informative for you and I would like to Thank you for reading.

Saturday, January 4, 2014

Get GridView Cell value using jQuery ASP.NET

In this tutorial I will show you how you can get the cell value of Grid View using jQuery

You will first need to populate your gridview using any datasource

than using the jquery below

$("#<%=gv1.ClientID %> tr").each(function () {
                    if (!this.rowIndex) return;
                    var row = $(this).find("td:first");
                    alert(row[0].innerText);
                });
gv1 is the name of our gridview

using the each loop we iterate on each row

td:first indicate that we are only getting value of first column

we can also use

td:last
td:even
td:odd
td:eq("index number")
td:gt("Include element that are past the given index")
td:lt("Include element that are before the given index")
td:not()

I hope it was informative for you and I would like to Thank you for reading