Showing posts with label inside. Show all posts
Showing posts with label inside. Show all posts

Wednesday, March 28, 2012

Extenders: Using complex types inside my Behavior.js javascript?

I added some complex types to my PanelExtender.vb that represents lists of numerical values:

Public Class ChartPanelExtenderInherits ExtenderControlBase(Of ChartPanelProperties, Panel)Private _dataseriesAs ArrayListPublic Sub AddSerie(ByVal p_serieAs DataSerie) _dataseries.Add(p_serie)End Sub Public Class DataSeriePrivate _valuesAs ArrayListPrivate _nameAs String Public Sub New(ByVal serieNameAs String) _name = serieNameEnd Sub Public Sub AddValue(ByVal p_valueAs Integer) _values.Add(p_value)End Sub Public Property Name()As String Get Return _nameEnd Get Set(ByVal valueAs String) _name = valueEnd Set End Property End Class End Class
Although I can easily create and add data series to my PanelExtender on the server-side (aspx page):

 Public Sub Page_load(ByVal sender As Object, ByVal e As EventArgs) Dim mySerie As New ChartPanelExtender.DataSerie("MyData") mySerie.AddValue(2) mySerie.AddValue(3) mySerie.AddValue(4) ' this is the name of the control in the page ChartPanelExtender1.AddSerie(mySerie) End Sub

I cannot figure how to access this data inside my javascript PanelBehavior.js code?
Do I need to somehow serialize/deserialize it manually?
How can I pass this data to the PanelBehavior.js script?

Any suggestions would be appreciated including telling me I am way off and giving an alternative hehe. All I really need is a way to pass data series to the behavior script.

Thanks in advance

PascalThe typical way of getting information to a JS behavior is via one of its properties. Your server code might transform the list somehow so that it can be safely passed to the behavior in a string (ex: [a, b, c] -> "a,b,c") and then the behavior can transform the string back into the data it represents. We're considering adding JSON support to this scenario so that more complex data types could be communicated more easily, but haven't done so yet, so the ->string-> technique may be a good choice for now. Hope this helps!
Okies, will see if JSON gets added in next CTP.
Thanks for the reply :)

Pascal

Extenders inside templateColumn in RC1

Hi, I have just installed the new RC1

I have a gridview that contains a template column, with 2 imageButtons inside it (Basically Edit Item and Delete Item) and a confirmButtonExtender linked on the delete image button. Everything was working well in Beta 2, but in RC1, in design time, it does not render the gridview, saying that a scriptmanger is required and must exist before any control on the page... It works great at runtime, but it is quite annoying at design time...

Will this be fixed in a future release of the control toolkit?

Thanks!

Yes, I am experiencing the same issue as you but with a PopupControlExtender inside a FormView on a ContentPage.


Please reply with acomplete, simple, self-contained sample page that demonstrates the problem so that we can investigate the specific behavior you're seeing. Thank you!

Hi David, This is a very simple page that demonstrates the error I am getting (only at design time, by the way). I have started a new project using the template provided by Ajax (Ajax Enabled web application), and just dragged a gridview, and edited the templates..

Thanks!

Default.aspx

1<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAXEnabledWebApplication1._Default" %>23<%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>45<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">67<html xmlns="http://www.w3.org/1999/xhtml" >8<head runat="server">9 <title>Untitled Page</title>10</head>11<body>12 <form id="form1" runat="server">13 <asp:ScriptManager ID="ScriptManager1" runat="server" />14 <div>15<asp:GridView ID="GridView1" runat="server">16<Columns>17<asp:TemplateField>18<ItemTemplate>19<cc1:ConfirmButtonExtender ID="ConfirmButtonExtender1" runat="server" ConfirmText="Testing"20TargetControlID="Button1">21</cc1:ConfirmButtonExtender>22<asp:Button ID="Button1" runat="server" Text="Button" />23</ItemTemplate>24</asp:TemplateField>25</Columns>26</asp:GridView>2728 </div>29 </form>30</body>31</html>32
 
