Showing posts with label panel. Show all posts
Showing posts with label panel. Show all posts

Wednesday, March 28, 2012

dinamically adding a webuser control to a Modal Pop Up Extender

I have a page that has two buttons and a text box on it. It also has a panel named pnlPopUp and an modalpopupextender which has 'pnlPopUp' as the PopupControlID.

If you Click Button1 it will display webusercontrol1 and if you click button2 it will display webusercontrol2.

Each user control has two buttons on tem (btnOK and btnCancel).

The web user controls are added dinamically to the panel when I click button1 or button2 (using Page.LoadControl("~/WebUserControl.ascx") andpnlPopup.Controls.Add(webusercontrol) );

I am trying to fill the text of teh textbox in the page according to which button is clicked on the pop-up (if I click Ok it writes "OK" in the textbox),

but my button events aren′t firing!


P.S.: If I load the controls in the page′s Page_Load and making them visible when I need them it will work fine but I didn′t want to do that because in my actual web site i will have too many user controls.

Here′s the sample code. (I′m using the exact code for both user controls):

==================== Default.aspx=============================

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@dotnet.itags.org. Register src="http://pics.10026.com/?src=~/WebUserControl.ascx" TagName="WebUserControl" TagPrefix="wuc" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<link rel="stylesheet" href="http://links.10026.com/?link=back.css" type="text/css" media="screen" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="true">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="btnPopup" runat="server" Text="PopUp" />

<input type="hidden" runat="server" id="hdnPopUp" />

<asp:Panel ID="pnlPopUp" runat="server" CssClass="modalPopup">
</asp:Panel>

<cc1:ModalPopupExtender ID="mpeTestePopUp" runat="server" TargetControlID="hdnPopUp"
PopupControlID="pnlPopUp" DropShadow="true" BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

===========================================================

==================== Default.aspx.cs============================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AjaxControlToolkit;

public partial class _Default : System.Web.UI.Page
{
WebUserControl ucTestePopUp;

protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnPopup.Click += new EventHandler(btnPopup_Click);
}

void btnPopup_Click(object sender, EventArgs e)
{
ucTestePopUp = (WebUserControl)Page.LoadControl("~/WebUserControl.ascx");
this.pnlPopUp.Controls.Add(ucTestePopUp);
this.mpeTestePopUp.Show();
}
}

============================================================

==================== WebUserControl.ascx============================

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<table>
<tr>
<td>
<asp:Button runat="server" ID="btnSim" Text="Sim" />
</td>
<td>
<asp:Button runat="server" ID="btnNao" Text="Nao" />
</td>
</tr>
</table>

==================================================================

==================== WebUserControl.ascx.cs============================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}

void Page_Init(object sender, EventArgs e)
{
this.btnSim.Click += new EventHandler(btnSim_Click);
this.btnNao.Click += new EventHandler(btnNao_Click);
}

protected void btnNao_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou N?o";
}

protected void btnSim_Click(object sender, EventArgs e)
{
((TextBox)this.Parent.FindControl("txtTeste")).Text = "Clicou Sim";
}
}

=================================================================

Hi,

to handle events you need a control with an event handler to instantiated. If you only load your user control once in the click event handler, the button (textbox) in your user control does not exist on the page when postback caused by this button in user control is processed at the server.

Therefore, as you said you need to load your user control in page_load to handle events.

However, you don't need to load all controls. You just need to remeber which control was created last time and create this single control. You can store this information in the ViewState property.

Once you handled events from controls insode user control you can safely remove it from the page.

ALSO: You need to assign ID to your dynamically loaded user control. Otherwise, you will occasionally get problems with events firing from the second click.

-yuriy
http://couldbedone.blogspot.com

Difference Between Panel Extender and Accordion

What is the difference between the two other than the accordion can handle more areas to expand? Is it because it actually uses the panel control? I'm trying to think of why I would use one over the other. Thank you for ideas.Hi just_for_forums,

The difference between the CollapsiblePanel and the Accordion is the number of sections you want to have. The Accordion is like a CollapsiblePanel with multiple sections that can have ONLY ONE open at a time. That's pretty much the difference.

Thanks,
Ted

Hello Ted,

I have tried to use Collapsible panel with my page but because of the flickering of the page I will try to use accordion. Does accordion extender support <panel> and <updatepanel> inside its <content> tag>??

Thanks

difference b/w Postbacktrigger & Asycpostbacktirgger in AJAX Panel ?

hi all, what is the difference b/w Postbacktrigger & Asycpostbacktirgger in AJAX Panel ?

