Ext.Net: radiogruop ,make selected radiobutton depend on its InputValue - asp.net

I have a radiogruop like this.
<ext:RadioGroup ID="rdyIsAktifmi" runat="server" FieldLabel="Aktifmi" Width="150"
Flex="1">
<Items>
<ext:Radio ID="Radio4" runat="server" BoxLabel="pasif" InputValue="0" />
<ext:Radio ID="Radio5" runat="server" BoxLabel="aktif" InputValue="1" />
</Items>
</ext:RadioGroup>
I save the cheched input value like this,
rdyIsAktifmi.CheckedItems[0].InputValue //0 or one depents on cheched item
however when binding it from code behind I failed.
I tryed this one :
rdyIsAktifmi.CheckedItems[0].Values = employee_obj.IsAktif;(this come from database as integer value)
I also tried this one :
rdyIsAktifmi.CheckedItems[0].Set("rdyIsAktifmi", employee_obj.IsAktif);
how I can select radiobutton depents on its InputValue.
**what I exactly looking for a methot something like this.
rdyIsAktifmi.CheckedItem.InputValue=employee_obj.IsAktif;
thank you .

I would achieve it this way.
<%# Page Language="C#" %>
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%# Import Namespace="System.Linq" %>
<script runat="server">
protected void Set0(object sender, DirectEventArgs e)
{
Radio r = this.RadioGroup1.Items.Cast<Radio>().First<Radio>(item => item.InputValue == "0");
r.Checked = true;
}
protected void Set1(object sender, DirectEventArgs e)
{
Radio r = this.RadioGroup1.Items.Cast<Radio>().First<Radio>(item => item.InputValue == "1");
r.Checked = true;
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:RadioGroup ID="RadioGroup1" runat="server" ColumnsNumber="1">
<Items>
<ext:Radio ID="Radio1" runat="server" BoxLabel="off" InputValue="0" />
<ext:Radio ID="Radio2" runat="server" BoxLabel="on" InputValue="1" />
</Items>
</ext:RadioGroup>
<ext:Button runat="server" Text="Set 0" OnDirectClick="Set0" />
<ext:Button runat="server" Text="Set 1" OnDirectClick="Set1" />
</form>
</body>
</html>

Related

ASP.NET Code behind not recognising control ID, error 'The name does not exist in current context'

I'm testing out some code that calculates the days by subtracting 2 dates and posting back the number of days in between.
Here is the first test:
CalculateDaysTest1.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CalculateDaysTest1.aspx.cs" Inherits="PopeyeMarinaWebApp.Templates.CalculateDaysTest1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Calculate Dates Test 1</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="formitem">
<asp:Label ID="startDateLabel" CssClass="formlabel" runat="server" Text="Start Date:"></asp:Label>
<asp:TextBox ID="txtStartDate" CssClass="DatePicker" runat="server" AutoPostBack="True" OnTextChanged="calculateDays"></asp:TextBox>
</div>
<div class="formitem">
<asp:Label ID="endDateLabel" CssClass="formlabel" runat="server" Text="End Date:"></asp:Label>
<asp:TextBox ID ="txtEndDate" CssClass="DatePicker" runat="server" AutoPostBack="True" OnTextChanged="calculateDays"></asp:TextBox>
</div>
<div class="formitem">
<asp:Label ID="totalDaysLabel" CssClass="formlabel" runat="server" Text="Number of Days:"></asp:Label>
<asp:Label ID="totalDays" CssClass="idlabel" runat="server" Text=""></asp:Label>
</div>
</div>
<script>
$(function () {
$('.DatePicker').datepicker(
{
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1950:2100'
});
})
</script>
</form>
</body>
</html>
CalculateDaysTest1.cs
using System;
namespace PopeyeMarinaWebApp.Templates
{
public partial class CalculateDaysTest1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void calculateDays(object sender, EventArgs e)
{
string startdate = txtStartDate.Text;
string enddate = txtEndDate.Text;
if (startdate != "" && enddate != "")
{
DateTime t1 = Convert.ToDateTime(startdate);
DateTime t2 = Convert.ToDateTime(enddate);
totalDays.Text = t2.Subtract(t1).Days.ToString();
}
}
}
}
Everything here is working perfectly and it's doing what it's supposed to be doing. You can select the start and end date and it posts back the calculated days.
Now for the second test I'm using it in the context of a Form View Control using model binding.
Here is Test 2:
CalculateDaysTest2.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CalculateDaysTest2.aspx.cs" Inherits="PopeyeMarinaWebApp.Templates.CalculateDaysTest2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Calculate Dates Test 2</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"/>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server"
ItemType="PopeyeMarinaWebApp.Models.Lease"
DataKeyNames="LeaseID"
RenderOuterTable="false"
DefaultMode="Insert"
InsertMethod="LeaseFormAdd_InsertItem">
<InsertItemTemplate>
<fieldset>
<div class="formitem">
<asp:Label ID="startDateLabel" CssClass="formlabel" runat="server" Text="Start Date:"></asp:Label>
<asp:TextBox ID="txtStartDate" CssClass="DatePicker" runat="server" AutoPostBack="True" OnTextChanged="calculateDays" Text="<%#: BindItem.StartDate %>"></asp:TextBox>
</div>
<div class="formitem">
<asp:Label ID="endDateLabel" CssClass="formlabel" runat="server" Text="End Date:"></asp:Label>
<asp:TextBox ID ="txtEndDate" CssClass="DatePicker" runat="server" AutoPostBack="True" OnTextChanged="calculateDays" Text="<%#: BindItem.EndDate %>"></asp:TextBox>
</div>
<div class="formitem">
<asp:Label ID="totalDaysLabel" CssClass="formlabel" runat="server" Text="Number of Days:"></asp:Label>
<asp:Label ID="totalDays" CssClass="idlabel" runat="server" Text=""></asp:Label>
</div>
<div class="col-lg-12">
<asp:Button ID="InsertButton" runat="server" Text="Insert" CausesValidation="True" CssClass="btn btn-primary btn-sm" CommandName="Insert" />
<asp:Button ID="CancelButton" runat="server" Text="Cancel" CssClass="btn btn-primary btn-sm" CommandName="Cancel"/>
</div>
</fieldset>
</InsertItemTemplate>
</asp:FormView>
</div>
<script>
$(function () {
$('.DatePicker').datepicker(
{
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1950:2100'
});
})
</script>
</form>
</body>
</html>
CalculateDaysTest2.cs
using System;
using PopeyeMarinaWebApp.Models;
namespace PopeyeMarinaWebApp.Templates
{
public partial class CalculateDaysTest2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void LeaseFormAdd_InsertItem()
{
var item = new Lease();
TryUpdateModel(item);
if (ModelState.IsValid)
{
using (MarinaDBContext db = new MarinaDBContext())
{
db.Leases.Add(item);
db.SaveChanges();
}
}
}
protected void calculateDays(object sender, EventArgs e)
{
string startdate = txtStartDate.Text;
string enddate = txtEndDate.Text;
if (startdate != "" && enddate != "")
{
DateTime t1 = Convert.ToDateTime(startdate);
DateTime t2 = Convert.ToDateTime(enddate);
totalDays.Text = t2.Subtract(t1).Days.ToString();
}
}
}
}
Here I'm getting an error in the calculateDays event which says:
'The name 'textStartDate' does not exist in the current context'
'The name 'textEndDate' does not exist in the current context'
'The name 'totalDays' does not exist in the current context'
I'm just wondering why this doesn't work within a Form View control and how can I fix it.
Any help would be much appreciated.
David
You've placed your code inside an "asp:FormView", which is preventing you from accessing your TextBox's etc directly in the code behind.
You'll need to setup something to handle commands from your FormView. In the code behind, you'll need something like this - although the example below is written off the top of my head.
void FormView1_ItemCommand(Object sender, FormViewCommandEventArgs e)
{
TextBox txtStartDate = (TextBox)e.Item.FindControl("txtStartDate");
if (e.CommandName == "Insert")
{
// Your logic here
}
}
Note you need to connect this code using the "OnItemCommand" property of your FormView on the aspx page.
See the MSDN documentation for a more extensive example.
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.itemcommand(v=vs.110).aspx
As for accessing the TextBox's anywhere in the code behind, you'll need to use the FindControl method on the FormView. Something like one of these:
TextBox txtStartDate = (TextBox)FormView1.Row.FindControl("txtStartDate");
Or
TextBox txtStartDate = (TextBox)FormView1.InsertItem.FindControl("txtStartDate");

