AjaxControlToolkit problem in asp.net - 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

Related

Update Panel Not working For Checkbox

In the below code Changing asyncPostBackTrigger to PostBackTrigger causing the entirepage postback.
But the below code is not at all doing anything when we use the trigger as asyncPostBackTrigger.
Any suggestions about what I am doing wrong??
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" ID="UpdatePanel_1" >
<ContentTemplate>
<asp:CheckBox ID="chkNotKnown" runat="server" AutoPostBack="True"
Text="(Not Known)" OnCheckedChanged="chkNotKnown_CheckedChanged"/>
</ContentTemplate>
<Triggers>
<asp:asyncPostBackTrigger ControlID="chkNotKnown"/>
</Triggers>
</asp:UpdatePanel>
<asp:TextBox ID="txtDrCode" runat="server" OnFocus="this.style.borderColor='red'" OnBlur="this.style.borderColor=''"></asp:TextBox>
</form>
</body>
</html>
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub chkNotKnown_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkNotKnown.CheckedChanged
With txtDrCode
If chkNotKnown.Checked Then
.Text = "Not Known"
.Enabled = False
Else
.Text = ""
.Enabled = True
End If
End With
End Sub
End Class
The chkNotKnown is inside the UpdatePanel, while txtDrCode is outside of it. Also you specify chkNotKnown as an asyncPostBackTrigger, which is the same as something already present in the UpdatePanel.
So either change the Trigger to a PostBackTrigger (causing a full PostBack)
<Triggers>
<asp:PostBackTrigger ControlID="chkNotKnown" />
</Triggers>
Or place the TextBox inside the UpdatePanel
<asp:UpdatePanel runat="server" ID="UpdatePanel_1">
<ContentTemplate>
<asp:CheckBox ID="chkNotKnown" runat="server" AutoPostBack="True"
Text="(Not Known)" OnCheckedChanged="chkNotKnown_CheckedChanged" />
<asp:TextBox ID="txtDrCode" runat="server"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>

Asp.net Image Button does not have an onClick event

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

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>

Use updatepanel to load child page without page refresh

This is my Default.aspx
<%# Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html>
<script runat="server">
Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
ScriptManager1.RegisterAsyncPostBackControl(HyperLink1)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Panel Created"></asp:Label>
<asp:HyperLink NavigateUrl="Default2.aspx" ID="HyperLink1" runat="server">HyperLink</asp:HyperLink>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
I want that when a user clicks on the HyperLink , content from another .aspx page gets loaded in the Default.aspx without full page refresh
You can manually update your updatepanel from javascript.
Here you have the example:
How to refresh an UpdatePanel from javascript

Element 'ToolkitScriptManager' is not a known element

So I have a file called WebParts.aspx which looks like this -
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebParts.aspx.cs" Inherits="e.WebParts" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:TabContainer ID="TabContainer1" runat="server">
<asp:TabPanel ID="TabPanel1" runat="server">
<ContentTemplate>Page One</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server">
<ContentTemplate>Page Two</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel3" runat="server">
<ContentTemplate>Page Three</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</div>
</form>
</body>
</html>
And that produces the desired results of creating 3 tab panels inside a tab container.
However, when I change that page to use a MasterPage.master to look like this -
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebParts.aspx.cs" Inherits="eservice.WebParts" MasterPageFile="~/MasterPage.Master"%>
<asp:Content ID="Content2"
ContentPlaceHolderID="ContentPlaceHolder1"
runat="server">
<asp:LoginView ID="LoginView1" runat="server">
<LoggedInTemplate>
<p id="backtoblog"></p>
<p> Preferences</p>
<div>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:TabContainer ID="TabContainer1" runat="server">
<asp:TabPanel ID="TabPanel1" runat="server">
<ContentTemplate>Page One</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel2" runat="server">
<ContentTemplate>Page Two</ContentTemplate>
</asp:TabPanel>
<asp:TabPanel ID="TabPanel3" runat="server">
<ContentTemplate>Page Three</ContentTemplate>
</asp:TabPanel>
</asp:TabContainer>
</div>
</div>
</LoggedInTemplate>
<AnonymousTemplate>
You are not logged in.
<br />
Please login to access eservice
</AnonymousTemplate>
</asp:LoginView>
</asp:Content>
VS2008 gives me the following warning:
Element 'ToolkitScriptManager' is not
a known element. This can occur if
there is a compilation error in the
Web site, or the web.config file is
missing.
on the following line:
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
Your second file does not contain the line
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
which you have in your first file. Just because the master page knows about the asp: prefix and the assembly/namespace you've associated to it, doesn't mean that the child page does.
A better approach would be to register the assembly/namespace/tag prefix inside your web.config, like so:
<configuration>
<!-- ... -->
<system.web>
<!-- ... -->
<pages>
<controls>
<add tagPrefix="asp"
namespace="AjaxControlToolkit"
assembly="AjaxControlToolkit" />
</controls>
</pages>
</system.web>
</configuration>
Element 'ToolkitScriptManager' is not a known element. This can occur
if there is a compilation error in the Web site, or the web.config
file is missing.
Just in case someone runs across this. The fix for me, was that the imported project properties pointed to 4.5.2 framework. I selected an older framework, and then selected 4.5.2 again. This got rid of the mentioned error along with dozens of others.

Resources