Yasserzaid’s Weblog

December 20, 2008

Get Yesterday Date

Filed under: ASP.Net — yasserzaid @ 8:19 pm

Try this example:

DateTime.Now.AddDays(-1).ToString(“yyyy-MM-dd”);

Good Luck

Prevent Copy from Textbox to another

Filed under: ASP.Net, Javascript — yasserzaid @ 8:14 pm

Try this example:

Javascript function :

function noCopyMouse(e) {
        var isRight = (e.button) ? (e.button == 2) : (e.which == 3);
       
        if(isRight) {
            alert(‘You are prompted to type this twice for a reason!’);
            return false;
        }
        return true;
    }

    function noCopyKey(e) {
        var forbiddenKeys = new Array(‘c’,'x’,'v’);
        var keyCode = (e.keyCode) ? e.keyCode : e.which;
        var isCtrl;

        if(window.event)
            isCtrl = e.ctrlKey
        else
            isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;
   
        if(isCtrl) {
            for(i = 0; i < forbiddenKeys.length; i++) {
                if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
                    alert(‘You are prompted to type this twice for a reason!’);
                    return false;
                }
            }
        }
        return true;
    }
//– To use it

And add bit of code-behind to handle the two events for the textbox(es):

    Textbox1.Attributes.Add(“onmousedown”, “return noCopyMouse(event);”)
    Textbox1.Attributes.Add(“onkeydown”, “return noCopyKey(event);”)
<asp:TextBox ID=”TextBox1″ runat=”server” onpaste=”return false” oncut=”return false”>
</asp:TextBox>

Good Luck

Show image in Gridview on mouseover

Filed under: ASP.Net, Javascript — yasserzaid @ 8:10 pm

Hi

try this example to show Image onmouseover where i save image name in database and upload image in

Car_Image folder in root of my website

<script type="text/javascript">   
function get_(div_)
{ 
div_=div_.id+"1"; 
document.getElementById(div_).style.display="block";
}

function get_1(div_)
{ 
div_=div_.id+"1"; 
document.getElementById(div_).style.display="none";
}   

</script>

         
<asp:GridView ID="GridView1" runat="Server" AutoGenerateColumns="False">               
<Columns>                   
<asp:BoundField DataField="Id" HeaderText="Id" />                   
<asp:BoundField DataField="Name" HeaderText="Name" />                   
<asp:TemplateField HeaderText="Description">                       
<ItemTemplate>                           
<asp:Image ID="lnk" runat="server" Height="105px" ImageUrl='<%# Eval("Image", "~/Car_Image/{0}") %>'
                        Width="126px" onmouseover="get_(this);" onmouseout="get_1(this);"  />
<div id="lnk1" runat="server" style="display: none; position: absolute; background-color: #FEFFB3;width: 170px; border:gray">
<p><strong>Car Image</strong></p>                               
<p>                                  
<img src='<%# Eval("Image", "~/Car_Image/{0}") %>' runat="Server" id="A" /></p>                           
</div>                        
</ItemTemplate>                   
</asp:TemplateField>               
</Columns>           
</asp:GridView>

Good Luck

Popup Calender with Javascript

Filed under: ASP.Net, Javascript — yasserzaid @ 8:02 pm

Hi

try this example:

Popup.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Popup.aspx.cs" Inherits="NewFolder1_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">

<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Calendar ID="calDate" OnSelectionChanged="Change_Date" Runat="server" />
    <input type="hidden" id="control" runat="server" />
    </div>
    </form>
</body>
</html>

Popup.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class NewFolder1_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        control.Value = Request.QueryString["textbox"].ToString();
    }
    protected void Change_Date(object sender, EventArgs e)
    {
        string strScript  = "<script>window.opener.document.forms(0)." + control.Value + ".value = '";
        strScript += calDate.SelectedDate.ToString("dd/MM/yyyy");
        //strScript += calDate.SelectedDate.ToString("MM/dd/yyyy");
        strScript += "';self.close()";
        strScript += "</" + "script>";
        RegisterClientScriptBlock("anything",strScript);
    }
}

Default.aspx

<asp:TextBox ID="txtEndDate" Runat="server"  />

      <a href="javascript:;" onclick="window.open('Popup.aspx?textbox=<%=txtEndDate.ClientID%>','cal','width=300,height=300,left=300,top=300')">
      <img src="images/Calendar_scheduleHS.png" border="0" title="Select End Date"></a>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Select End Date" ControlToValidate="txtEndDate"></asp:RequiredFieldValidator>

   

Good Luck

Open Popup Window with HyperLink inside GridView

Filed under: ASP.Net, Javascript — yasserzaid @ 8:00 pm

Hi

try these examples:

<asp:TemplateField>
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=<%# String.Format("javascript:void(window.open('http://www.{0}.com'))", Eval("ProductID")) %>> HyperLink</asp:HyperLink>
                    </ItemTemplate>

</asp:TemplateField>

//———Or  this example——

