Thursday, 13 September 2012

Timer In Asp.net

Timer is available in asp.net toolbox. Double click it to add your page.
Then add Script Manager in our aspx page. Script Manager is Important for timer.


Design Page


<asp:ScriptManager ID="ScriptManager1" runat="server" >
    </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" interval="1000" ontick="Timer1_Tick">
        </asp:Timer>
        <asp:Label ID="Label1" runat="server" Text="60"></asp:Label>
        </ContentTemplate>
        </asp:UpdatePanel>


Coading


  protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (Convert.ToString(Label1.Text) != "")
        {
            seconds = int.Parse(Label1.Text);
            min = int.Parse(Label1.Text);
        }
        else
        {
             seconds =Convert.ToInt32(defaultTimer);//set some time count in default timer
        }
        Session["timeout"] = (seconds - 1).ToString();
        if (seconds > 0)
        {

            Label1.Text = (seconds + 1).ToString();

        }
        else
        {
            Timer1.Enabled = false;

        }
    }

Set paging in datalist control in asp.net

Design Page

 <asp:DataList ID="dlPaging" runat="server" CellSpacing="15" RepeatColumns="2" Width="85%">
                        <ItemTemplate>
          <table>
                                <tr>
                                    <td >
                                        <h4>
            <asp:Label ID="Label6" runat="server" Text='<%#Eval("Column Name") %>'></asp:Label></h4>
                                    </td>
                                </tr>
           </table>
<div id="paging">
                     <asp:Label ID="lblCurrpage" runat="server" CssClass="labelpaging"></asp:Label>
                </div>
</ItemTemplate>
</asp:DataList>


Coading 

string m_pagingId;

protected void Page_Load(object sender, EventArgs e)
    {
    if (!string.IsNullOrEmpty(this.Request.QueryString["page"]))
        {
            m_pagingId = this.Request.QueryString["page"];
            Paging();
        }
     }

private void Paging()
    {
        string strQuery = "";
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        strQuery = string.Format("Select  Query");

        SqlCommand cmd = new SqlCommand(strQuery, cn);
        SqlDataAdapter adp = new SqlDataAdapter(cmd);
        DataTable DT = new DataTable();
        adp.Fill(DT);

        if (DT.Rows.Count == 0)
        {
            divpage.Visible = false;
            lblError.Text = " No Items to Show";
            return;
        }
        //if (Session["catID"] == null && Session["object"] == null) { return; }

        PagedDataSource pageds = new PagedDataSource();
        pageds.DataSource = DT.DefaultView;
        pageds.AllowPaging = true;
        pageds.PageSize = 2;

        int curpage = 0;

        //when click paging, it sends the page index through query string
        if (m_pagingId != null)
        {
            curpage = Convert.ToInt32(m_pagingId);
        }
        else
        {
            curpage = 1;
        }
        pageds.CurrentPageIndex = curpage - 1;

        //display the current page index setup
        if (curpage == 1 && pageds.DataSourceCount < pageds.PageSize)
            lblCurrpage.Text = "Page:";
        else if (pageds.DataSourceCount == 0)
            lblCurrpage.Text = "No productst";
        else if (curpage > 1 && pageds.DataSourceCount > pageds.PageSize)
            lblCurrpage.Text = "Page: <a href='Current  Page Name.aspx?page=' style='text-decoration:none;' ></a>";
        else
            lblCurrpage.Text = "Page:";

        //set link for each index
        for (int i = 1; i <= pageds.PageCount; i++)
        {
            if (i == curpage)
                lblCurrpage.Text = lblCurrpage.Text + " &nbsp; " + i.ToString();
            else
                lblCurrpage.Text = lblCurrpage.Text + " &nbsp; <a href='Current Page Name.aspx?page=" + i.ToString() + "' style='text-decoration:none;'>" + i.ToString() + "</a>";
        }

        //bind the value in datalist
        dlPaging.DataSource = pageds;
        dlPaging.DataBind();
    }

Wednesday, 21 March 2012

Query String

Query String in asp.net

Query String is used to transfer the data to another page by redirecting.

