Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
My user's requirement is simple: have two buttons on the page, one that displays a PDF in a new window, and another that performs a calculation and displays the result in the same window. If I set
Form.Target = "_blank";
in the Page_Init, it puts the results for both buttons in a new window. If I leave it alone, it puts both of them in the same window. As far as I can tell, I need two forms with separate targets, one for each button, but all my searchy-fu seems to indicate that this is not possible with ASP.Net. Has anyone done anything like this?
Posted 14-Nov-12 10:12am
Comments
GeekforChrist at 14-Nov-12 16:15pm
   
Can you perform the calculation in the new window?
Matt Maynard at 14-Nov-12 16:24pm
   
No, the requirement is that the results from that button be displayed in the same window. Essentially, I have to decide the Form.Target value before the user clicks one of the buttons - hence the two form idea.
ryanb31 at 15-Nov-12 8:26am
   
Is the pdf just a hyperlink? If not, use JavaScript to open it in a new window and just stick with one form.
Matt Maynard at 15-Nov-12 12:29pm
   
That's one possibility, but the button decides what pdf to show based on a text input. If the pdf does not exist, I need to display an error message on the page. I suppose I could do the file check in javascript (maybe), then redirect if it exists.
 
Alternately, I could pop the second window at a different page (call it viewpdf.aspx) and redirect back to the original page, but then I'd have to display the 404 error message there. It's worth thinking about though.
ryanb31 at 15-Nov-12 12:48pm
   
Possibly call a webservice using jQuery's ajax() call and if the result coming back is that the file does not exist than you can display that message otherwise maybe you pass back the url of the pdf and then can use window.open().
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

No, ASP.NET requires only one. If you add another form tag, it won't have viewstate.
  Permalink  
Comments
Matt Maynard at 14-Nov-12 16:27pm
   
That pretty much fits with what I've seen. One thing I saw had two forms but only one of them set to runat="server", but that won't work for me.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Like Christian said, ASP.NET only allows for a single Form tag per page.
 
But, it would require restructing your site and code, you could use straight HTML or some other framework, like MVC, which doesn't have the single form limit.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 CPallini 490
2 George Jonsson 297
3 OriginalGriff 250
4 Suvabrata Roy 209
0 OriginalGriff 4,873
1 CPallini 3,900
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,646
4 Gihan Liyanage 2,236


Advertise | Privacy | Mobile
Web03 | 2.8.140905.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100