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

Pages

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