<asp:TemplateField>
                <ItemTemplate>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl=<%# String.Format("javascript:void(window.open('image.aspx?PId={0}',null,'left=45px,top=15px, width=300px, height=300px,status=no, resizable= yes, scrollbars=yes, toolbar=no, location=no,menubar=no'))",Eval("Image", "~/Car_Image/{0}")) %>>View Image</asp:HyperLink>
                </ItemTemplate>
</asp:TemplateField>

Good Luck

LinkButton and CSS image

Filed under: CSS — Tags: — yasserzaid @ 7:57 pm

Hi

try this example:

<style>

#navigation a
{
 color: #fff;
 background: #26a url("images/left-tab.gif") left top no-repeat;
 text-decoration: none;
 padding-left: 10px;
}

#navigation a span
{
 background: url("images/right-tab.gif") right top no-repeat;
 padding-right: 10px;
}

</style>

<ul id="navigation">
 <li><asp:LinkButton ID="LinkButton1" runat="server">Home</asp:LinkButton></li>
 <li><asp:LinkButton ID="Linkbutton2" runat="server"><span>Home</span></asp:LinkButton></li>
</ul>

Good Luck

HowTo Display radiobuttonlist with images

Filed under: ASP.Net — yasserzaid @ 7:53 pm

Hi Try this example:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioListImage.aspx.cs" Inherits="RadioListImage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>">
<html xmlns="<a href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</a>">
<head runat="server"> 
<title>Untitled Page</title>
</head>
<body> 
<form id="form1" runat="server">     
<div>         
<asp:RadioButtonList ID="rdoI" runat="Server">         
</asp:RadioButtonList>     
</div> 
</form>
</body>
</html>

in code behind :-

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class RadioListImage : System.Web.UI.Page
{  
protected void Page_Load(object sender, EventArgs e)  
{      
string[] strImages = System.IO.Directory.GetFiles(Server.MapPath("~/img"));      
foreach (string strImage in strImages)      
{          
this.rdoI.Items.Add(new ListItem(String.Format("<img src='{0}'>", strImage.ToString()), strImage.ToString()));      
}  
}
}

Good Luck

How To Make Window Fit Any Resolution

Filed under: Javascript — yasserzaid @ 7:52 pm

Hi

try this example:

1) Create function definition
<head>
<script language=”Javascript”>
function resolution()
{
UserWidth = window.screen.availWidth
UserHeight = window.screen.availheight
window.resizeTo(UserWidth, UserHeight)
window.moveTo(0,0)
}
</script>
</head>

2) Call the function on load event of body.
<body OnLoad=”resolution();”>

Good Luck

How to Display Sum Total in the Footer of the GridView Control

Filed under: ASP.Net — yasserzaid @ 7:50 pm

Hi

try this example:

<asp:GridView ID=”GridView1″
  ShowFooter=”true” DataKeyNames=”ProductId”
  AutoGenerateColumns=”false” runat=”server”
  DataSourceID=”SqlDataSource1″>
<Columns>
<asp:BoundField DataField=”Productid” HeaderText=”Product Id” />
<asp:BoundField DataField=”ProductName” FooterText=”Total” HeaderText=”Product Name” />
<asp:TemplateField HeaderText=”Unit Price” FooterStyle-Font-Bold=”True”>
<ItemTemplate>
  <%# GetUnitPrice(decimal.Parse(Eval(“UnitPrice”).ToString())).ToString(“N2″) %>
</ItemTemplate>
<FooterTemplate>
  <%# GetTotal().ToString(“N2″) %>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID=”SqlDataSource1″ runat=”server”
ConnectionString=”<%$ ConnectionStrings: DummyDB %>”
SelectCommand=”Select * from Products”>
</asp:SqlDataSource>

in code behind:

decimal TotalUnitPrice;
decimal GetUnitPrice(decimal Price)

  TotalUnitPrice += Price;
  return Price;
}
decimal GetTotal()
{
  return TotalUnitPrice;
}

Good Luck

How to Check ImageURL in DataList

Filed under: ASP.Net — yasserzaid @ 7:48 pm

Hi

try this example that we store image name in database and uplaod image in Car_Image folder

Place this function in page code behind:
    Protected Function GetImageUrl(ByVal url As Object) As String
        Dim url1 As String = ""
        If url Is DBNull.Value OrElse String.IsNullOrEmpty(url) Then
            url1 = "~/Car_Image/NOIMAGE.jpg"
        Else
            url1 = String.Format("~/Car_Image/{0}", url)
        End If

        Return ResolveUrl(url1)
    End Function

 
And change the image code to :

<asp: DataList ID="dlCountry" runat="server"  RepeatDirection="Horizontal" >
<ItemTemplate>
<asp:image id="Image1" runat="server" ImageUrl='<%# GetImageUrl(Eval("Image")) %>' />
</ItemTemplate> 
</asp: DataList>

Good Luck

Older Posts »

Blog at WordPress.com.