Click here to Skip to main content
15,881,380 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Comments
Casey Sheridan 14-Nov-12 16:15pm    
Can you perform the calculation in the new window?
Matt Maynard 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.
ZurdoDev 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 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.
ZurdoDev 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().

No, ASP.NET requires only one. If you add another form tag, it won't have viewstate.
 
Share this answer
 
Comments
Matt Maynard 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.
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900