Asp.net Image Button does not have an onClick event - asp.net

This code is inside a GridView,
<asp:TemplateField HeaderText="Edit" ItemStyle-VerticalAlign="Middle" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Image ID="imgEdit" ImageUrl="~/edit.png" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
My problem is that if I try to create an onClick event inside the <asp:Image attribute it is not available. What might be the issue?

<asp:Image /> is used to display images only, hence you're not able to use OnClick Event. The control you're looking for is <asp:ImageButton /> which will allow you to use the OnClick Event.
<asp:ImageButton runat="server" OnClick="MyClickFunction" />

You can use an ImageButton like that :
<%# Page Language="C#" AutoEventWireup="True" %>
<!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>
<title>ImageButton Sample</title>
<script language="C#" runat="server">
void ImageButton_Click(object sender, ImageClickEventArgs e)
{
Label1.Text = "You clicked the ImageButton control at the coordinates: (" +
e.X.ToString() + ", " + e.Y.ToString() + ")";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>ImageButton Sample</h3>
Click anywhere on the image.<br /><br />
<asp:ImageButton id="imagebutton1" runat="server"
AlternateText="ImageButton 1"
ImageAlign="left"
ImageUrl="images/pict.jpg"
OnClick="ImageButton_Click"/>
<br /><br />
<asp:label id="Label1" runat="server"/>
</form>
</body>
</html>
If is on Client side you can simply use a ..
more at : https://msdn.microsoft.com/fr-fr/library/system.web.ui.webcontrols.imagebutton.onclick(v=vs.110).aspx

Related

Date Picker Control Using AjaxControlToolkit in a form (Comparing between 2 date picker )

I am using the normal AjaxControlToolkit & use 2 datepicker in my page.
First date picker is taking the date which doesn't ex id from Today Date(today or any previous date). On the 2nd text box I can selected the date in between the date taken in the 1st date picker to Today Date.
The Script code which i am using that works on the JQuery date picker. But it won't work in the normal Ajax date picker.
Here is the code As follows:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 runat="server">
<title>Date Picker</title>
<script type="text/C#" >
$(function () {
$("#txtfrom").datepicker({
onSelect: function (date) {
$("#txtto").datepicker({
minDate: date,
maxDate: new Date()
});
},
maxDate: 0
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<b>From</b>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="ceLoanTakenDate" runat="server" Format="dd/MM/yyyy" PopupButtonID="txtfrom" TargetControlID="txtfrom">
</cc1:CalendarExtender>
&nbsp &nbsp
<b>To</b>
<asp:TextBox ID="txtto" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" PopupButtonID="txtto" TargetControlID="txtto">
</cc1:CalendarExtender>
</div>
</form>
</body>
</html>
You need to handle client-side DateSelectionChanged event of the first extender and set up startDate property of the second extender:
<b>From</b>
<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="ceLoanTakenDate" runat="server" Format="dd/MM/yyyy"
PopupButtonID="txtfrom" TargetControlID="txtfrom"
OnClientDateSelectionChanged="ceLoanTakenDate_dateSelectionChanged">
</ajaxToolkit:CalendarExtender>
<b>To</b>
<asp:TextBox ID="txtto" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" PopupButtonID="txtto"
TargetControlID="txtto">
</ajaxToolkit:CalendarExtender>
<script type="text/javascript">
function ceLoanTakenDate_dateSelectionChanged(sender, args) {
$find("<%= CalendarExtender1.ClientID %>").set_startDate(sender.get_selectedDate());
}
</script>

asp.net page not posting back, while the button click event is still firing

Okay, so I have this page, which has one Ajax:AsyncFileUploader also some other ajax stuff like ModelPopUpExtender etc. The problem is the two buttons in the page, of Cancel and Submit, both of them firing up but none is posting back, while I made sure none of the fields in the page are blank.
I know the events are firing up, because I debugged the JavaScript in Firebug (a single step into and continue process took more than 4 min, while I was just almost held the F10 key for stepping into, down!)
If anyone wants code, please tell me I'd post it, but buttons are just in normal code so nothing special, that's why I am not posting the code, but in case required I can post entire page's code (which is pretty long I'd tell you, not really though, but at least just for posting purpose in here, somewhat around 200 lines).
Any help anyone?
Edit: As per comment I am posting the code
code: aspx page
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!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 runat="server">
<title>Detailed Reminder</title>
<link href="StyleSheets/Default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function FileUploaded(sender, args) {
var filename = args.get_fileName();
var contentType = args.get_contentType();
var text = "Size of " + filename + " is " + args.get_length() + " bytes";
if (contentType.length > 0) {
text += " and content type is '" + contentType + "'.";
}
$get('LabelStatusUpload').innerHTML = "File Uploaded Successfully";
}
function UploadStarted(sender, args) {
$get('LabelStatusUpload').innerHTML = "Upload Started";
}
function ErrorUploaded(sender, args) {
$get('LabelStatusUpload').innerHTML = "Some Error Occured";
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ajax:ToolkitScriptManager ID="SM1" runat="server">
</ajax:ToolkitScriptManager>
<asp:Button ID="Temp1" runat="server" Text="clear" />
<div id="UpperContainer">
<asp:Panel ID="PanelOuter" runat="server">
<asp:Table ID="TableDetailedRemidner" runat="server">
<asp:TableRow ID="TableRowName" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
<asp:Label ID="LabelName" runat="server" AssociatedControlID="txtName" Text="Name"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell2" runat="server">
<asp:TextBox ID="txtName" runat="server" ToolTip="Name of the user to send the mail to"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowEmail" runat="server">
<asp:TableCell ID="TableCell3" runat="server">
<asp:Label ID="LabelEmail" runat="server" AssociatedControlID="txtEmail1" Text="Email 1"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell4" runat="server">
<asp:TextBox ID="txtEmail" runat="server" Width="560px"></asp:TextBox>
<asp:RegularExpressionValidator ID="regexEmailValidator" runat="server" ControlToValidate="txtEmail"
Display="Dynamic" Text="Invalid Email" ValidationExpression="\w+([-+.’]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowSubject" runat="server">
<asp:TableCell ID="TableCell5" runat="server">
<asp:Label ID="LabelSubject" runat="server" AssociatedControlID="txtSubject" Text="Subject"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell6" runat="server">
<asp:TextBox ID="txtSubject" runat="server" AutoComplete="off" Width="560px"></asp:TextBox>
<asp:Panel ID="PanelDefaultSubjects" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanelSubject" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RadioSubjectList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioSubjectList_SelectedIndexChanged">
<asp:ListItem Text="Submit the reports"></asp:ListItem>
<asp:ListItem Text="prepare the presentation"></asp:ListItem>
<asp:ListItem Text="Custom" Value=""></asp:ListItem>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<ajax:PopupControlExtender ID="PCESubject" runat="server" TargetControlID="txtSubject"
PopupControlID="PanelDefaultSubjects" CommitProperty="value" Position="Right"
OffsetX="5" CommitScript="e.value" />
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowMessage" runat="server">
<asp:TableCell ID="TableCell7" runat="server">
<asp:Label ID="LabelMessageBody" runat="server" AssociatedControlID="txtMessageBody"
Text="Message"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell8" runat="server">
<asp:TextBox ID="txtMessageBody" runat="server" Columns="40" Rows="10" Multiline="true"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowFileUpload" runat="server">
<asp:TableCell ID="TableCell9" runat="server">
<asp:Label ID="LabelFileAttached" runat="server" AssociatedControlID="AsyncFileUpload1"
Text="Attach a file"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell10" runat="server">
<ajax:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnClientUploadComplete="FileUploaded"
OnClientUploadError="ErrorUploaded" OnClientUploadStarted="UploadStarted" OnUploadedComplete="File_Uploaded"
UploaderStyle="Modern" ThrobberID="LabelThobber" />
<asp:Label ID="LabelThobber" runat="server" Style="display: none"><img alt="" src="Images/uploading.gif" /></asp:Label><br />
<asp:Label ID="LabelStatusUpload" runat="server" Text=" "></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TableRowDueDate" runat="server">
<asp:TableCell ID="TableCell11" runat="server">
<asp:Label ID="LabelDueDate" runat="server" AssociatedControlID="txtDueDate" Text="Due Date"></asp:Label>
</asp:TableCell>
<asp:TableCell ID="TableCell12" runat="server">
<asp:TextBox ID="txtDueDate" runat="server" Width="560px"></asp:TextBox>
<ajax:MaskedEditExtender runat="server" ID="MEEDueDate" TargetControlID="txtDueDate"
Mask="99/99/9999" AutoComplete="true" MaskType="Date">
</ajax:MaskedEditExtender>
<ajax:MaskedEditValidator ID="MEVDueDate" runat="server" ControlExtender="MEEDueDate"
ControlToValidate="txtDueDate" IsValidEmpty="False" EmptyValueMessage="Due Date is required"
InvalidValueMessage="Due Date is required" EmptyValueBlurredText="*" InvalidValueBlurredMessage="*"
MaximumValueBlurredMessage="*" MinimumValueBlurredText="*" Display="Dynamic" />
<ajax:CalendarExtender ID="CalDueDate" runat="server" TargetControlID="txtDueDate">
</ajax:CalendarExtender>
</asp:TableCell></asp:TableRow>
<asp:TableRow ID="TableRowFrequency" runat="server">
<asp:TableCell ID="TableCell17" runat="server">
<asp:Label ID="LabelFrequency" runat="server" AssociatedControlID="txtFrequency"
Text="Frequency"></asp:Label>
</asp:TableCell><asp:TableCell ID="TableCell18" runat="server">
<asp:TextBox ID="txtFrequency" runat="server"></asp:TextBox>
<asp:Panel ID="PanelFrequency" runat="server">
<div>
<asp:UpdatePanel ID="UpdatePanelFrequency" runat="server">
<ContentTemplate>
<asp:RadioButtonList ID="RadioButtonFrequency" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="RadioSubjectFrequency_SelectedIndexChanged">
<asp:ListItem Text="15 min"></asp:ListItem>
<asp:ListItem Text="6 hr"></asp:ListItem>
<asp:ListItem Text="24 hr"></asp:ListItem>>
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<ajax:PopupControlExtender ID="PCEFrequency" runat="server" TargetControlID="txtFrequency"
PopupControlID="PanelFrequency" CommitProperty="value" Position="Right" OffsetX="5"
CommitScript="e.value" />
</asp:TableCell></asp:TableRow>
<asp:TableFooterRow>
<asp:TableCell ID="TableCellSubmit" runat="server">
<asp:Button ID="BtnSubmit" runat="server" OnClick="Submit_Click" Text="Set Reminder Detailed" />
</asp:TableCell><asp:TableCell ID="TableCellCancel" runat="server">
<asp:Button ID="BtnCancel" runat="server" OnClick="Cancel_Click" Text="Cancel" />
</asp:TableCell></asp:TableFooterRow>
</asp:Table>
</asp:Panel>
</div>
</form>
</body>
</html>
Code : page_Behind.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
//static protected string savePath;
//static protected int curFileSize;
//static protected bool IsFileAttached;
protected void Page_Load(object sender, EventArgs e)
{
CalDueDate.StartDate = DateTime.Now.Date;
CalDueDate.EndDate = DateTime.Now.Date.AddYears(1);
MEVDueDate.MinimumValue = DateTime.Now.Date.ToShortDateString();
MEVDueDate.MaximumValue = DateTime.Now.Date.ToShortDateString();
}
protected void RadioSubjectList_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(RadioSubjectList.SelectedValue))
{
// Popup result is the selected task
PCESubject.Commit(RadioSubjectList.SelectedValue);
}
else
{
// Cancel the popup
PCESubject.Cancel();
}
// Reset the selected item
RadioSubjectList.ClearSelection();
}
protected void RadioSubjectFrequency_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(RadioButtonFrequency.SelectedValue))
{
PCEFrequency.Commit(RadioButtonFrequency.SelectedValue);
}
else
{
PCEFrequency.Cancel();
}
RadioButtonFrequency.ClearSelection();
}
protected void File_Uploaded(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
string savePath = MapPath("~/Uploads/") + Path.GetFileName(DateTime.Now.Month + DateTime.Now.Day + " "
+ DateTime.Now.Hour + DateTime.Now.Minute + " " + e.FileName);
AsyncFileUpload1.SaveAs(savePath);
}
}
protected void Submit_Click(object sender, EventArgs e)
{
// On Submit button doesn't even reaches here, debugged and breakpoint on any of following code is never reached
int lastID = BusinessLayer.DetermineLastDetailedID();
// Some other logic unimportant at this point
BusinessLayer.AddDReminder(sender, e);
}
protected void Cancel_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtEmail1.Text = "";
txtEmail2.Text = "";
txtEmail3.Text = "";
txtSubject.Text = "";
txtMessageBody.Text = "";
txtDueDate.Text = "";
txtFrequency.Text = "";
}
}
I copied your code, experienced the problem, fixed it and now the postback is happening just fine. MEVDueDate is always saying "IsValid=false" and because of that the PostBack was not getting to Page_Load (that is the expected behavior of that validator).
You need to change:
MEVDueDate.MinimumValue = DateTime.Now.Date.ToShortDateString();
MEVDueDate.MaximumValue = DateTime.Now.Date.ToShortDateString();
with this:
MEVDueDate.MinimumValue = DateTime.Now.Date.ToString("MM/dd/yyyy");
MEVDueDate.MaximumValue = DateTime.Now.Date.ToString("MM/dd/yyyy");
Select today on the calendar for Due Date, click cancel button and you should have a full postback. Please see that you are saying that min and max allowed dates are both today, so today is the only valid date that will allow the post-back to fire.
The reason is that your calendar picker writes on the textbox "03/08/2012" but the ToShortDateString() retrieves a string with another date format. You end up comparing "03/08/2012" with "08/03/2012".
You need to make sure the date format you use to set MEVDueDate.MinimumValue is according to the format that calendarPicker (CalDueDate) puts in txtDueDate.
comment this and try
<%-- <ajax:MaskedEditExtender runat="server" ID="MEEDueDate" TargetControlID="txtDueDate"
Mask="99/99/9999" AutoComplete="true" MaskType="Date">
</ajax:MaskedEditExtender>
<ajax:MaskedEditValidator ID="MEVDueDate" runat="server" ControlExtender="MEEDueDate"
ControlToValidate="txtDueDate" IsValidEmpty="False" EmptyValueMessage="Due Date is required"
InvalidValueMessage="Due Date is required" EmptyValueBlurredText="*" InvalidValueBlurredMessage="*"
MaximumValueBlurredMessage="*" MinimumValueBlurredText="*" Display="Dynamic" />
<ajax:CalendarExtender ID="CalDueDate" runat="server" TargetControlID="txtDueDate">
</ajax:CalendarExtender>--%>
The button events are not being propagated out of the Table object that they are contained in.
Register the OnClick events for the 2 buttons in the table creation.

