473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

UpdatePanel with dynamically added buttons

Pittaman
Here's the problem,

We're still using .NET 2.0. I have a custom grid view whichs includes a context menu. Each item in the menu is a Button.

One button action, the export to excel, wants to do some Response.Write calls, but this does not work as it's giving me the "Sys.WebForms.PageRequestManager" exception whichs tries to parse whetever I write to Response as some kind of Ajax I guess (don't know the full details). Which I can fully understand, because when I press the update, only the update panel does a post-back and not the entire page, so I can not change the Response.

I would have to set a PostBackTrigger on the Export to excel button. The problem is that I can not seem to do this before the PreRender event because then I will get an exception at trigger initialization saying it cannot find the control with the ID of my button. However, if I do this in PreRender phase, it WILL find the control, but nothing changes and still a partial update is performed (I guess because the triggers are already initialised at that point?).


Does anyone know this problem and a solution? I can put the postback trigger on my grid, but that would have performance issues I would like to avoid when it's not needed. I can not use the AddPostBackControl method of the ScriptManager - which is the best way to do it - because we're in .NET 2.0.

Or should I take a completely different approach?

Thanks guys
Oct 14 '09 #1

✓ answered by Pittaman

Hey, thanks for the explanation...

I actually ended up solving the issue in a very different way.

I add my context menu buttons to a panel and add that panel to the Controls collection of my server control before the CreateChildControls is called (so in OnInit). At that point, I also attach my event handlers to each of the buttons. This ensures me that the handlers will be called. Although the menu is shown without adding the panel to the controls collection, this is vital because if it's not in there CreateChildControls will not be called and my event handlers will not be triggered.

So now my button clicks raise server side events and allow me to run server side logic. For the export to excel I had the problem that I could not immediatly modify the Response.Write. I made it easy for myself by using the following technique:

1) In my Server Control there's a class ExcelViewer, which inherits from Page (so it is a page).
2) That class contains a shared field (shared, to make it easy for myself) which contains the data for the excel.
3) In the event handler I generate the actual excel file as a string and then assign it to the shared field of my ExcelViewer class. After this, I raise an ExcelExported event.
4) In the Page_Load of the ExcelViewer I do my Respone.Write manipulations and write the excel data to it (I change the content-type etc...)
5) In the website that is using my grid all I have to do is create an ASPX page which inherits from my ExcelViewer page and then handle the "ExcelExported" event of my grid. In that handler I simply do a Response.Redirect() to my ASPX page that inherits from the viewer.

The Response.Redirect should work even if the grid is inside updatePanels.

9 5064
Frinavale
9,735 Expert Mod 8TB
I'm going to suggest moving the function that exports the data into its own ASPX page. Place an iframe on the page and set the src of the iframe to the ASPX page that exports the excel sheet whenever the user clicks the "export" button. This way the ASPX page can use response.write to export the page into the iframe instead of the main page.

-Frinny
Oct 14 '09 #2
I see what you mean, but the problem is that the Grid is actually a server control. And I do not think it is possible to embed that other page inside the control, which is a requirement.

This was the first approach we took but I think it's not possible, but maybe I'm mistaking?

Thx
Oct 14 '09 #3
Frinavale
9,735 Expert Mod 8TB
Ok, well if that doesn't fit your requirements I am going to recommend that you put the GridView in an UpdatePanel of it's own and set the GridView as a full page postback trigger for the UpdatePanel.

I tried in the past to set individual, dynamic buttons/links within a GridView as triggers for an UpdatePanel but found out that it's impossible. I tried everything I could think of but could not get this to go.

The easiest way is to set the entire GridView as a full page postback trigger.
Oct 14 '09 #4
I know, that is what I might be doing, but it would kind of defeat the purpose of using an update panel, as most postbacks will happen in the grids.

Thanks for the link by the way! Then I know some stuff to exclude. I will keep you updated, because we'll have another look at it.
Oct 15 '09 #5
Frinavale
9,735 Expert Mod 8TB
I'm going to be removing the link shortly because it's actually against forum rules to post links to other forums. I figured it would help you to see the problems that I ran into when I was attempting the same thing as you. Let me know when you're done with it so I can remove it.

