Button Event not firing when use Ajax Extender in form [Resolved]

Posted by Tg under ASP.NET AJAX on 11/1/2012 | Points: 10 | Views : 3187 | Status : [Member] | Replies : 28
Hi,
I am using Ajax Extenders in my form for many Textbox.Now,button click event not firing when i insert data.
I tried using validation group and updatepanel but its not working.But i want to validate the Textbox value which user insert.
Cause validation=false its not a solution .




Responses

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,
If we have two sets of form elements and if we want to validate them separately, we can follow this validation group approach.
Once try below code.
ASPX:

<fieldset>
<legend><b>User Login</b></legend>
<p>
Username:
<asp:TextBox ID="txtUserName" runat="server" ValidationGroup="LoginForm1" />
<asp:RequiredFieldValidator ID="req1" runat="server" ErrorMessage="Mandatory !" ForeColor="Red"
ControlToValidate="txtUserName" ValidationGroup="LoginForm1" />
</p>
<p>
Password:
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" ValidationGroup="LoginForm1" />
<asp:RequiredFieldValidator ID="req2" runat="server" ErrorMessage="Mandatory !" ForeColor="Red"
ControlToValidate="txtPassword" ValidationGroup="LoginForm1" />
</p>
<asp:Button ID="btnSubmit" runat="server" Text="Login" OnClick="SubmitData1" ValidationGroup="LoginForm1" />
</fieldset>
<fieldset>
<legend><b>Admin Login</b></legend>
<p>
Username:
<asp:TextBox ID="txtAUserName" runat="server" ValidationGroup="LoginForm2" />
<asp:RequiredFieldValidator ID="req3" runat="server" ErrorMessage="Mandatory !" ForeColor="Red"
ControlToValidate="txtAUserName" ValidationGroup="LoginForm2" />
</p>
<p>
Password:
<asp:TextBox ID="txtAPassword" runat="server" TextMode="Password" ValidationGroup="LoginForm2" />
<asp:RequiredFieldValidator ID="req4" runat="server" ErrorMessage="Mandatory !" ForeColor="Red"
ControlToValidate="txtAPassword" ValidationGroup="LoginForm2" />
</p>
<asp:Button ID="btnASubmit" runat="server" Text="Login" OnClick="SubmitData2" ValidationGroup="LoginForm2" />
</fieldset>

Code Behind:
protected void SubmitData1(object sender, EventArgs e)

{
Response.Write(" Success");
}
protected void SubmitData2(object sender, EventArgs e)
{
Response.Write("Success");
}



Thanks & Regards

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..

once try this code...Definitely will help.

<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1"
ValidationGroup="Group1" runat="server" ErrorMessage="TextBox1 is required." />
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox2"
ValidationGroup="Group2" runat="server" ErrorMessage="TextBox2 is required." />
<br />
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="TextBox3"
ValidationGroup="Group3" runat="server" ErrorMessage="TextBox3 is required." />
<br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return Validate()" />
<script type="text/javascript">
function Validate() {
var isValid = false;
isValid = Page_ClientValidate('Group1');
if (isValid) {
isValid = Page_ClientValidate('Group2');
}
if (isValid) {
isValid = Page_ClientValidate('Group3');
}
return isValid;
}
</script>
</form>

With Regards,
sravya

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi..
Once Refer this below link..It will help
http://www.dotnetspider.com/resources/43508-How-create-Slider-ASP-NET-using-AJAX.aspx

With Regards,
Sravya

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply.I will check and tell you.

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sravya,

It is not working.
I paste my sample Code here.
-----------------------This is my TextBox--------------------
<asp:TextBox ID="Name" runat="server" Height="18px" Width="186px" MaxLength="10" CssClass="txtbx"></asp:TextBox>
----------------------------------------------------------------------
------------------------This is my Validator-------------------
<asp:RequiredFieldValidator ID="Name" runat="server" ControlToValidate="Name" Display="None"
ErrorMessage="Please Enter Name" ValidationGroup="s">
</asp:RequiredFieldValidator>
-----------------------------------------------------------------------

----------------------This is my Ajax Extender----------------
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" Enabled="True" TargetControlID="Name">
</asp:ValidatorCalloutExtender> --Its for pop up display----
------------------------------------------------------------------------
<asp:Button ID="btnsave" runat="server" onclick="btnsave_Click" Text="Save"
AutoPostBack="True" CssClass="but1" ValidationGroup="s" OnClientClick="return Validate()" />

Here I put Cause Validation =False .Button is Firing.But I put true means validation is working and button not firing.For Entire page i used like this only.
And I used Filtered textbox Extender and CalenderExteder whether for this also i have to put validation group.
Because its not validation control.
I need an immediate reply from you.I hope u have solution for this.
Regarding any doubt please ask me .

