Archive

Archive for January, 2015

Show Confimation Message Using Javascript

January 11, 2015 Leave a comment

Hi all,

try this example to Show Confimation Message Using Javascript with Action

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="Demo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Show Confimation Message</title>
<script type="text/javascript">
function ConfirmMessage() {
var result = confirm('Are you Sure?');
if (result)
document.getElementById('<%=btnSaveHidden.ClientID%>').click();
else
document.getElementById('<%=btnCancelHidden.ClientID %>').click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="sc" runat="server" EnablePartialRendering="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="updpnlSave" runat="server">
<ContentTemplate>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click1" />
<asp:Button ID="btnSaveHidden" runat="server" Text="Save Hidden" OnClick="btnSaveHidden_Click"
Style="display: none;" />
<asp:Button ID="btnCancelHidden" runat="server" Text="Cancel Hidden" Style="display: none;"
OnClick="btnCancelHidden_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

In Code behind :

public partial class Demo : System.Web.UI.Page
{
protected void btnSave_Click1(object sender, EventArgs e)
{
//Do Something
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "script", "ConfirmMessage();", true);
}
protected void btnSaveHidden_Click(object sender, EventArgs e)
{
//Do Something
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "script", "alert('You clicked Hidden Save');", true);
}
protected void btnCancelHidden_Click(object sender, EventArgs e)
{
//Do Something
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "script", "alert('You clicked Hidden Cancel');", true);
}
}

Hope this helps

Good Luck

Categories: ASP.Net, Javascript

Enable or Disable Asp.net TextBox on Button Click Event in jQuery

January 11, 2015 Leave a comment

Dear all,

Try this example to Enable or Disable Asp.net TextBox on Button Click Event in jQuery

<html>
<head>
<title>Webblogsforyou.com | Enable/Disable Asp.net Textbox</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#btnDisable").click(function () {
$("input:text").attr("disabled", "disabled");
return false; //to prevent from postback
});
$("#btnEnable").click(function () {
$("input:text").removeAttr("disabled");
return false; //to prevent from postback
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td colspan="2">
<b>* Click on any button and try to type text in textbox for demo</b>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
Try to type:
</td>
<td>
<asp:TextBox ID="txtTestbox" runat="server" ClientIDMode="Static" />
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<asp:Button ID="btnDisable" runat="server" Text="Disable" />
<asp:Button ID="btnEnable" runat="server" Text="Enable" />
</td>
</tr>
</table>
</form>
</body>
</html>

Hope this helps

Good Luck.

Categories: ASP.Net, Jquery

GridView CheckBox Validation using JavaScript jQuery and ASP.Net CustomValidator

January 8, 2015 Leave a comment

Hi all,

try this example to Validate ChekBox inside Gridview using Javascript JQuery with Custom Validator Control

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type = "text/javascript">
function ValidateCheckBoxes(sender, args) {
args.IsValid = $("[id$=GridView1] input:checked").length > 1;
}
</script>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Item" />
<asp:BoundField DataField="Code" />
</Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Please check atleast one checkbox" ClientValidationFunction = "ValidateCheckBoxes"></asp:CustomValidator>

In Code behind :

protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Code") });
dt.Rows.Add("Shirt", 199);
dt.Rows.Add("Football", 020);
dt.Rows.Add("Shirt", 566);
dt.Rows.Add("Disc", 099);
dt.Rows.Add("Watch", 54);
dt.Rows.Add("Clock", 890);
GridView1.DataSource = dt;
GridView1.DataBind();
}

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript, Jquery