"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, May 28, 2010

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

 Hi, 
From last day this error is fucking my happiness.I search @ all forms 'n Blah Blah Blah i didn't get what i need.last i Solved it myself.
  In my early post i'm tell how to copy text from one text-box to another.it's done by one java-script.
when i put ajax over my pages this showing me this error
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

when i eliminate ajax it's working fine.but that's not a solution.On my search one told me that replace = with # i done it but i got another error on java-script.

 so i change the way i'm getting the value on the text-box 'n i done it

Previously it is in this way
           var paramVal1 = document.getElementById('<%=txtcheckin.ClientID%>').value;
Later i change to this
          var paramVal1 = document.getElementById('txtcheckin').value;


Have a nice day... 'N happy Coding :)
 Visual Studio 2010 Professional UpgradeProfessional Visual Studio 2010 (Wrox Programmer to Programmer)Microsoft Visual Studio 2010: A Beginner's Guide (A Beginners Guide)

Tuesday, May 25, 2010

Passing and Retrieving Querystring using JavaScript in ASP.NET

 Hi ,
We all are familiar with Query string in asp.net.Today I'm showing query string handling with JavaScript .
To sent the data to another page i create a function on page1.aspx and call the function on client-side button click

    <script type="text/javascript" language="javascript">
        function PassQuery()// my fuction
        {
            var paramVal1 = "SimplyAsp.net";
            var paramVal2 = "simplyasp.blogspot.com";
            window.open("Page2.aspx?id=" + paramVal1 + "&p=" + paramVal2);
        }
    </script>

To retrieve the value i call another function on body load of page2.aspx

    <script language="javascript" type="text/javascript">
        function GetQueryValue()
        {
           
                var query = window.location.search.substring(1);
                var parms = query.split('&');
                for (var i = 0; i < parms.length; i++) {
                    var pos = parms[i].indexOf('=');
                    if (pos > 0) {
                        var key = parms[i].substring(0, pos);
                        var val = parms[i].substring(pos + 1);
                        alert(val);
                    }
                }

        }
    </script>


Hope it help u some way's


Have a nice day... 'N happy Coding :)

Saturday, May 22, 2010

solve width problem in ASP.Net Password control

I came across a strange issue with Password input and IE browser. I have set the width property as same as that of the other controls. But while rendering it in IE, the width of Password field was coming as around 10 pixel less than the other control. The best way to get rid of this issue was using CSS.

Before



After


add these changes in ur css
===========================================================
<style type="text/css" >
       .TextBox
       {
           font-family: Arial, Tahoma, Verdana, Calibri;
           font-size: 12px;
           color: Black;
           height: auto;
           width: auto;
       }
   </style>
=========================================================
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
<form id="form1" runat="server">
<table width="25%">
<tr>
<td style="width:100%; text-align:left">UserName: </td>                  
<td style="width:100%; text-align:left">
<asp:TextBox CssClass="TextBox" ID="txtUserName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width:100%; text-align:left">Password: </td>                  
<td style="width:100%; text-align:left">
<asp:TextBox  CssClass="TextBox" ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox></td>
</tr>
</table>
</form>
</body>
</html> 


hope it,helped u :)
 Have a nice day... 'N happy Coding :)

 Beginning HTML5 and CSS3: Next Generation Web StandardsCSS: The Missing ManualPicture CSS3

Friday, May 21, 2010

Limiting the Data being displayed in the GridView and Display Tooltip


C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                ViewState["OrigData"] = e.Row.Cells[0].Text;
                if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements
                {
                    e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "...";
                    e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString();
                }
             }
} 
VB.NET
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) 
    If e.Row.RowType = DataControlRowType.DataRow Then 
        ViewState("OrigData") = e.Row.Cells(0).Text 
        If e.Row.Cells(0).Text.Length >= 30 Then  'Just change the value of 30 based on your requirements 
            e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(0, 30) + "..." 
            e.Row.Cells(0).ToolTip = ViewState("OrigData").ToString() 
        End If 
    End If 
End Sub 
 

Have a nice day... 'N happy Coding :)
 Illustrated C# 2008 (Windows.Net)Microsoft Visual C# 2008 Step by StepMicrosoft Visual C# 2010 Step by Step

Thursday, May 20, 2010

time based redirection in asp.net

 Hi everybody,
This is a very useful one for every Project. A simple example is after registration v show a message after that a few second (Manually controlling) redirecting him to his home page.

        System.Threading.Thread.Sleep(5000); //  after 5 sec
        Response.Redirect("http://www.simplyasp.net");
//
i'm redirecting him to simplyasp.net

hope it help u some way's
Have a nice day... 'N happy Coding :)

 The Rough Guide to KeralaHidden India: The Kerala SpicelandsKerala Dream: A Shaman's Dream Project

Wednesday, May 19, 2010

Check RadioButton/CheckBox Depending Upon Data in DataBase

 hi eveybody,
Saving checked items in RadioButton/CheckBox  to database and showing that back like edit command.
For that i first saved that checked item in checkbox list to database by comma separated form like (TV,Fridge)

