Showing posts with label dynamically. Show all posts
Showing posts with label dynamically. Show all posts

Wednesday, March 28, 2012

Modal Popup events not responding

I have a modal popup control that is created dynamically along with various other controls on Page_Init. Actually it's a user control created dynamically, and part of that user control is the modal popup.

Inside the modal popup is basically just a grid view with some hyperlink columns. The problem is that none of the links ever seem to respond. The popup is shown by a serverside call to the Show() method.

I experimented and put a few buttons and various other controls, and while the button animates like it's been pressed, no server code fires. This happens reguardless of the control type; radiobuttons won't even check. This occurs in controls both inside and outside of the gridview.

Anyone run into something similar with a dynamically created modal popup?

When the controls are being created dynamically, are you attaching events to the objects that will be posting back (ie the modal popup window). I have a similar situation where I have a user control that dynamically creates buttons. The buttons did not work until I added a event handler once I created them. When you add conntrols to a page, this is done automatically, but If you create a control dynamically, you must tell the page what to do with its events when they are raised. Make sence?

-Alan


Yes, it makes sense. The standard events that are tied into the controls, Page_Load, Page_PreRender, etc. all fire fine at the right times. It's only UI events like Click that don't respond on the server side. I can get them to execute javascript (of course) but I'd like to avoid having to hack together a callback function just to get a button working. Besides wiring the buttons/links/etc with events directly from the aspx page, I've tried adding the controls dynamically also (within the dynamically created user control housing the modalpopup) and then wiring them to the events.

Adding the controls that way in the user control's Load, and Init events both yield the same results. The code gets run and the controls get created, but they do not respond to UI events.

Monday, March 26, 2012

Modal Popup onClickScript and encoding

Hello I have a strange problem and I'm not sure if I'm doing something wrong. I have a Modal Popup which I am adding dynamically to my page during pre-render. I have a string which I create using thePage.ClientScript.GetPostBackEventReference function and when I debug it looks fine. But when it converts to html the javascript is going from:

__doPostBack('MyControlID,'') in the debugger to:

__doPostBack(\u0027MyControlID\u0027,\u0027\u0027) in the source on the actual html.

Is there a way to tell the control to ascii encode or something along those lines. Or am I barking up the wrong tree and there is something else wrong with my code most likely?

Matt

Hi Matt,

Can you show me essential part of your code so that I can look into the issue?

Wednesday, March 21, 2012

ModalPopup -> UserControl -> fire event ?

Hello !

Because I made different scenarios with modalpopups, I have this situation :

1) I create ModalPopup dynamically

2) Load dynamically a usercontrol into a ModalPopup (and set usercontrol ID)

3). UserControl has buttons OK,Cancel and btnFireClick with click event on a server

Everything is fine, except that when I click btnFireClick the click event didnt fire...

If I set the same buttons into modalpopup but not like usercontrol - event is executed

If I load the usercontrol in the page (not in modalpopup) - event is executed

But if I load usercontrol into modalpopup - event didnt execute

Where is the problem ?

I use Microsoft ASP.NET 2.0 AJAX Extensions

Please try your scenario with the recently available61121 release of the Toolkit (and ASP.NET AJAX Beta 2). If the problem persists, then 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!

2) Load dynamically a usercontrol into a ModalPopup (and set usercontrol ID)

Your user control is a server side control which renders a bunch of html controls at the client side, it is not like a Panel server control which renders a div at the client side.


The second thing you may want to look at is, if you load the user control dynamically, you will have to load the user control every postback within OnInit or OnLoad and give it the same name since you the first time you load the user control dynamically. Otherwise, the event won't fire and the control does not even exist.

ModalPopup - Web Service Failed - DynamicServiceMethod

I was trying to update the ModalPopup dynamically passing the topics section of an article to it.

I believe this is related to my DynamicServiceMethod. I test this out with C# and it worked fine, but would like to convert it to VB.

C# Code

<script runat="server">
[System.Web.Services.WebMethod()]
public static string GetContent(string contextKey)
{
string sIndName = contextKey;
return sIndName;
}
</script>

Method

VB CODE

<script runat="server">
<System.Web.Script.Services.ScriptMethod()> _
<System.Web.Services.WebMethod()> _
Public Function GetContent(ByVal contextKey) As String
Dim topics As String = contextKey
Return topics
End Function

</script>

This is the code

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:v1ConnectionString %>"
SelectCommand="SELECT [TITLE], [TOPICS] FROM [AGEXPRESS]"></asp:SqlDataSource>
<asp:Repeater DataSourceID="SqlDataSource1" ID="Repeater1" runat="server">
<HeaderTemplate>
AG</HeaderTemplate>
<ItemTemplate>
<div class="title">
<asp:LinkButton ID="myLabel" Text='<%#Eval("TITLE") %>' runat="server"></asp:LinkButton>
<cc1:ModalPopupExtender

BackgroundCssClass="background"

DropShadow="true" EnableViewState="true"
PopupControlID="Panel2" CancelControlID="CancelButton" TargetControlID="myLabel"
ID="ModalPopupExtender" DynamicControlID="Label10" DynamicServiceMethod="GetContent"
DynamicContextKey='<%#Eval("TOPICS") %>' runat="server">
</cc1:ModalPopupExtender>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:Panel ID="Panel2" runat="server" Width="300px" BackColor="BlanchedAlmond" BorderColor="Black">
<h2>
Topcis:</h2>
<asp:Label ID="Label10" runat="server" Text="Label"></asp:Label>
<div align="center">
<asp:LinkButton ID="CancelButton" runat="server">Close</asp:LinkButton>
</div>
</asp:Panel>
</form>

IF i don't find a solution then i can use the C#, but would really like this to be formatted in converted to VB (would be consistent with the site)

Please help.

You are missing the "Shared" keyword on the method. PageMethods are supposed to be Static/Shared.

Thanks! It worked.



Thanks it worked!

Hi

the property DynamicContextKey
what is useful?