Error on String.Format

I get an "Object reference not set to an instance of an object." error on the line "welcome.Text = ...."
Home:
protected void OKButton_Click(object sender, EventArgs e)
{
if (UserNameTextBox.Text != String.Empty)
{
Session["UserName"] = UserNameTextBox.Text;
Label welcome = (Label)Master.FindControl("GreetingLabel");
welcome.Text = String.Format("Welcome, {0}!", Session["UserName"]);
}
}
<%# Page Title="" Language="C#" MasterPageFile="~/Professional.master" AutoEventWireup="true" CodeFile="Home.aspx.cs" Inherits="Home"%>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<br /><br />
<asp:TextBox ID="UserNameTextBox" runat="server"></asp:TextBox>
<br /><br />
<asp:DropDownList ID="SitePrefDropDownList" runat="server" AutoPostBack="True">
<asp:ListItem Text="Professional" Value="Professional"></asp:ListItem>
<asp:ListItem Text="Colourful" Value="Colourful"></asp:ListItem>
</asp:DropDownList>
<br /><br />
<asp:Button ID="OKButton" runat="server" Text="OK" onclick="OKButton_Click" />
</asp:Content>
I got the code from MCTS Exam 70-515 Web Dev book.
I looked at the Errata page, no luck. http://oreilly.com/catalog/errataunconfirmed.csp?isbn=9780735627406
Master Page:
public partial class Professional : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] != null)
{
GreetingLabel.Text = String.Format("Welcome, {0}!", Session["UserName"]);
}
}
}
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Professional.master.cs" Inherits="Professional" %>
<!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>
<asp:ContentPlaceHolder id="HeadContent" runat="server">
</asp:ContentPlaceHolder>
<link href="~/Styles/Site.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Contoso.gif" /><asp:Label ID="Label1" runat="server" Text="Welcome to Contoso!"
Font-Size="X-Large"></asp:Label>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<Items>
<asp:MenuItem Text="Products" Value="Products"></asp:MenuItem>
<asp:MenuItem Text="Services" Value="Services"></asp:MenuItem>
<asp:MenuItem Text="Downloads" Value="Downloads"></asp:MenuItem>
<asp:MenuItem Text="About Us" Value="About Us"></asp:MenuItem>
</Items>
</asp:Menu>
<asp:ContentPlaceHolder id="MainContent" runat="server">
<asp:Label ID="GreetingLabel" runat="server" Text="Label"></asp:Label>
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Regards
LF
Where is the GreetingLabel control located in the master? If it's in a ContentPlaceHolder the NamingContainer is that not the master.
You: "it is in a Master, under":
<asp:ContentPlaceHolder id="MainContent" runat="server">
That's it, you first have to find the ContentPlaceHolder, then use FindControl on it:
var cPlaceHolder = (ContentPlaceHolder)Master.FindControl("MainContent");
Label welcome = (Label)cPlaceHolder.FindControl("GreetingLabel");
Now you don't get a NullReferenceException on welcome.Text anymore:
welcome.Text = String.Format("Welcome, {0}!", Session["UserName"]);
Edit Since you have commented that it still doesn't work for whatever reason. I will suggest a different - better - approach. Provide a public property in your Master, for example Greeetings. Then you can get/set the Label.Text via this property. That is much more readable and maintainable. It will also work even if you change the label to a different control like TextBox or Div.
For example (in the MasterPage of type Professional):
public string Greetings
{
get { return GreetingLabel.Text; }
set { GreetingLabel.Text = value; }
}
Now you can cast the Master property in your content-page to Professional to access it:
Professional professional = (Professional) this.Master;
professional.Greetings = String.Format("Welcome, {0}!", Session["UserName"]);
Try this:
see this
welcome.Text = String.Format("Welcome, {0}!", Session["UserName"]);// replace Session["UserName"] with Session["UserName"].ToString()
now your new line is
welcome.Text = String.Format("Welcome, {0}!", Session["UserName"].ToString());