PostBackTrigger forces full (regular) postback by contol inside an update panel with ChildrenAsTriggers == true.

AsyncPostBackTrigger makes control to initiate async (partial rendering) postabck.

-yuriy

Monday, March 26, 2012

Determine what element caused the Postback when handling the endRequest event

Hi All,

I have an UpdatePanel with 2 buttons. Pressing either of them causes a Postback and the panel gets refreshed.

I'm handling the endRequest event on the client side. Is there a way to determine which of the page elements caused the Postback?

Thanks,

Uzi

Try here:

http://www.eggheadcafe.com/articles/20050609.asp


Hi,

you can determine the postback element on the client side with the PageRequestManager. Attach to the beginRequest event and you can save the postback control. More information here:

http://ajax.asp.net/docs/ClientReference/Sys.WebForms/BeginRequestEventArgsClass/default.aspx

Regards
Marc André


Here is a neat way to get it done:

In the 'BeginRequest' event handler insert the postback element to the UserContext of the WebRequest:

function BeginRequestHandler(sender, args)

{

var elemName = args.get_postBackElement().id;var request = args.get_request();

request.set_userContext(elemName);

}

Then, when the request ends, at the 'EndEvent' get the information from the Response object:

function EndRequestHandler(sender, args)

{

var response = args.get_response();

alert(response._webRequest.get_userContext());

}

Thanks,

Uzi

Saturday, March 24, 2012

Deployment on production server : Ajax does not function; on local WorkStation is Ok

Hello,

I have just put to me to the AJAX, I installed it well on my PC, my ajax project with "Update Panel" functions locally.

I put it in production, I put the extensions in [bin]: "AjaxControlToolkit.dll"; System.Web.Extension is quite present in the GAC and when I click on the button to refresh the "update panel" in which a label update yourself. a traditional PostBack of alll the page is carried out! as if there were no Ajax!!?

Help me!


En fran?ais :

Bonjour,

Je viens de me mettre à l'AJAX, je l'ai bien installé sur mon poste, mon projet ajax avec un Update Panel fonctionne en local.

Je le mets en production, j'ai mis les extensions dans [bin] :
"AjaxControlToolkit.dll", System.Web.Extension est bien présent dans le GAC

et quand je clique sur le bouton pour rafraichir l'update panel dans lequel un label se mets à jour. un rafraichissement classique de toute la page s'effectue! comme si il n'y avait pas d'Ajax!!?

un peu d'aide ne serait pas de refus!

The first think I will ask you is to make sure the same version of Ajax is installed on the production server. I know it may sound silly, but I know several people with similar problem and they claim that they have the same version, but when they take a deeper look, they notice that there was not the same.

Deny a collapsible Panel Extender from collapsing if required field validators arent valid

Hi all,

I am using an collapsible Panel Extender that has a panel with textboxes used for sending a message.

When a user needs to send a message he expands the panel then fills in the boxes and presses the send button that

will send the message and collapse the panel as well.

I want to prevent the panel from collapsing if the required field validators are not valid.

I am not that great in javascript so please try and elaborate as much as possible.

Thanks.

Hi Itay,

Itay molecule:

I am not that great in javascript so please try and elaborate as much as possible.

Is is this javascript that collapses the panel?