Default.aspx.cs
1using System;2using System.Data;3using System.Configuration;4using System.Collections;5using System.Web;6using System.Web.Security;7using System.Web.UI;8using System.Web.UI.WebControls;9using System.Web.UI.WebControls.WebParts;10using System.Web.UI.HtmlControls;1112namespace AJAXEnabledWebApplication113{14public partialclass _Default : System.Web.UI.Page15 {16protected void Page_Load(object sender, EventArgs e)17 {1819 }20 }21}22  

This seems like an atlas issue and not a toolkit issue. The script manager is not being detected at design time. Could you try the asp.net ajax forum?

http://forums.asp.net/1007/ShowForum.aspx


I tested to define a asp:TemplateField template of a asp:GridView in Ajax RC 1.0 and get the similar problem saying "There was error rendering the control.The control with ID 'ConfirmButtonExtender1' requires a ScriptManager on the page.The ScriptManager must appear before any controls that need it". Wish this issue will be resolved in ASP.NET AJAX RTM.

Hi,

I too was experiencing this issue, however as a workaround i have put the extender into a usercontrol, and then put that into the template column. This way the gridview looks ok at design time, and it all compiles properly at runtime too.

Hope this little snippet of info is useful to someone else who has been searching for this issue.

Cheers,
Rich.

Extenders inside template column of a gridview

[THIS IS FOLLOWED FROM POSThttp://forums.asp.net/thread/1498604.aspx in ControlToolKit forum, where I have been suggested to post in this forum]

I have a gridview that contains a template column, with 2imageButtons inside it (Basically Edit Item and Delete Item) and aconfirmButtonExtender linked on the delete image button. Everything wasworking well in Beta 2, but in RC1, in design time, it does not renderthe gridview, saying that a scriptmanger is required and must existbefore any control on the page... It works great at runtime, but it isquite annoying at design time...

Will this be fixed in a future release?

I have posted an example of page that reproduce the issue in the other post (see link at top of message)

Thanks!This is a known issue with Ajax RC 1.0. Wish this issue will be resolved in ASP.NET AJAX RTM.

Extenders for controls inside TabContainer/TabPanel

Hi,

I have a textbox control (ID="'PasswordTxtBox' ") inside TabPanel and I am trying to attach watermark extender to it. In design mode TargetControlID for watermark extender does not appear and when I manually write it in the markup I get run time error saying

The TargetControlID of 'TextBoxWatermarkExtender1' is not valid. A control with ID 'PasswordTxtBox' could not be found

Please guide.

Regards & thanks

Kapil

My bad. I was _not_ putting the extender control in the contenttemplate of tabpanel.

Regards

Kapil

extender control inside databound controls

I will show you a piece of code that worked with the last CTP:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Databound Controls</title>

</head>

<body>

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

<atlas:ScriptManagerEnablePartialRendering=trueID="sm"runat="server"></atlas:ScriptManager>

<

asp:RepeaterID="rpt"runat="server"DataSourceID="xmlData"OnItemDataBound="rpt_ItemDataBound">

<ItemTemplate>

<%# XPath("name") %><asp:TextBoxID="textInside"runat="server"></asp:TextBox><br/>

<atlastoolkit:TextBoxWatermarkExtenderID="watInside"TargetControlID="textInside"runat="server"WatermarkText="Inside TextBox"/>

</ItemTemplate>

</asp:Repeater>

Somebody<asp:TextBoxID="textOutside"runat="server"></asp:TextBox><br/>

<atlastoolkit:TextBoxWatermarkExtenderID="watOutside"runat="server"TargetControlID="textOutside"WatermarkText="Outside TextBox"/>

<asp:XmlDataSourceID="xmlData"runat="server"XPath="contacts">

<Data>

<contacts>

<name>Peter</name>

</contacts></Data>

</asp:XmlDataSource>

</form>

</body>

</html>

This piece of code is not working anymore more. The responsible is the “new” behaviour of the TargetControlID. Now, you need the ClientID of the target control, not the usual control ID.

In the easy case, both (ClientID and ID) are the same, but not inside databound controls. So what you need now is:

First, you need to DataBind() the Page at load stage; this is because you need the extender controls in the control tree before the (Pre)Render stage; otherwise, they won’t render.

Second, you need to delete the TextBoxWatermarkExtender instantiated declaratively, and add it at runtime:

protectedvoid rpt_ItemDataBound(object sender,RepeaterItemEventArgs e)

{

AjaxControlToolkit.TextBoxWatermarkExtender tbe =new AjaxControlToolkit.TextBoxWatermarkExtender ();

tbe.TargetControlID = (e.Item.FindControl("textInside")asTextBox).ClientID;

tbe.ID ="watInside";

tbe.WatermarkText ="Inside Text";

tbe.ResolveControlID +=new AjaxControlToolkit.ResolveControlEventHandler(tbe_ResolveControlID);

e.Item.Controls.Add(tbe);

}

Finally, the extender control is not still able to find the TargetControlID, so you have to make up your own FindControl (like this one) :

void tbe_ResolveControlID(object sender, AjaxControlToolkit.ResolveControlEventArgs e)

{

e.Control =Util.FindControl(e.ControlID,"_",this.Page);

}

publicstatic System.Web.UI.Control Util.FindControl(string cliendid,string separator, System.Web.UI.Control root)

{

int i = 0;

string[] sepControls = cliendid.Split(separator[0]);

System.Web.UI.Control fc =null;

for (fc = root; (null != fc) && i < sepControls.Length; i++)

{

fc = fc.FindControl(sepControls[i]);

}

if (fc !=null && fc.ClientID == cliendid)return fc;

elsereturnnull;

}

If someone knows any other way to simplify this case, please tell me. Otherwise, my project has become a nightmare.

fran

Your original sample works fine for me with the addition of only:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
rpt.DataBind();
}