Redirect Query String
Response.Redirect("aspxPage.aspx?parameter=" + TextBox1.Text);
 
Receive the Query String Value
string sQueryStringVal = Request.QueryString["parameter"];


Send and Receive a Query String using Hyperlink

SEND a Query String using Hyperlink
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx?Id={0}">Link
</asp:HyperLink>

HyperLink1.NavigateUrl = string.Format(HyperLink1.NavigateUrl, TextBox1.Text);

Receive a Query String using Hyperlink
string sQueryStringVal = Request.QueryString["Id"];


Pass a Query String using Hyperlink inside the Grid View


  1. <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "~/Default2.aspx?Id="+Eval("columnName")%>'>Link</asp:HyperLink>
     2. <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Default2.aspx?Id={0}">Link
</asp:HyperLink>

Disable Mouse Drag Event

Disable Mouse Drag Event Using J QUERY

First write a function in j query

<script type="text/javascript">
    $(document).ready(function(){
    disableDrag(document.getElementById("Drag"));
    });
   
    function disableDrag (element){
    element.draggable=false;
    element.onmousedown=function(event){
    event.preventDefault();
    return false;
    }
    }
    </script>

Then call the function in the ready function

Thank You

Send Mail Automatically in asp.net

First you include System.Net.Mail name space ..
Then you insert the below query in button click event...

try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("raja.com");
                message.To.Add("raja30march90@gmail.com");
                message.Subject = "Subject";
                message.Body = "Body Content";

                SmtpClient sptclt = new SmtpClient();
                sptclt.Host = "127.5.7.1";
                sptclt.Send(message);
                lblStatus.Text = "Mail send successfully";
            }
            catch (Exception e)
            {
                lblError.Text = "Mail sent Failed";
            }

Friday, 2 March 2012

Notes for ajax jquery

 GET textbox value 

TextBox in a Contentplaceholder
         Use :   $("#<%=txtRepaymentAmt.ClientID%>")

TextBox Not in a Contentplaceholder
        Use  :    $("#txt_Address")

TextBox in a gridview
    USe  :  
$("table[id*=grd_RevisedPlan] input[type=text][id*=txt_amt]") 

TextBox in a TabPanel

        Use  :
$(document.getElementById("ctl00_ContentPlaceHolder_TabContainerProduct_TabPanelSize_txtPrice"))


Get ddl value

         var getValue = $("#<%=ddlTypeId.ClientID%>").val();


Get ddl Selected text
        var getText = $("#<%=ddlTypeId.ClientID%> option:selected").text();

Split ddl selected value
       var getText = $("#<%=ddlTypeId.ClientID%> option:selected").text().split('|');
       var Text = getText [0].toString();

Set ddl selected value
       var subType = "";
       $("#<%=ddlTypeId.ClientID%>").val(subType );

Show
     $("#<%=ddlTypeId.ClientID%>").show();

Hide
     $("#<%=ddlTypeId.ClientID%>").hide();

Number validation in to textbox using Jquery

Javascript 
<script type="text/javascript">
    function numberOnlyExample() {
        if ((event.keyCode < 48) || (event.keyCode > 57))
            return false;
    }
</script> 

<asp:TextBox ID="TextBox1" onKeyPress="return validateNumbersOnly();"runat="server"></asp:TextBox>
Jquery 
<script type="text/javascript">
  $(document).ready(function () {
            $('input[numeric]').keyup(function () {
                var d = $(this).attr('numeric');
                var val = $(this).val();
                var orignalValue = val;
                val = val.replace(/[0-9]*/g, "");
                var msg = "Only Integer Values allowed.";
                if (val != '') {
                    orignalValue = orignalValue.replace(/([^0-9].*)/g, "")
                    $(this).val(orignalValue);
                    alert(msg);
                }
            });
        });

    </script>

    <asp:TextBox ID="txtCardno" numeric="integer" runat="server"></asp:TextBox>



<script type="text/javascript">
            $(document).ready(function () {

                $('#<%=txtboxId.ClientID %>').ariyValidate({
                    type: "price",
                    error_message: ""
                });

           });
</script>