Regards,
Prakash


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

Here above i put my sample code.please verify it.I used Required Field validator and also ValidateCallout Extender .

Regards
Prakash


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,
You used two onclicks in one button control. Thats why you are not able to fire. Check by keeping only onclick i.e Either onclick or onclientclick.
Try like that.

Thanks & Regards

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default12.aspx.cs" Inherits="Default12" %>


<!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>
<script type="text/javascript" language="javascript"> function Validate() {
alert("Hi");
}</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Name" runat="server" Height="18px" Width="186px" MaxLength="10"
CssClass="txtbx"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="Name"
Display="None" ErrorMessage="Please Enter Name" ValidationGroup="s">
</asp:RequiredFieldValidator>
<%-- <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server" Enabled="True"
TargetControlID="Name">
</asp:ValidatorCalloutExtender>--%>
<asp:Button ID="btnsave" runat="server" Text="Save" AutoPostBack="True"
CssClass="but1" ValidationGroup="s" OnClientClick="return Validate()" />
</div>
</form>
</body>
</html>

I used your code and i commented your ajax extendercoz present I dont have ajax dll in my solution

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

I must use Ajax extender in my page.
Bcoz Its my requirement.I have reason why its not firing bcoz when i click its also check that extenders also.
Without Extenders Its running.my problem is with extender its not firing.

And one more I dint use form in my page directly i gave <div> instead of that.whether this is problem ah.

Thanks & Regards
Prakash

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
And Remove display=none in your required field validator.

Thanks & Regards


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

how can i use one click.
I used one for my event and one for script.


Thanks

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
If you want to show error message to the user , You remove that display=none. And sorry I dont have ajax dll.

Thanks & Regards

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Yes, We can use two clicks. When I tried First Alert Message came and next error message displayed.

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
And, Did you use This scriptManger in your page?
<asp:ScriptManager runat="server" ID="SM1" />

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
And, Did you use This scriptManger in your page?
<asp:ScriptManager runat="server" ID="SM1" />

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

I used Master Page and in master page i used ScriptManager .
Its common for all pages.


Thanks


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Once try this one

Put autopostback = true

Page.IsValid= true in the code behind before you do onclick event

kindly let me know whether it works for you or not

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab ,

Here below i put entire code.
I didnt use update panel.I just used Calender Extender to display calender ,Filtered Extender for Text box to Filter values as numbers and validate Callout Extender for Requirefield validation .
Please find any solution for this.
i am facing this prob for long days.

Thanks and
Regards
Prakash

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sravya on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Please Refer this link...you find out sol
http://www.c-sharpcorner.com/UploadFile/364074/validatorcalloutextender-control-in-ajax/

With Regards,
Sravya

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi tg, I tried by adding ajax dll. The modification I have done is ,TargetControlId of ValidatorCalloutExtender I mentioned the Id of Requiredfieldvalidator not the Id of textbox.I have attached the file and also image. Once Download Source code and try. I have attached the image of which I got output. Once checkout.

Thanks & Regards
 Download source file

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sravya,

Thanks for your reply.once i try and tell.

Thanks
Prakash


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

I m aslo put Target is my Required Field validator Id only.I m using large form.In the form nearly 21 textboxes is there.for each Textbox i used Required Field validator for nearly 10 text box and some five text box i used Filtered Extender and only one text box i used Calender Extender.
But when i used Required means in that box i didnt use Filtered again .
I mean if validatecallout i m using for text box means i didnt use filtered Extender for that.

I think u understand my prob.If u need means i place my code here.


Thanks
Prakash


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Please can you attatch your source code?

Thanks & Regards

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

Please find attachment.i send only design source only.
I changed some lbl and Textbox names.
But i used correct referencfe for each validator.
Please refer this and reply me soon.


Thanks
Prakash
 Download source file

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab ,

I used javascript for checking date only and used compare validator for 4 textboxes for this also i used validate callout extender.
plese verify it and tell the solution for this.
Give me ur mail id .I ll send it my code behind also .

Thanks.Prakash

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandhyab on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Click on Reply with attchment. If You Attach here others will also try to resolve your problem

Thanks & Regards

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/23/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

I asked if u need i ll attach.Bcoz i dint use any validation in codebehind File.Entire validation happen in .aspx only.
did u see my attachment with previous reply.

Thanks
Prakash

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 11/24/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Sandhyab,

If u find any idea to solve this pls share .
If anybody find solution for this pls share .

Thanks
Prakash

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response