More details here:http://forums.asp.net/thread/1441672.aspx.

Monday, March 26, 2012

Export to excel and UpdatePanel problems

As I have noticed myself and while looking around for a good answer, a normal asp button to export to excel does not work inside UpdatePanels since Response lines are not viable inside UpdatePanels. It throws an exception that states something to same affect, "common causes for this error are when the response is modified", etc.

I have looked around and was not able to find a complete answer to work around this problem. The shortened code that I am using is below:

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
EnableViewState = False
Controls.Add(frm)
frm.Controls.Add(gv)
frm.RenderControl(hw)
Response.Write(tw.ToString())
Response.Flush():Response.Close():Response.End()

I guess the question is obvious... Is there a clean way around this besides taking the button out of the UpdatePanel? I say this since it does look silly to have one button hanging out by itself in the corner of the page somewhere... I am still new to this so I would much appreciate it if you could "dumb" down the answers a bit.

A bit off topic but would there be a way to handle this on the master page? I believe I just asked two questions ( 1. Update Panel and export to Excel issues, and 2. How to handle this in a master page) but I am mainly focused on the Export issue.

I am able to provide further information as needed. Thanks in advance to all.

First I believe you don't want to add an UpdatePanel around the response.

However why are you doing this? Response.Flush():Response.Close():Response.End()?

Just use Flush but do not close the Response


I saw both ways on the web in different threads that use both ways, without the close and end and with the close and end. However, having the habit of closing what I open, I naturally went with closing it.

BTW, the close and end did not seem to be the cause of the problem as the export as the same problem persists.


I met this problem too. when I put the export buttom into a updatepannel, it will display some javascript error. I think the most possibility of this problem that is you put the Response.contentType in the code as updatePannel use the XMLHTTP to aysn communicate with the server.

Response.ContentType = "application/vnd.ms-excel"

Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")