Storing data to database Which where items are checked
Code

            foreach (ListItem li in Chk_ItemList.Items)// here u will get all the item in the CheckBoxList
            {
                if (li.Selected == true)// here i filter the selected from the list
                {
                    _itemlist = _itemlist += li.Text + ","; //here i add the selected item one by one separated by comma ex:tv,coller
                }
            }

here
Chk_ItemList is my Checkboxlist id
_itemlist is a string where i storing my checked item
and normally storing to database :) .and show the content in a grid i chosen here a datagrid.

On displaying back Which where items are checked 
 i taken the SelectedIndexChanged event of grid and 

        string _Item = grd.SelectedItem.Cells[1].Text.ToString(); // here i'm getting the string TV,Fridge
        string[] Seperator = new string[] { "," }; //i define here which one is ti be eliminated from that string and i'm calling the split function
        string[] strsplitarr = _Item.Split(Seperator, StringSplitOptions.RemoveEmptyEntries);//
RemoveEmptyEntries is for remove blankspace from the string and storing that string in an array
        foreach (string _chkitem in strsplitarr)
        {
            Chk_ItemList.Items.FindByText(_chkitem).Selected = true;// by the help of foreach i'm taking all the entry of an array and finding the text in checkboxlist if i find i mark it as selected :)
        } 

'n i created a demo of it u can download that from here 

Have a nice day... 'N happy Coding :)

TitanicTitanic (10th Anniversary Edition)Titanic (Three-Disc Special Collector's Edition)

Monday, May 17, 2010

Pls wait... on submit button click in asp.net C#

Hi everybody,
One of the social website giving this feature i notice this stuff from their i feel pretty nice i done only on page load just like gmail.I done this by calling a javascript on server side on page load event i'm giving event name, no of second,button name, Display message  :)

Important 

"Match Every event with color"

lets move to coding
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(3000); but_sve.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(but_sve, "") + ";this.value='Please wait...';this.disabled = true;");
    }
    protected void but_sve_Click(object sender, EventArgs e)
    {
        System.Threading.Thread.Sleep(5000); ClientScript.RegisterClientScriptBlock(this.GetType(), "reset", "document.getElementById('" + but_sve.ClientID + "').disabled=false;", true);
        lbl.ForeColor = System.Drawing.Color.Green;
        //lbl.Text = "Data Have Saved";
        Response.Redirect("http://www.google.com");//  from here ur coding can start
    }



U can download a demo from Here
Have a nice day... 'N happy Coding :)

SQL For DummiesSQL All-in-One Desk Reference For DummiesMicrosoft SQL Server 2008 For Dummies (For Dummies (Computer/Tech)) 

Saturday, May 15, 2010

AutoNumber Column or Auto Number in GridView or DataList ASP.NET

 Hi,
I posted early adding Serial Number on datagrid and that was through itemdatabound sometimes it may cause ur pjt to run a bit slow.on client-side Serial Number a nice concept is it...

Here v Go...


<asp:GridView ID="GridView1" runat="server"
              AllowPaging="True" AutoGenerateColumns="False">
    <Columns>
    <asp:TemplateField HeaderText="Serial Number">
    <ItemTemplate>
        <%# Container.DataItemIndex + 1 %>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="Name" HeaderText="Name"/>
    </Columns>
    </asp:GridView>


I hope this will help u....
Have a nice day... 'N happy Coding :)

ASP.NET Data Web Controls Kick StartProfessional DevExpress ASP.NET Controls (Wrox Programmer to Programmer)

Detecting Session Timeout and Redirect to Login Page in ASP.NET

Hi ,
V can do this by calling the Page_Init() function.. I hope everybody have an idea abt this function.v are checking our session value on this function.

Code

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Page_Init(object sender, EventArgs e)
    {
        CheckSession();
    }
    private void CheckSession()
    {
        if (Session["SessionID"] == null)
        {
            Response.Redirect("Login.aspx"); // This means session haves no value
        }
    }
I hope this will help you

Have a nice day... 'N happy Coding :)

This Is UsMillenniumThe Hits--Chapter One 

Friday, May 14, 2010

To check given String is Url or not using Regular Expression

Hi everyboday,
Few days back my friend ask me abt validating a  string that it contain a url or not.
Visual stdio is giving us a in-build option to check this so what v need is to cal this control on server side and validate it Simple :) 

To call Regular Expression on server side v need to add a name space
using System.Text.RegularExpressions;


validate URL's without http
 
Private bool ValidateUrl(string url)
{
// regex pattern for url validation string
Regex RgxUrl = new Regex("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
if (RgxUrl.IsMatch(url))
{
return true;// string url contain valid url
}
else
{
return false;
// string url contain invalid url
}

}


validate URL's with http



 

Private bool ValidateUrl(string url)
{
System.Globalization.CompareInfo cmpUrl = System.Globalization.CultureInfo.InvariantCulture.CompareInfo;
if(cmpUrl.IsPrefix(txtUrl.Text, "http://") == false)
{
txtUrl.Text = "http://" + txtUrl.Text;
}
Regex RgxUrl = new Regex("(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)?/{0,2}[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?");
if (RgxUrl.IsMatch(url))
{
return true;
}
else
{
return false;
}
}

Have a nice day... 'N happy Coding :)
 Hackers: Heroes of the Computer RevolutionHackersThe Web Application Hacker's Handbook: Discovering and Exploiting Security Flaws