How to fire direct event in row editing in gridpanel in ext.net

i'm using VB.net with ext.net (version 1.6).
i have a Gridpanel where i can double click on a row in order to edit it.
I can successfully edit it, but i need a direct event to be called whenever i finish editing ( in order to update the row in my database ).
I tried :
<ext:Column ColumnID="Name" dataindex="Name" Header="Field" Width="210" >
<Editor>
<ext:TextField ID="TextField00" runat="server" />
</Editor>
</ext:Column>
and outside of the column :
<DirectEvents>
<AfterEdit OnEvent="UpdateFieldValue"></AfterEdit>
</DirectEvents>
thanks
It works in this example.
<%# Page Language="C#" %>
<%# Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.GridPanel1.GetStore();
store.DataSource = new object[]
{
new object[] { "test1" },
new object[] { "test2" },
new object[] { "test3" }
};
store.DataBind();
}
}
protected void GridPanel_AfterEdit(object sender, DirectEventArgs e)
{
X.Msg.Alert("GridPanel_AfterEdit", "Hello from Server!").Show();
}
</script>
<!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>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
<Store>
<ext:Store runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="test" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel runat="server">
<Columns>
<ext:Column Header="Test" DataIndex="test">
<Editor>
<ext:TextField runat="server" />
</Editor>
</ext:Column>
</Columns>
</ColumnModel>
<DirectEvents>
<AfterEdit OnEvent="GridPanel_AfterEdit" />
</DirectEvents>
</ext:GridPanel>
</form>
</body>
</html>
Hope this helps.