Big Smile

execute code with the OkButton of modalPopup

Hi guys:

I have a modalPopup and inside it I have a formView linked to a GridView, and I also have a text box and a button to let the user Add a new record.The point is, when the user will click in the OkButton, to close the modalPopup, I want to clean the popup window, I Mean: clean the textbox, de-select the GridView, just for the next time..When the user gonna open again don't find the old tasks.So I put some code behind on click event of the OkButton, but it doesn't work, It doesn't do anything.So I think it is disable for any event by the fact to be the OkButton of the ModalPopupExtender, so how can I solve it?Maybe putting some Java Script onclick Event?

I don't know how to do that.

Any help!Thanks Marcos

The button click event should fire, if you do not set the button as the ModalPopups OkButton.

(i also figured out that no events inside a modalpopup fires when the tragetcontrolid is set to an surronounding elelemt (e.g. the panel you want to pop up)

(an in the button's event handler, simply close the modalpopup with it's Hide() method)


thanks a lot for answer me!

If you can, please explain me better, I am new in all this and I've no much experience.

I didn't understand you well, maybe for my english.

Some comments about:

-can you please put some code for understand you idea!

- of course the Ok button don't fire becouse is set as okbutton of the modalPopup, i Know that but i also want to fire a other events in order to clean the modalPopup.

Myabe you gave me the solution but I didnt get it, sorry, if you can give some additional comments about.

I wan to do something like that:

In the aspx Code put some JS like that:

<JavaScript>..

MiJavaScrip()

{ here is the code, by example clean a textBox

}

</JavaScript>..

and In the button aspx code:

<asp:ButtonID="YesButton"runat="server"Text="Close"onClick="MiJavaScrip()" />

But I am not good with JS, and I dont know if this is the best practice for this case

Thanks again!

Marcos


I wan to do something like that:

<asp:Button ID="Button1" runat="server" Text="open windows popup" /
<asp:Panel ID="Panel1" runat="server" Width="125px" BackColor="yellow">
popup window
<br />
<asp:Button ID="Button2" runat="server" Text="OK" />
<asp:Button ID="Button3" runat="server" Text="Cancel" />
</asp:Panel
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
CancelControlID="Button3"
OkControlID="Button2"
OnCancelScript="Cancel()"
OnOkScript="OK()"
PopupControlID="Panel1"
TargetControlID="Button1">
</ajaxToolkit:ModalPopupExtender
<script type="text/javascript">
function OK()
{
alert(' you press OK');
}

function Cancel()
{
alert('you press Cancel');
}
</script>

With the diference that In the javaScript I want to call to my VB code behind "CleanPopupWindows"

And CleanPopupWindows is like this:

Private sub CleanPopupWindows()

textBox1.text = ""

....etc

End Sub

How can I do this?

thanks!


When you click the OK button, this will trigger the event attached to it, which you know...

protected void btnModalOk_Click(object sender, EventArgs e){// put your "clean box code here" // Use this to hide the modal programatically ModalPopup.Hide();}
 

That can be used in Java on the client side to close the popup without a postback also. Just put the method inside a Javascript script tag, or use it in your code-behind with a postback.

I'm not sure if you were asking for the code to clear the actual box, but I dont think you were. Hope this helps some... You might want to brush up on Java. I didn't know it before ajax either but it forced me to learn it.


thanks a lot, I putted the ok, button inside the updatePanel that is in the modalPopup, and I just did a modalPopupState.Hide and that is !

thanks agian!

Saturday, March 24, 2012

Exception thrown from code inside an updatepanel is not handled by global.asax Application

Hi All

In the application I developed, I had the code to log the exceptions in Global.asax. This was working fine until I use Ajax update panel in the code behind of a few files.

When an exception happens in the code, called through update panel, Application_Error handler in the global.asax is never called.
Instead I can see an alert with the exception.message.

Is this a known issue? if so, is there a was to call the Application_Error automatically in case any exception thrown.

Thanks

Hi,

It's not a issue, but designed to work so.

If it's a asyncRequest, an custom error handler will be registered to handle any exception. The error message is encoded and returned in the internal error handler. And it's worth mentioning that this exception isn't swallowed and theoretically speaking, the appliction_error is able to fire.


Hi,

Thanks for the reply.

But the Application_Error event is not called.

I tried setting breakpoint in the function entry point and indused an Object Reference Is Nothing Errror within the code that is called through UpdatePanel. The breakpoint is not getting hit. Even in the test server, the errors are not getting logged. Is there any way, we can override the Ajax custom error handler or just make the Application_Error event to be called.


I used the following code, and it's able to trigger the Application_Error method.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); throw new Exception("custom exception"); }</script><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> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Can you try it? Please let me know the result.


Hi

One more thanks for the reply.

I tried the code, the exception is getting thrown, but still the breakpoint in application_error is not being hit.


Can you simplify your app into a single page along with web.config that is able to reproduce the problem and mail it to me?

Hi Mr.Raymond Wen,

Many thanks for your continued support.

Below I post a simple "Not in use" page, for your understanding

<%@. Page Language="VB" AutoEventWireup="true" 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"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Partial-Page Update Error Handling Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox> / <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox> = <asp:Label ID="Label1" runat="server"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Try Throw New Exception("FOR TESTING")Finally End Try End SubEnd Class


GLOBAL.ASAX

'This code is not being called during an asyncronous postback'But this is called when a request is made directly without using UpdatePanel.Sub Application_Error(ByVal senderAs Object,ByVal eAs EventArgs)Dim exAs System.Exception = Server.GetLastError()TryIf ex IsNotNothing ThenWriteLog(ex)End IfServer.Transfer("~/ErrorDescriptionPage.aspx")CatchEnd TryEnd Sub

Hope this will help to identify the issue.

Thanks once again


One more thing is that I use Microsoft Entreprise Block for exception handling

Thanks


Still, I can fire the Application_Error method. I guess it's caused by come configurations. That's why I want your web.config file.

Can you post it here?

Exception Problem

Hi...
I've a problem when exceptions are raised using a ASP.NET AJAX framework.

I have a exception raised inside a updatepanel, and its show an alert wrote :
"Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500."
and this message dont correspond with the real Exception message.

When I used the event "AsyncPostBackError" of ScriptManager, the Exception that received in the e.Exception parameter its the correct exception and message that was raised.


thanks

Hi

for myself, i got this error when something wrong to call web services...(i am not sure you have web services in your call or not)

here is another thread about same issue. have a look

http://forums.asp.net/thread/1474598.aspx


Well,

I'm not uses a webservice in this case. The error occur when is raised my personalised Exception (throw new exception("my error")).

Someone have a answer?

Thanks...

Exception not being sent

Hi there!
I'm having a little bit of trouble trying to catch exceptions thrown by the application.
I inserted the scriptmanager tag inside the head tag:
<atlas:ScriptManager ID="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="ChatService.asmx" />
</Services>
</atlas:ScriptManager>
I've already tried to put the GenerateProxy = "true" property and still doesn't work...
when I call a webmethod, I do something like:

ClassName.WebMethod(attributes, onCallOk, onTimeout, onError);

the functions are inside a .js file.

The darkiest thing is that when the error occurs on my machine I cansee the message from the exception, but, when someone from anothermachine (acessing my machine) receives the error, the message from theexception is sent empty, even when the same occurs...

is there something that I have to do to allow remote computers to receive the exception?

thanks!!!

hi leandrokoiti,

you can have a look at Nikhil blog:

http://www.nikhilk.net/AtlasM1Refresh.aspx

they talk about that subjet

Exception has been thrown by the target of an invocation

I have a scriptmanager and updatepanel, inside the panel is a gridview it's bound to an objectdatasource, when I click the select button in the grid I get the alert with the message "Exception has been thrown by the target invocation". How would I know the source of this error, or what is causing the error. Is there a way to get the real exception that occurred not just a message?

Thanks

Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).
This error message is about as useful as a chocolate fireguard. Disabling the update panel is fine for development, and the few bugs that I stumble across while developing. But what about in a production situation. If I get my clients phoning up telling me the app won't work becuase an "Exception has been thrown by the target of an invocation", then I'll just explain to them how to disable AJAX so I can get a useful error message. AHH. No. I don't think so. Is there some way that you can actually pass the message text up to the popup box. Dev's like me are pretty reliant on the exception text. Especially as we often just write stuff and then it gets put into production without rigourous testing. Not ideal, but thats what happens in the real world outside of Redmond.

Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank


Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank you

Everytime postback hiddenfield outside updatepanel

Hello,

I am using some updatepanels inside my site.

There is a hiddenfield value I want to get back on every callback of any updatepanel.
This field is not inside an updatepanel. How can I do this?

Thank you,

Christian

Hi,

what are you going to do with the hidden field's value? I ask you this because a binding may solve your problem.
Hi,

thank you for your reply,

it is a session-id and our own viewstate variable. (We are not using the MS implementation of sessions and we are storing the viewstate in the database).

Christian

Events not firing on custom control inside FormView inside UpdatePanel

Hi all-

I have a custom control that I have been using inside a FormView; all its events have been firing properly. Recently I placed the FormView inside an UpdatePanel, and now the events of the control are not firing.

I set the AutoPostBack property of the control to True and even turned on AutoEventWireup, but the event doesn't fire.

I tried adding the control as a Trigger on the UpdatePanel using this syntax:

<asp:AsyncPostBackTriggerControlID="FormView1:CustomControl1"EventName="SelectionChanged"/>

but the event still doesn't fire.

Am I doing this the right way? I have also posted this question on the control vendor's forum, but I thought I'd check here as well, to make sure I'm doing everything else right.

Thanks for any help...

-Andrew

Hi Andrew,

Can you post a small but full sample? It's preferred that this sample doesn't rely on a specific class or database( Use mock data created in memory instead? ) .


No,

"FormView1:CustomControl1" is not the right way, In this scenario,I think you can use FindContorl method(for more information,seehttp://forums.asp.net/t/1107107.aspx).

TheRegisterAsyncPostBackControl(Control) method enables you to register controls to perform an asynchronous postback instead of a synchronous postback which updates the entire page . When theChildrenAsTriggers property of anUpdatePanel control is set totrue (which is the default), postback controls inside theUpdatePanel control are automatically registered as asynchronous postback controls and cause a refresh of the panel content.

Use theRegisterAsyncPostBackControl(Control) method to register controls outside of anUpdatePanel control as postback controls that can perform asynchronous postbacks and potentially update the content of an update panel. To update anUpdatePanel control programmatically, call theUpdate() method.

For more information,seehttp://www.asp.net/AJAX/Documentation/Live/mref/M_System_Web_UI_ScriptManager_RegisterAsyncPostBackControl_1_62fe17e7.aspx.

Best Regards,


Hi gentlemen-

I just created a simple version of the page, and everything is working. So the problem has to be somewhere in my page. Now that I know that, I believe I can figure out the rest on my own.

Thanks for your time; next time I will just try a simplified version first!

Thanks,

-Andrew


Hi,

It is a good manner to try a simplified version first when you run into an issueSmile

Best Regards

Events inside an UpdatePanel

I'm still fairly new to Ajax so please bear with me. I have an updatepanel that has a bunch of user controls in it that are added dynamically and have their events wired up to some of my methods. What I'm trying to figure out is the order in which callbacks work. For example, I have a radio button with the click event wired up and a textbox with the text changed event wired up. If I type in some text and then click the radio button the text event fires, then the click event fires, then the text event fires again. This is how it runs when I'm using studio, but when I deploy to our production site it seems that the click event fires then the text event and that's it. I actually like the first behavior because it maintains my data structure. Could someone shed light on what it's "supposed" to do and why I get two different behaviors?

Thanks,

Jim

Hi Jim,

It's strange. The order of the controls' event is determined by the ASP.NET, it has nothing to do with which server that it resides in.
A possible cause is with the form of the posted data.
For example, to post "textbox1=value1&1=Radiobutton1" may cause the events to fire in different order from posting "1=Radiobutton1&textbox1=value1".
You can useFiddler?or?Web?DevHelper?to?moniter?the?traffice?to?make?it?clear.

Hope this helps.
I have figured out that the ordering is definitely determined by the order in the page control structure. I'm assuming the control structure is traversed and that each control's events are checked, that's at least seems what happens. What I can't seem to figure out is why when I'm using studio events fire more than once. I got it tod do what I want now so I guess that's all that matters for now.
This is weird, can you show me a stripped version of your code that can reproduce the issue?
It's hard for me to trouble shooting without detail information.

Wednesday, March 21, 2012

Event Triggered from UpdatePanel1 fires validator in UpdatePanel2

I have a form with requiredfieldvalidators inside separate updatepanels, whose UpdateMode's are set to conditional. I've set timestamps in each panel to ensure that the updatemode was functioning correctly, which it is. However, it seems that a postback triggered in the first update panel still fires my validator in my 2nd update panel. I've attached code below. Your insight is much appreciated!

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %><!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>Update Panel Test</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> This is Panel 1. <div> TextBox1:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="TextBox1 isn't filled in."></asp:RequiredFieldValidator> <asp:Button ID="Button1" runat="server" Text="Button1" /><%=DateTime.Now%> </div> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server"> <ContentTemplate> This is Panel 2. <div>Textbox2: <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="TextBox2 isn't filled in."></asp:RequiredFieldValidator> <asp:Button ID="Button2" runat="server" Text="Button2" /><%=DateTime.Now%> </div> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

You just need to assign the two sets of controls to different validation groups.

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ... ValidationGroup="Grp1" />
<asp:Button ID="Button1" ... ValidationGroup="Grp1" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ... ValidationGroup="Grp2" />
<asp:Button ID="Button2" ... ValidationGroup="Grp2" />

Also, you don't need UpdatePanels to make this work.


Assign each button a different validator that will solve the issue

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!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 id="Head1" runat="server">
<title>Update Panel Test</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Auto">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
This is Panel 1.
<div>
TextBox1:<asp:TextBox ValidationGroup="panel1" ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="panel1" ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
ErrorMessage="TextBox1 isn't filled in."></asp:RequiredFieldValidator>
<% =DateTime.Now %>
<asp:Button ID="Button1" ValidationGroup="panel1" runat="server" Text="Button1" />
</div>
</ContentTemplate>
</asp:UpdatePanel>

<asp:UpdatePanel ID="UpdatePanel2" UpdateMode="Conditional" runat="server">
<ContentTemplate>
This is Panel 2.
<div>
Textbox2:
<asp:TextBox ID="TextBox2" ValidationGroup="panel2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ValidationGroup="panel2" ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2"
ErrorMessage="TextBox2 isn't filled in."></asp:RequiredFieldValidator>
<% =DateTime.Now %>
<asp:Button ID="Button2" ValidationGroup="panel2" runat="server" Text="Button2" />
</div>
</ContentTemplate>
</asp:UpdatePanel
</div>
</form>
</body>
</html

Event Handlers for Dynamically Added Controls

Hi all,

I'm dynamically creating controls inside an UpdatePanel by declaring something like "Dim abc As New DropDownList()" and then adding this control to a PlaceHolder inside the UpdatePanel.
Now, these controls are added and they appear on the page as they should, however I am also added an event handler dynamically to each control that I'm adding (using AddHandler, since it's VB). However, the events definitely do not register with the UpdatePanel, even though I have set AutoPostBack and also tried adding the control's event to the Triggers collection of the UpdatePanel. The UpdatePanel simplify refreshes when the control event is fired (in this case SelectedIndexChanged of a DropDownList) but the event handler is not fired at any point. Could someone please point me where I'm going wrong here. Thanks in advance...

Hi,

this behavior is possible due to different reasons. Can you let us know when do you create your controls? Is it in page_init, page_load or somewhere else?

Do you create the smae controls on each postback?

Do you assign IDs to your controls?

-yuriy
http://couldbedone.blogspot.com


events can only be added in page_load, or from a function that is called from page load. so unless in your page_load function you have a call to another function called something like, populateUpdatePanelWithControls(), then you will have to change your code.

Its a pain sometimes, but thats just the way the page lifecycle works. Basically when you do the post back it wants to add your events, but because you are referenceing dynamically created controls that do not technicially exist at page_load, the events cannot be linked to the controls. This is why you must create them at page_load


Thanks to both of you. The problem seems to have been solved by moving the code to Page_Load. It wasn't any trouble at all, fortunately, considering the way I'd structured the page.

Event fire only once !

Hi,

I've got a little problem ^^. I'm using an update panel wich is created dynamically.

The control inside the updatepanel make some postback calling the __doPostBack function created using the GetPostBackEventReference function.

First time i click on one of the item that is inside the update panel it send an asynchronous request, the controls inside the update panel are created, then

the function that handle the postback event is called, it deletes one of the item inside the update panel and refresh the content of the update panel (you might notice that the update panel is first filled to recreate the control that handle the event, then it deletes the item from the database, then it recreates all the item inside the updatepanel).

The problem is that after this asyncronous callback, if i try to click on another item the asynchronous callback is done but the event handling function is not called :s ... then i retry to click and it works, the event handler is called ...

So i think that the problem is more an asp .net problem, maybe due to the page life cycle, but if someone could show me the light or a way to find the light it would be create :)