I just re-read your question and it for some reason I missed the fact that you're using a server control.

We actually might be able to solve your problem by converting your server control into an Ajax-enabled server control. We'd implement a JavaScript Object that could solve your problems. Designing this JavaScript Object will be interesting but...could be fun :)
Oct 15 '09 #6
I'm not very familiar with AJAX programming, could you explain to me what the functionalities would be of the "javascript object" and how it would help solve the problem? Would it pop-up a new screen in which we can freely change the content with Response.Write? Or is it another approach?
Oct 16 '09 #7
Frinavale
9,735 Expert Mod 8TB
Well, you could do the pop-up thing but I was thinking about something a little different. I would think that the JavaScript Object would do 3 things.

First of all, it would dynamically create an iFrame element that you could use as I my original suggestion.

Secondly, it would provide a method that would set the src of the iFrame to the ASPX page that will generate the excel file.

Lastly, it would hijack the onclick events for the dynamic links (buttons?) in your GridView to make them execute the JavaScript method that sets the src for the iFrame.

What do you think?

-Frinny
Oct 16 '09 #8
Hey, thanks for the explanation...

I actually ended up solving the issue in a very different way.

I add my context menu buttons to a panel and add that panel to the Controls collection of my server control before the CreateChildControls is called (so in OnInit). At that point, I also attach my event handlers to each of the buttons. This ensures me that the handlers will be called. Although the menu is shown without adding the panel to the controls collection, this is vital because if it's not in there CreateChildControls will not be called and my event handlers will not be triggered.

So now my button clicks raise server side events and allow me to run server side logic. For the export to excel I had the problem that I could not immediatly modify the Response.Write. I made it easy for myself by using the following technique:

1) In my Server Control there's a class ExcelViewer, which inherits from Page (so it is a page).
2) That class contains a shared field (shared, to make it easy for myself) which contains the data for the excel.
3) In the event handler I generate the actual excel file as a string and then assign it to the shared field of my ExcelViewer class. After this, I raise an ExcelExported event.
4) In the Page_Load of the ExcelViewer I do my Respone.Write manipulations and write the excel data to it (I change the content-type etc...)
5) In the website that is using my grid all I have to do is create an ASPX page which inherits from my ExcelViewer page and then handle the "ExcelExported" event of my grid. In that handler I simply do a Response.Redirect() to my ASPX page that inherits from the viewer.

The Response.Redirect should work even if the grid is inside updatePanels.
Nov 13 '09 #9
Frinavale
9,735 Expert Mod 8TB
I'm glad you solved your problem!

You're right it's a completely different approach. I would never have thought of making a server control that inherits from Page. I'm impressed that you got it to work this way!

Congrats!
Nov 13 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: RussC | last post by:
My C# app has a toolbar with 12 or so buttons on it, all created via the designer. In some circumstances we need to add one or two buttons to it dynamically. I have code that does this and it...
1
by: Bob | last post by:
I have a requirement to show a label and x number of buttons in all of the pages. So i decided to write a Base Page class and added code for dynamically adding the label and buttons. For the...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
2
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
0
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I have a Wizard that have about 5 steps and in every step (page) I do have some tables, checkboxes, gridview...etc and I'm trying to Cut and Paste this wizard into Ajax UpdatePanel for Ajax...
0
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Hi, I have a Wizard that have about 5 steps and in every step (page) I do have some tables, checkboxes, gridview...etc and I'm trying to Cut and Paste this wizard into Ajax UpdatePanel for Ajax...
3
by: JacekDr | last post by:
Hello, I've got the following problem: I want to add and remove dynamically controls to UpdatePanel. In my user control I have a button, but when I click it I get AsyncPostback and Event for...
23
by: rsdev | last post by:
Hi, I have read hundreds of post regarding this issue, but none have an answer for my situation. So hopefully somebody here can help! I have a gridview in an updatepanel (AJAX control toolkit)...
5
by: Pselus | last post by:
I have a dynamically created page. The page creates an UpdatePanel (created at Design time) which has an ASP:Table (design time) in it. The table has rows with a textbox (run time) that runs some...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.