Why The error message for custom validator is not shown in message box?

I have tried in many way but the error message for custom validator is not shown in validation summary but it(ValidationSummary) shows error message for every other type of validator.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Expt_Custom Validator.aspx.cs" Inherits="Expt_Custom_Validator" %>
<!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>
<script runat="server">
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (args.Value.Equals("Jagdeep"))
args.IsValid = false;
else
args.IsValid = true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblName" runat="server" Text="Enter Your Name"></asp:Label>
<asp:TextBox ID="txtbxName" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ErrorMessage="You are Not allowed" Display="None"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
<br />
<asp:Label ID="lblClass" runat="server" Text="Class"></asp:Label>
<asp:TextBox ID="txtClass" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Please enter Clas" ControlToValidate="txtClass" Display="None"></asp:RequiredFieldValidator>
<br />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server" Text="Validate" />
</div>
</form>
</body>
</html>
Custom Validator, when placing in formview will not show its error message after server-side validation (though it has been validated and result is invalid) the mean to fix this in to wrap it by a Update Panel.
I solved this issue by registering a client script block, which updates the validation summary content. I have used jQuery for this:
private void DisplayCustomValidationMessage(CustomValidator cv, ValidationSummary vs)
{
if ((cv == null) || (vs == null)) return;
Type csType = this.GetType();
if (ClientScript.IsClientScriptBlockRegistered(csType, cv.ID)) return;
StringBuilder sb = new StringBuilder(#"<script type='text/javascript'>");
sb.Append(#"$(function () {");
sb.Append(#"var $vs = $('#" + vs.ClientID + "');");
sb.Append(#"if($vs.find('ul').length){");
sb.Append(#"$vs.find('ul').append('<li>" + cv.ErrorMessage + "</li>');");
sb.Append(#"}else{");
sb.Append(#"$vs.html('Fehlerhafte Eingabe(n):<ul><li>" + cv.ErrorMessage + "</li></ul>'); }");
sb.Append(#"$vs.css('display', 'block');");
sb.Append(#"});");
sb.Append(#"</script>");
ClientScript.RegisterClientScriptBlock(csType, cv.ID, sb.ToString());
}
The method has to be called if validation fails:
protected void cvYourCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = YourCustomValidationMethod();
if (!args.IsValid)
{
DisplayCustomValidationMessage((CustomValidator) source, vsYourValidationSummaryControl);
}
}

ModalPopupExtender and validation problems

The problem I am facing is that when there is validation on a page and I am trying to display a model pop-up, the pop-up is not getting displayed. And by using fire-bug I have noticed that an error is being thrown.
The button that is used to display the pop-up has cause validation set to false so I am stuck as to what is causing the error.
I have created a sample page to isolate the problem that I am having, any help would be greatly appreciated.
The Error
function () {Array.remove(Page_ValidationSummaries, document.getElementById("ValidationSummary1"));}(function () {var fn = function () {AjaxControlToolkit.ModalPopupBehavior.invokeViaServer("mpeSelectClient", true);Sys.Application.remove_load(fn);};Sys.Application.add_load(fn);}) is not a function
http://localhost:1131/WebForm1.aspx
Line 136
ASP
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CLIck10.WebForm1" %>
<%# 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></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:Button ID="btnPush" runat="server" Text="Push" CausesValidation="false" onclick="btnPush_Click" />
<asp:TextBox ID="txtVal" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtVal" ErrorMessage="RequiredFieldValidator" />
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:Panel ID="pnlSelectClient" Style="display: none" CssClass="box" runat="server">
<asp:UpdatePanel ID="upnlSelectClient" runat="server">
<ContentTemplate>
<asp:Button ID="btnOK" runat="server" UseSubmitBehavior="true" Text="OK" CausesValidation="false" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<input id="popupDummy" runat="server" style="display:none" />
<ajaxToolkit:ModalPopupExtender ID="mpeSelectClient" runat="server"
TargetControlID="popupDummy"
PopupControlID="pnlSelectClient"
OkControlID="popupDummy"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancel"
DropShadow="true" />
</div>
</form>
Code Behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CLIck10
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnOK_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnCancel_Click(object sender, EventArgs e)
{
mpeSelectClient.Hide();
}
protected void btnPush_Click(object sender, EventArgs e)
{
mpeSelectClient.Show();
}
}
}
This is an issue with using both ValidationSummary and ModalPopup.
see here: http://ajaxcontroltoolkit.codeplex.com/WorkItem/View.aspx?WorkItemId=12835
The problem is that there is a missing ";" between the two injected scripts.
Their solution is to create/use a custom server control that inherits from ValidationSummary, that injects a ";" into the page startup script to fix the bug:
[ToolboxData("")]
public class AjaxValidationSummary : ValidationSummary
{
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), this.ClientID, ";", true);
}
}
Try setting your ValidationSummary "Enabled" property to false on this event : "btnPush_Click"
; and then setting it back to enabled = "true" on this events : "btnOK_Click" ,"btnCancel_Click".
I think this will work if you do not have the validation summary inside the Panel that you want to pop up.But it is not a solution if you need the validation summary inside the pop up panel,...witch is my case :(.
Best Regards.
I tried all the available answer online but didn't worked any. Then i tried to move my modal popup extender at very end of the HTML and it works fine for me. Me and my users are Happy :)
I am not using FROM tag I am using Content place holder just like below:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<table id="tblMessage" runat="server" width="100%" >
<tr align="center">
<td align="center">
main content and
<asp:Panel ID="pnlSelectClient" Style="display: none" CssClass="box" runat="server">
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<asp:UpdatePanel ID="upnlSelectClient" runat="server">
<ContentTemplate>
<asp:Button ID="btnOK" runat="server" UseSubmitBehavior="true" Text="OK" CausesValidation="false" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CausesValidation="false" OnClick="btnCancel_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
If you notice i have validation summary inside the panel because i want error message inside the pop up(i have some additional control in pop up too). and
Some more HTML tag here as i have so many other things to do in one page. right before closing tag of TABLE
<ajaxToolkit:ModalPopupExtender ID="mpeSelectClient" runat="server"
TargetControlID="popupDummy"
PopupControlID="pnlSelectClient"
OkControlID="popupDummy"
BackgroundCssClass="modalBackground"
CancelControlID="btnCancel"
DropShadow="true" />
</table>
Done.it's working. Hope that works for other too.
Are you using validation groups anywhere on the page? I've had problems with control events not firing when they are not part of a validation group and other controls on the page are part of a validation group.
I'd try changing this:
<input id="popupDummy" runat="server" style="display:none" />
to something like this:
<asp:Button id="popupDummy" runat="server" CausesValidation="false" Visible="false" />
I bet the untyped input is requiring validation.
i had the same issue, adding ValidationGroup to the validation controls did the trick!
One other thing to try, if you don't need Client Script you can disable it in the markup. Doing that fixed our problem.
EnableClientScript="false"

Resources