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>