Thanks

http://news.infragistics.com/readmessage?id=%3C2c08997$32849066$2c1d78@.news.infragistics.com%3E&group=infragistics.products.netadvantage.aspnet.webasyncrefreshpanel


set "_spFormOnSubmitCalled = false: "_spFormOnSubmitCalled" object, as mentioned, is given in C:\Program
Files\Common Files\Microsoft Shared\web server extensions\12
\TEMPLATE\LAYOUTS\1033\Init.js
function _spFormOnSubmitWrapper()
{
if (_spSuppressFormOnSubmitWrapper)
{
returntrue;
}
if (_spFormOnSubmitCalled)
{
returnfalse;
}
if (typeof(_spFormOnSubmit)=="function")
{
var retval=_spFormOnSubmit();
var testval=false;
if (typeof(retval)==typeof(testval) && retval==testval)
{
returnfalse;
}
}
RestoreToOriginalFormAction();
///_spFormOnSubmitCalled=true;
_spFormOnSubmitCalled=false; // !!!!!!!!!
returntrue;
}

Escape Key Behaviour

Hey,

One of my users just discovered the following:

If you hit ESC twice when on a page containing an update panel with a control inside, if you click on anything else that does a postback, you'll get aSystem.ArgumentException: Invalid postback or callback argument. Event validation is enabled using [...] error.

I would like to know more about the default behaviour of the ESC key. And might be interested in hooking up to the event to fire something else when that happens.

Note: I am still using the July CTP (haven't had time / fond it necessary to upgrade yet, so maybe this issue no longer exists now).

Thanks,

Jason

Okay just upgraded to 1.0 RTM and I'm no longer gettingpostback or callback argument exceptions. However, if I do it during a postback, I do see that my updateprogress stays open. In my old one, it didn't seem to have any effect.

Are there any references to the escape key behaviour?

Jason