ASP.NET ValidatorOnChange being fired on a DropDownList even though CausesValidation is by default false

The use case here is that a dropdownlist that has AutoPostBack set to true, which updates the other items on the page. However the same dropdownlist is also part of required item in the ValidationGroup when submit button is clicked.
The problem we're facing is that when the dropdownlist changes, the ValidatorOnChange is triggered and therefore shows the error briefly before the postback refreshes the page.
The fix we're planning to do is to remove the ValidatorOnChange function for the dropdownlist, but this seems like a weird hack, so we're wondering if anyone has any other suggestions.
Here's a very simple list that demonstrate the problem:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void OnChange(object sender, EventArgs e)
{
updateList.Visible = test.SelectedValue == "1";
updateList2.Visible = test.SelectedValue == "2";
}
private void OnSubmit(object sender, EventArgs e)
{
if (Page.IsValid)
{
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList runat="server" ID="test" AutoPostBack="true" OnSelectedIndexChanged="OnChange">
<asp:ListItem Text="Test" Value="-1" />
<asp:ListItem Text="Test 1" Value="1" />
<asp:ListItem Text="Test 2" Value="2" />
<asp:ListItem Text="Test 3" Value="3" />
</asp:DropDownList>
<asp:RequiredFieldValidator ID="DropDownListValidator2" runat="server" ControlToValidate="test"
ErrorMessage="Please select" InitialValue="-1" ValidationGroup="testGroup" />
<asp:DropDownList runat="server" ID="updateList" Visible="false" />
<asp:DropDownList runat="server" ID="updateList2" Visible="false" />
<asp:Button runat="server" ID="testSubmit" Text="Submit" ValidationGroup="testGroup"
OnClick="OnSubmit" />
</div>
</form>
</body>
</html>
The following jquery script block should work for you. disabling validation using ValidatorEnable() when selecting an item from Dropdownlist will do the trick
here i bind the change handler with the onchange client side event of the dropdownlist
$("#<%=test.ClientID %>").change(function(){
ValidatorEnable(DropDownListValidator2, false);
});

FilteredTextBoxExtender in asp.net

iam using ajaxtoolkit in asp.net 3.5, using filter texbox extender control
<%# Page Language="C#" %>
<%# Register TagPrefix="ajaxToolkit" Namespace="AjaxControlToolkit"
Assembly="AjaxControlToolkit" %>
<!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 runat="server">
<title>Show Filtered TextBox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Label
id="lblNumeric"
Text="Enter a Number:"
AssociatedControlID="txtNumeric"
Runat="server" />
<br />
<asp:TextBox
id="txtNumeric"
Runat="server" />
<ajaxToolkit:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtNumeric" FilterType="Numbers">
</ajaxToolkit:FilteredTextBoxExtender>
<br /><br />
<asp:Label
id="lblProductCode"
Text="Enter a Product Code:"
AssociatedControlID="txtProductCode"
Runat="server" />
<br />
<asp:TextBox
id="txtProductCode"
Runat="server" />
<br />
(A product code can contain only lower-case characters,
![enter image description here][1] underscores, exclamation marks, and no spaces)
</div>
</form>
</body>
</html>
iam using extender control..witfiltertype as numbers..but in doesnt works at runtime,, it accepts all characters..
any help would be appreciated
You are trying to make your code more complex. Actually the FilterTypeExtender is very easy to use. Follow this way. [Note: Close the appropriate controls properly.]
<asp:TextBox ID="txtExperienceYears" runat="server" Width="223px" MaxLength="2"></asp:TextBox>
<%-- Now add the FilterTypeExtender below --%>
<asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="txtExperienceYears" FilterType="Numbers"></asp:FilteredTextBoxExtender>

AjaxControlToolkit problem in asp.net

I am trying to set up ajaxConfirmButton Extender. Here is my code
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!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 runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<script language="javascript" type="text/javascript">
function onCancel()
{
var lblMsg = $get('<%=lblMessage.ClientID%>');
lblMsg.innerHTML = "You clicked the <b>Cancel</b> button of AJAX confirm.";
}
</script>
<asp:Label ID="Label1" runat="server" Text="Click this button to open AJAX Confirm box:" Font-Bold="true" Font-Size="16px"></asp:Label><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnConfirm" runat="server" Text="Confirm" OnClick="btnConfirm_Click" />
<ajaxToolkit:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" TargetControlID="btnConfirm"
ConfirmText="Are you sure?
You want to run the server code." OnClientCancel="onCancel" ConfirmOnFormSubmit="false">
</ajaxToolkit:ConfirmButtonExtender>
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
code behind
protected void btnConfirm_Click(object sender, EventArgs e)
{
lblMessage.Text = "You clicked the <b>OK</b> button of AJAX confirm";
}
But the confirm wondow is not coming. It is just performing the onclick action. Need help to fix this problem
You need to use ToolkitScriptManager instead of ScriptManager.
<ajaxToolkit:ToolkitScriptManager ID="ToolKitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
Hope it will help you

Resources