Here is some javascript code that checks on the clientside if the page is valid. Merge this code with your javascript ;)

 <script type="text/javascript"> function checkValidity() { if (Page_ClientValidate() == false) {//handle the fact that some controls are not valid! } } </script>

If you have questions/remarks please do so!
Kind regards,
Wim


Would it be a solution to use a little updatepanel for an async postback allowing you (the server) to either:

- disable or hide the ExpandControlID ?

- (temporarily) change the target control id of the CollapsiblePanelExtender to a hidden button (style="display:none;") ?


Actually this is not an option because my collapse button is the "send" button that is supposed to check the validation

of the form.


Hi Itay,

Itay molecule:

Actually this is not an option because my collapse button is the "send" button that is supposed to check the validation

of the form.

My solution will do!
If you allow javascript in the browser offcourse.

Give me your panelcode and I'll show you what to adapt!

Kind regards,
wim


Wim Hi,

My reply wasn't ment for you i am sure your solution is the way to do it.

Here is my code thanks alot for the help.

c#

protectedvoid ImageButton1_Click(object sender,ImageClickEventArgs e)

{

sendmail sendusamail =newsendmail();

sendusamail.sendmail1(Subject.Text + "from: " + From.Text );

}

ASPX

<body>

<formid="form1"runat="server">

<div>

<asp:ScriptManagerID="ScriptManager1"runat="server">

</asp:ScriptManager>

<asp:ImageButtonID="ImageButton1"runat="server"ImageUrl="~/animalsbusinessid/c2a1_66.png"OnClick="ImageButton1_Click1"CausesValidation="False"/>

<asp:PanelID="Panel1"runat="server"Height="7px"Width="376px"Direction="RightToLeft"HorizontalAlign="Center">

<asp:LabelID="Label1"runat="server"Font-Bold="True"></asp:Label>

<asp:TextBoxID="From"runat="server"Columns="23"></asp:TextBox><br/>

<asp:TextBoxID="UsersEmail"runat="server"Columns="23"></asp:TextBox>

<asp:TextBoxID="Subject"runat="server"Columns="23"></asp:TextBox>

<asp:TextBoxID="Body"runat="server"Columns="30"Rows="8"TextMode="MultiLine"></asp:TextBox>

<br/>

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="UsersEmail"

Display="Dynamic"ErrorMessage="please fill in your address"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="From"

Display="Dynamic"ErrorMessage="please fill in your name"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator>

<asp:RequiredFieldValidatorID="RequiredFieldValidator3"runat="server"ControlToValidate="Body"

Display="Dynamic"ErrorMessage="write your message"Font-Bold="False"Font-Size="13px"></asp:RequiredFieldValidator><br/>

<asp:ImageButtonID="ImageButton2"runat="server"ImageUrl="~/animalsbusinessid/mailto_10.png"OnClick="ImageButton1_Click"/>

<asp:RegularExpressionValidatorID="RegularExpressionValidator1"runat="server"ControlToValidate="UsersEmail"

Display="Dynamic"ErrorMessage="this is not a valid email address"Font-Bold="False"Font-Size="13px"ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></asp:Panel>

</div>

<ajaxToolkit:CollapsiblePanelExtenderID="cpe"runat="server"

TargetControlID="Panel1"

CollapsedSize="30"

ExpandedSize="500"

Collapsed="True"

ExpandControlID="ImageButton1"

CollapseControlID="ImageButton2"

AutoCollapse="False"

AutoExpand="False"

ScrollContents="False"

TextLabelID="Label1"

CollapsedText="Show Details..."

ExpandedText="Hide Details"

ExpandDirection="Vertical">

</ajaxToolkit:CollapsiblePanelExtender>

</form>

</body>


Hi Itay,

The following code should do the trick.

More info about the $find function here:http://asp.net/AJAX/Documentation/Live/ClientReference/Sys/ApplicationClass/SysApplicationFindComponentMethod.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function handleCollapse(extenderId)
{
//Find your CollapsiblePanel Behavior on the page.
var myBehavior = $find(extenderId)

//if the page is not valid, do something
if(!Page_ClientValidate())
{
//what I do here is dispose the behavior. This way the collapse will be cancelled.
myBehavior.dispose();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="my image.jpg" OnClick="ImageButton1_Click1" CausesValidation="False" />
<asp:Panel ID="Panel1" runat="server" Height="7px" Width="376px" Direction="RightToLeft" HorizontalAlign="Center">
<asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
<asp:TextBox ID="From" runat="server" Columns="23"></asp:TextBox><br />
<asp:TextBox ID="UsersEmail" runat="server" Columns="23"></asp:TextBox>
<asp:TextBox ID="Subject" runat="server" Columns="23"></asp:TextBox>
<asp:TextBox ID="Body" runat="server" Columns="30" Rows="8" TextMode="MultiLine"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="UsersEmail"Display="Dynamic" ErrorMessage="please fill in your address" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="From"Display="Dynamic" ErrorMessage="please fill in your name" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="Body"Display="Dynamic" ErrorMessage="write your message" Font-Bold="False" Font-Size="13px"></asp:RequiredFieldValidator><br />
<asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="confirm_icon.gif" OnClick="ImageButton1_Click"OnClientClick="handleCollapse('cpe')"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="UsersEmail"Display="Dynamic" ErrorMessage="this is not a valid email address" Font-Bold="False" Font-Size="13px" ValidationExpression="\w+([-+.']\w+)*@.\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></asp:Panel>
</div>
<ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="server"TargetControlID="Panel1"CollapsedSize="30"ExpandedSize="500"Collapsed="True"ExpandControlID="ImageButton1"CollapseControlID="ImageButton2"AutoCollapse="False"AutoExpand="False"ScrollContents="False"TextLabelID="Label1"CollapsedText="Show Details..."ExpandedText="Hide Details"ExpandDirection="Vertical" >
</ajaxToolkit:CollapsiblePanelExtender>
</form>
</body>
</html>

If you have questions/remarks please do so!

Kind regards,
Wim


Thanks alot Wim,

Everything is almost up and running.

Just one little thing.

My collapse button doesn't collapse the panel on the first click even if the validation are valid.

Only the second time i click the button the panel collapeses back.

Any thoughts?


Hi Itay,

Hmm, that behavior is not right :)

Did you also have that behavior when you use my code example AS IS? Or is it only specific to your code?
If it is only occuring in your code, then please give me the code that replicates this behavior.

If it is also in my example, then I must say that it was not happening to me!
Can you please give me your browser version where you are noticing this behavior?
Also try your code in another browser and see if it also happens over there.

Please comment on my observations.
Kind regards,
Wim


Hi,

I tried using your code and the same thing happened. I will be more specific.

After expanding the panel i press the collapse panel in order to check that it won't collapse if not valid.

Then i fill in the required filled and press the collapse button again this time no none of the required fields error messages pop up

but the panel doesn't collapse as well then i press the collapse button again and it collapses the panel from there on

expanding or collapsing the panel works with a single click.

I did have a problem that every collapse or expanding the page would flicker (postback)

solved it with adding the

suppresspostback="true"

to theCollapsiblePanelExtender.

I am using IE7 version 7.0.5730.11

and again thanks for the help.


Wim do you have any idea to how i can resolve this problem?


Itay molecule:

Wim do you have any idea to how i can resolve this problem?

Sorry Itay that I didn't get back to you any sooner ....

I looked at the example again (the one I created):

it is not good!

Hi Wim

Every thing works great just one little thing

in order to send the message on the panel

i need the collapse button/img ti initialize a postback calling the sendmail function

is there a way that the javascript function will create the postback as well?


Hi itay,

Ok I forgot about that functionality you needed.

I didn't try it yet, but I think you could use an ImageButton for that second one. The IMG that triggers the javascript. Then just set the javascript function in the OnClientClick of it. ImageButtons have those right? Then I think it's possible to NOT let the button postback until the page is valid. Look at the button's properties. Is it the CausesValidation property, I'm not sure ...

I would go for a setup like that!

Please give it a try and if it doesn't work out I'll look into it.

Kind regards,
Wim


Wim thanks

it works just fine

still getting a page refresh on the onclick="... from the image button

but that's expected

i will try to rap it up in an update panel.

Thanks a lot

hope some day i will the ability to help you back.

Wednesday, March 21, 2012

DefaultButton in UpdatePanel

ASP.Net 2.0 has a nice feature. You can - in a panel - define a DefaultButton. When you have focus in a TextBox (on the panel) and presses RETURN, you click the DefaultButon.
When using an UpdatePanel (ScriptManager:EnablePartialRendering="True) this also works fine, but... only once.
Does somebody knows a workaround or a solution or am I doing something wrong?

<atlas:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:PanelID="Panel1"runat="server"DefaultButton="Button1">
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:ButtonID="Button1"runat="server"OnClientClick='alert("click")'Text="Button"/></asp:Panel>
</ContentTemplate>
</atlas:UpdatePanel>

hello.

well, this is a side-effect bug related with the way the code used by the asp.net works. when you add a default button, you get this on your panel:

THe problem happens on the WebForm_firedDefaultButton. Inside, the method checks for a global variable called __defaultFired which initially is set to false. the 1st thing the method does is check the value of this var. if it is set to true, it doesn't do anything since it thinks you're re-submitting the form. if you think only about ASP.NET, this makes sense, right?

unfortunatelly, when yuo use atlas you start getting the behavior you've described. for now, i think that you can override the prerender method of your page and add this:

protected override void OnPreRender (EventArgs args)
{
base.OnPreRender(args);
this.ClientScript.RegisterStartupScript(this.GetType(), "resetBt", "__defaultFired = false;", true);
}

By injecting this instruction, you're resetting the state of the _defaultFired variable so that you're able to start another request when you press the enter key.


btw, what's wrong with the feedback center? i'm trying to add a bug and can't pass from the searh page :(

Thank you for your reply Luis. It works!


Sorry to say but then i am having the same problem and not bale to get it work :(

Can you please help ?

This is a known issue in the current CTP and we are considering fixing it in a future release.

Thanks,

Eilon


the prerender solution doesn't work at my neither :(

maybe it depends on which CTP you're using? are there any other solutions available right now?


protected override void OnPreRender(EventArgs args)
{
base.OnPreRender(args);
this.ClientScript.RegisterStartupScript(this.GetType(), "resetBt", "__defaultFired = false;", true);
}

works in IE but not in Firefox

always working Workaround or Fix would be great


Does anyone have a workaround for this that will work in Firefox? I'd really rather not have to yank out all of my updatepanels, but this is about the only option I see right now.

Thanks


hello.

i really hanve't checked how the current version implements this functionality. i suggest that you use a new static methods of the scriptmanager class instead of using the clientscriptmanager class to register the startup scripts.


Has anyone figured out a way to get the the default button working with firefox in an updatepanel?

Did'nt want to start a new topic!

Thanks


hello.

if i recall correctly, the approach mentioned on this thread doesn't work only in IE (ie, it should work without any problems in firefox)

After struggling with this for a while between browsers andAtlas ajax.net I chose a dumb method and implement this in code, w/o using the DefaultButton attribute. I set this on Page_Load for any control collection. In fact ASP.NET should have a default button setting for just about anything that is clickable - for example the button on an panel extender.

publicstaticvoid SetDefaultButton(WebControl button,ControlCollection cc)
{
foreach (System.Web.UI.Control wcin cc)
{
SetDefaultButton(button, wc.Controls);
if (wcis System.Web.UI.WebControls.WebControl)
{
if (wcis System.Web.UI.WebControls.TextBox)
{
TextBox tb = (TextBox)wc;
SetDefaultButton(button, tb);
}
}}}publicstaticvoid SetDefaultButton(WebControl button,TextBox tb)
{
if (tb.TextMode ==TextBoxMode.MultiLine)
return;

tb.Attributes.Add(

"onkeydown","if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + button.UniqueID +"').click();return false;}} else {return true}; ");
}


The OnPrerender() solution above didn't work for my app.

I had this issue in IE and Firefox.In IE the first time the user pressed enter the default button fired, but after that it won't fire. In FireFox is was just the opposite, the first time it wouldn't fire and then it fired fine after that.

The fix I came up with (after seeing the OnPrerender() exmaple) is to set the __defaultFired variable appropriately in the pageLoad() function which AJAX calls after the page is completely loaded. This works for IE, Firefox and Safari.

<script type="text/javascript" language="javascript">
function pageLoad()
{
if (navigator.userAgent.indexOf("Firefox")!=-1)
{
__defaultFired = true;
}
else
{
__defaultFired = false;
}
}
</script>

I put this on my master page and now all my default buttons fire properly now.

Anyone know why Firefox has the reverse logic for __defaultFired?


I am having the same problem. :( DefaultButton works only in IE, not in Firefox. Can anyone on the Asp.net Ajax team comment on whether this will be fixed for the release version?

Thanks

DefaultButton in Firefox

I added a DefaultButtion to a normal asp panel to handle enter key event. This works fine in IE, but has problem in FireFox.

This asp panel is in anupdate panel.

When user presses enter key in FireFox, this does not trigger OnClick function of the button, it only triggers client side function OnClientClick. My submit button code is in server side OnClick function. So when user presses the enter key, nothing is saved.

I debugged the javascript, traced to following function:

function WebForm_FireDefaultButton(event, target) {
if (event.keyCode == 13 &&
!(event.srcElement &&
event.srcElement.tagName.toLowerCase() == "textarea")) {
var defaultButton;
if (__nonMSDOMBrowser) {
defaultButton = document.getElementById(target);
} else {
defaultButton = document.all[target];
}
if (defaultButton && typeof defaultButton.click != "undefined") {
defaultButton.click(); myapplication continues. But web application which does not use Ajax stops here and posts back. ?
event.cancelBubble = true;
if (event.stopPropagation) {
event.stopPropagation();
}
return false;
}
}
return true;
}

Is this problem related to update panel. I used the approach inhttp://forums.asp.net/thread/1685533.aspx. (UseSubmitBehavior="False" OnClientClick="ResetDefault" ).But that does not work.

Any suggestion will be much appreciated.

Any luck with this issue? Sounds like I have the same issue as you and I also tried the ResetDefault function with no luck. I reset the __defaultFired variable (i think that's the name of it) inside the page_prerender using the registerclientstartupscript method with no luck. I noticed that the the enter button does cause a postback, it just doesn't fire the button that it is suppose to be firing. If you look at the Request.Forms collection the button is missing from it. If you look at the same collection after clicking the button with the mouse it is there. I hope someone can shed a little light on this matter. I am going to try to create a simple page to reproduce the issue.

DefaultButton in a Panel inside an ajax UpdatePanel

The DefaultButton does not act properly on browsers other than MS IE. I guess that the WebForm_FireDefaultButton is the main problem. When I override this function by one that i wrote the problem becomes solved.

Could you post the fix you made please? Right now I'm about to pull out the update panels on my page because I must have default button working under firefox.

Thanks


I would also like to know the fix, and where you put the fix at. Thanks!

DefaultButton and the ValidationSummary Control

Scenario:

I have an asp:panel control with the defaultbutton attribute set to a button within the panel. The button is part of a validation group that includes a requiredvalidator control associated with a textbox (within the panel). I also have a validationsummary control that is part of the validationgroup and also has its ShowMessageBox attribute set to true. The validation summary displays correctly when I click on the button, but when I hit enter on the keyboard I get the text value of the required validator to show up but the validationsummary popup message does not appear. I posted the code below. Any clues?

<asp:UpdatePanel ID="upCustomerEdit" runat="server">
<ContentTemplate>
<asp:Panel ID="panCustomerEdit" runat="server" DefaultButton="btnSave">
<table>
<tr>
<td>Some label:</td>
<td>
<asp:Textbox ID="Textbox1" runat="server"></asp:DropDownList>
<asp:RequiredFieldValidator ID="valTextbox1" runat="server" ControlToValidate="Textbox1" ValidationGroup="valGroupSave" EnableClientScript="true" Text="*" Display="Static" ErrorMessage="Textbox 1 value is required" SetFocusOnError="true"></asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<asp:Button ID="btnSave" runat="Server" Text="Save" ValidationGroup="valGroupSave" CausesValidation="true" />
</td>
</tr>
</table>
</asp:Panel>
<asp:ValidationSummary ID="valSummary" runat="server"
DisplayMode="BulletList"
ShowMessageBox="True"
ShowSummary="False"
ValidationGroup="valGroupSave"
HeaderText="Errors on Page:" />
</ContentTemplate>
</asp:UpdatePanel>

The exact same problem plagues me also. The ValidationSummary does not show up when the enter key is being pressed.

Has anyone yet found a solution for this one?Sad

sincerely stawrogin


See if this post helps you out at all:http://forums.asp.net/p/985791/1798911.aspx

-Damien


Validation controls, which includes theBaseCompareValidator,BaseValidator,CompareValidator,CustomValidator,RangeValidator,RegularExpressionValidator,RequiredFieldValidator, andValidationSummary control are not compatible with UpdatePanel

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

You can download compatible version of validators from here

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx


Thanks for your suggestions. It is not about the UpdatePanel. In fact i don't use an UpdatePanel. It's about the ValidationSummary not being shown.

Take this simple scenario (code below): A Loginform with username, password, and a Login-Button. The defaultFocus is on the username, the defaultButton is set to the Login-button. Additionally there are two RequiredFieldValidators and a ValidationSummary. When clicking the Login-Button all controls get evaluated and the ValidationSummary is being shown. When hitting enter, only the Text of the RequiredFieldValidator is shown but not the ValidationSummary. I want the Validation to be the same whether anyone clicks the button or hits enter. But how?


<form id="form1" runat="server" defaultfocus="txtUserName" DefaultButton="btnLogin">
<div>
<div>
<h2>Login</h2>
</div>
<div>
<asp:Label ID=lblUserName runat=server AssociatedControlID="txtUserName" CssClass="w-117">Benutzername</asp:Label><asp:RequiredFieldValidator ID=reqUser runat=server Text=" *" ControlToValidate="txtUserName" ErrorMessage="Erforderliche Eingabe Benutzername." SetFocusOnError=true></asp:RequiredFieldValidator>
<asp:TextBox id="txtUserName" runat=server CausesValidation=true CssClass="w-153" />
</div>
<div>
<asp:Label ID=lblPassword runat=server AssociatedControlID="txtPassword" CssClass="w-117">Passwort</asp:Label><asp:RequiredFieldValidator ID=requPassword runat=server Text=" *" ControlToValidate="txtPassword" ErrorMessage="Erforderliche Eingabe Passwort." SetFocusOnError=true></asp:RequiredFieldValidator>
<asp:TextBox id="txtPassword" runat=server CausesValidation=true CssClass="w-153" TextMode=Password />
<asp:Button ID=btnLogin runat=server Text="Login" />
</div>
<asp:ValidationSummary ID=valSummaryLogin runat=server DisplayMode=BulletList ShowSummary=true/>
</div>
</form>


I have a similar issue. I have a Validation Summary out side of a GridView that has a Range Validator inside of it. The Range Validator will fire correctly with either pressing "Enter" or clicking the "Update" button (set as DefaultButton). However the Validation Summary will not update when I press "Enter", only when I click on the "Update" button.

Anyone else have an idea?

Default Focus with the Login control and the Ajax RoundedCornersExtender

I have a problem that either has a simple solution or is an Ajax bug - I don't know which.

I've implemented the Login control inside a panel that has its corners enhanced by the RoundedCornersExtender. It looks great but one negative side effect is that the initial focus is no longer in the UserName textbox. Remove the extender and the problem goes away.

Any ideas?

Robert W.
Vancouver, BC

Hi Robert,

Can you show me a small, self-sufficient repro regarding this issue?


Raymond,

Greetings from the North end of the I-5 !!! :-)

One perfect example of this can be found here: http://pocketpollster.com/beta/Login/login.aspx

I looked for your e-mail address on here but can't find it. You can e-mail me here: A1 at PocketPollster dot Com

And then I can send you the source files back.

Robert



Robert, I think it will be better if you post a simple demo here. All the community may benefit from this. :)

I had a rough idea for solving your problem. Can you add a javascript function which will run on pageLoad? And set focus to the userName textbox in this method. For instance:

function pageLoad()

{

window.setTimeout(setfocus, 1000);

}

function setfocus()

{

$get("the client id ").focus();

}


Raymond,

I will try your workaround but hopefully you can let the Ajax guys at MS know of this definite bug. Here's the barebones of the code:

<%@. Page Language="C#" MasterPageFile="~/main.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="_login" %>
<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="panelLogin" runat="server" Height="250px" Width="270px" BackColor="#F9F9F9">
<asp:Login ID="Login1" runat="server" BorderPadding="12">
<TitleTextStyle HorizontalAlign="Left" VerticalAlign="Top" Height="40px" Font-Bold="true" Font-Size="Large" />
<TextBoxStyle Width="140px" />
<LoginButtonStyle Width="70px" />
</asp:Login>
</asp:Panel>
<cc1:RoundedCornersExtender ID="RoundedCornersExtender1" runat="server" TargetControlID="panelLogin" BorderColor="black" Radius="5" />
</asp:Content>

protected void Page_Load(object sender, EventArgs e)
{
// Make the Sign In button the default button and place the cursor in the User Name textbox
if (!IsPostBack)
{
Page.Form.DefaultButton = Login1.FindControl("LoginButton").UniqueID; // This works!
Page.Form.DefaultFocus = Login1.FindControl("UserName").UniqueID; // Doesn't currently work because of the Ajax RoundedCornersExtender control
}
}

------------
- End of Code -

Robert


http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11520


Gracias, amigo!!

Well, my app takes this one step further. While this is related to the Ajax RoundedCornersExtender, it is also aggravated by the Ajax TextBoxWatermarkExtender control as well. Basically, I have a MasterPage with a LoginView control on it, and my content page (Register.aspx) is a 2-step CreateUserWizard process. I managed to figure out how to handle the Default Button work around (LoginView login button was being defaulted), but then I came across the Focus issue. Due to the fact that I have the TBWE control on the textboxes I want to focus, the Ajax controls are overriding my focus settings. Using Raymond's workaround, I managed to be able to get Step 1 of my CreateUserWizard control to set the focus to my first textbox (though only 90% of the time). The problem is that I then don't have any recourse on setting the focus of the first control on the second step since the load event is already set. Any ideas?


Shouldn't this now be fixed with the latest release - 10920? If so, I still have the problem.


I've been on holidays so wasn't aware that it was released ... and on my birthday no less! The notes with the release do seem to indicate that the problem has been resolved.

Robert


I have downloaded the latest release and I still get this issue. Without the RoundedCornersExtender I can set the focus in a textbox on page load, as soon as I put one on the page the focus doesn't work. Anyone else still having this issue or is something not right in my set up?


I have now had the opportunity to test it too. It definitely is NOT fixed. I even went so far as to set the default focus to the actual (hard-coded) UserName control name but it did not work. With the RoundedCornerExtender it does, so I'm convinced that the bug is not fixed.

Default Button Issue

Hi Everyone

I have a asp Panel with few textboxes and two ImageButtons - imgbtnSave and imgbtnCancel

Now what i want that whenever the user presses enter button as long as he is inside that asp Panel, the default button (say I want "imgbtnSave" as Default Button) works.

Note : - I am using my own JavaScript code for DateValidation. So if i use inbuilt defaultButton property of asp Panel then DateValidation fails. I cant change the DateValidation function now as my project is on deliverey stage. So i want JavaScript Code for Default Button

Thanx in advance

you want to set focus to ImageSave button

you can do like this

write the function in javascript

<script type="text/javascript" language="javascript">
function setFocus()
{
document.getElementById("<%= Button.ClientID %>").focus();


}
</script>

call this function like this

protected void ButtonAddCategory_Click(object sender, EventArgs e)
{

ClientScript.RegisterStartupScript(typeof(Classname), "Focus", "setFocus();", true);

}

give me the feedback

-----------

mark as Answer if you feel


Hi Manoj

Thanx for your valuable time....

The solution you have given works in the condition where we have one textbox associated with a single Button.

Now suppose i have Panel inside which i have 60 textBoxes and One Imagebutton

And Other Panel inside which i have 20 textboxes and 2 ImageButton.

Now what should i do???
Hope u understand now

Bye and Take Care

Thanx in advance


Hi DeepakTake a look at the following code:

1 private void SetDefaultButton(TextBox control, Button btButton)
2 {
3 control.Attributes.Add("onkeydown",
4 "if(event.which || event.keyCode)"
5 +"{"
6 + "if ((event.which == 13) || (event.keyCode == 13)) "
7 + "{"
8 + "document.getElementById('" + btButton.UniqueID +"').click();"
9 + "return false;"
10 + "}"
11 +"}"
12 +"else"
13 +"{"
14 + "return true;"
15 +"};" );
16 }
17
18 private void SetDefaultButton(TextBox control, ImageButton btButton)
19 {
20 control.Attributes.Add("onkeydown",
21 "if(event.which || event.keyCode)"
22 +"{"
23 +"if ((event.which == 13) || (event.keyCode == 13)) "
24 +"{"
25 +"document.getElementById('" + btButton.UniqueID +"').click();"
26 +"return false;"
27 +"}"
28 +"}"
29 +"else"
30 +"{"
31 +"return true;"
32 +"};");
33 }
34
35 protected void Page_Load(object sender, EventArgs e)
36 {
37 SetDefaultButton(this.TextBox1,this.Button1);
38 SetDefaultButton(this.TextBox2,this.Button2);
39 SetDefaultButton(this.TextBox3,this.ImageButton1);
40 }
41
42 protected void Button1_Click(object sender, EventArgs e)
43 {
44 this.Label1.Text ="Button 1 was clicked";
45 }
46
47 protected void Button2_Click(object sender, EventArgs e)
48 {
49 this.Label1.Text ="Button 2 was clicked";
50 }
51
52 protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
53 {
54 this.Label1.Text ="Image button was clicked";
55 }
56

And on the .ASPX page, I have the following the following controls:

1 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
2 <br />
3 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
4 <asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" /><br />
5 <br />
6 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
7 <asp:Button ID="Button2" runat="server" Text="Button 2" OnClick="Button2_Click" /><br />
8 <br />
9 <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
10 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Save.png" OnClick="ImageButton1_Click" />

I have placed three textboxes, and each has an associated button.  The third textbox has an imagebutton
next to it. Enter something in the textbox, and press the enter key. It executes the associated click event
for each of them.
The trick over here is to add a small piece of JavaScript code.  I have formatted the code so that you can
understand what it actually does. The trick here is that since I need to make sure it works for IE and Firefox,
I have identify the ENTER KEY (key code 13), using both event.keyCode and event.which (for FireFox), to
fire its respective click.
And to make this implementation easily replicatable, I have turned this JavaScript add-on as a generic function,
which is called from the Page_Load method (as shown in this example). It is overloaded to handle both ordinary
buttons, and imagebuttons.
Hope this helps.
In case you find this suitable, please don't forget to mark it as the answer.
Happy coding!
MANOJ KUMAR SHARMA
www.manojkumarsharma.com

Default atlas:UpdatePanel Default Behavior

I feel that the default behavior for an update panel should include disabling the content/controls it contains while an update is occuring (Make all the anchors turn into divs, disable all form inputs, etc.. etc..), or at least an option for toggling that functionality. Then the atlas:UpdateProgress could contain a cancel button that would re-enable the update panel's content. It seems to me that most people would expect that behavior and it would really help developers AJAX code be a little tighter.

hello.

hum...i think that you can do that by injecting javascript on the page during the events generated by the pagerequestmanager client class...another option would be to build an extender ;)


Well, I'm sure there are plenty of ways to do it; however, what I'm trying to say is it would be nice if either (A) it was the default behavior of an atlas:updatepanel while it is updating or (B) there was a property that could easily be set to accomplish this disableDuringUpdate="true" or something like that.

My reasoning is simply that I believe many people will end up writing that code themselves while one of the main goals of .NET seems to be to write less code and make it easier for a developer to produce results faster. I don't think it would be very difficult to include with the AJAX/Atlas extensions.