Scenario:
I have a ASPX (with no form element) let's call it Page A, the form contains a DIV that displays a ASPX page with a FileUpload Control in a form element, Page B.
Requierment:
Submit the form to upload the file, without Page A refreshing or navigating out and displaying the result of the upload in the DIV or Page B.
Problem:
When I hit the submit button to upload the file, the file uploads and Page A turns into Page B.
Any suggestion will be very appreciated.
Thank you,
You can use PreviousPage to do this.
1) Create a property in Page A to expose the file name o something else that you need to expose in Page B, for exemple:
public string FileName
{
get { return fileUpload.FileName; }
}
2) On the submit button event in Page A redirect to Page B
protected void btn_Click(object sender, EventArgs e)
{
/*Save file here*/
this.Server.Transfer("~/PageB.aspx");
}
3) Add the directive in Page B aspx that tell which page is the PreviousPage:
<%# PreviousPageType VirtualPath="~/PageA.aspx" %>
4) Use the public property in Page B to show the result to the user, for exemple put it in a label:
Label1.text = this.PreviousPage.FileName;
Hopes this help! Take a look here for more info: How to: Pass Values Between ASP.NET Web Pages
Related
Hi all I was designing web application in that i have two master pages Default.aspx and Addregistration.aspx in addregistration i stored the data in database using SQL and i display data in default page as a gridview and I made my column as hyperlink in grid view when I click that link it should go to addregistration page how I store the data with fields and text what I type.Below is the Css for column
Handle it by javascript. Your NavigateUrl is #, and add an onclick event, Or just use an input type button to make it easier
<asp:HyperLink ID="hlink" CssClass="control" runat="server" NavigateUrl='#' onclick="gotoRegistration(<%#Bind("ReferenceNo")%>)" Text='<%#Bind("ReferenceNo")%>'></asp:HyperLink>
try there to pass the ReferenceNo to the JS function, if Bind doesn't work, try Eval.
and your JS
<script>
function gotoRegistration(theRefNo)
{
theUrl = "~/AddRegistration.aspx?refNo="+ theRefNo
window.location = theUrl;
}
</script>
And then your Registration page read it from Query of the Request
Use the Page.PreviousPage Property to get data or access controls at Default.aspx from Addregistration.aspx
sample code in Addregistration.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Page.PreviousPage.FindControl("hlink")
}
I use to generate pdf from my web page wkhtmltopdf.
My project is on ASP.Net and on Bootstrap. So buttons on page has common classes btn btn-primary.
As i know if i set to some element .Visible = false; this element will be invisible on pdf. As there are many buttons on page it isn't too nice to set visibility to each button by Id.
So how can i get all buttons from page just by className?
What i found :
In some post on Stack user advice to add event OnPreRender and in this event set visibility to false. Example:
<asp:LinkButton ID="lnkContinue" runat="server" OnClick="lnkContinue_Click" CssClass="btn btn-primary" Text="Continue" OnPreRender="Button_PreRender"></asp:LinkButton>
protected void Button_PreRender(object sender, EventArgs e)
{
var button = (HtmlGenericControl)sender;
button.Visible = !button.Attributes.CssStyle.Value.Contains("btn btn-primary");
}
You can supply your own javascript function to wkhtmltopdf to iterate over each element and make them invisible:
http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
--run-script js
var eles = document.getElementsByClassName('btn btn-primary');
for (var x = 0; x < eles.length; x++) {
eles[x].style.visibility = false;
}
You should not directly use the HTML generated for your webpage as the HTML for the PDF. Your webpage will likely have navigation and other UI elements (like the mentioned buttons) that aren't appropriate for display in the PDF.
A better solution is to separately generate the HTML. This allows you to retain control over the exact markup used to create the PDF. You can manually build the HTML with StringBuilder or use other libraries to create it.
My favorite way of doing this is using the Razor PDF for MVC library. You use Razor syntax (which is very intuitive) to generate a PDF.
I have a mainpage with a Button with some content. I want to open a second page or popup in witch i must have a longlistselector with X items in it. when i choose one of them i want to change the content of the button to the selected item.
I can make the main page and the second page i dont know how to send back the result to the first page. ?
if you are using "MVVM Light" library then you can use Messenger service Like this....
in second page after selection is changed send a message
Messenger.Default.Send<type>(message,token);
and then in the consructor of page 1 viewmodel
Messenger.Default.Register<type>(this,token,Method);
here token should be same as sender token....
then
void Method(type message)
{
button.content = message;
}
Use Popup to show your LongListSelector ,and when set popupElement.IsOpen=false; the set Button Content same as required,
If you wish to change content as selected list then use popupElement.IsOpen=false; on selection change method and get selected item there.
Remember use selection change method on page not inside popup child class.
If you are using a separate page to show the longlistselector, then you could try something like this.
//in long list page,
Void longlist_SelectionChanged()
{
PhoneApplicationService.Current.State["key"] = longlist.selecteditem;
NavigationService.GoBack();
}
//in your main page where the selected data has to be displayed..
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
if(PhoneApplicationService.Current.State.ContainsKey("key"))
{
Button.Content = PhoneApplicationService.Current.State["key"];
}
}
OK, here is the problem I have. I have a servlet that dynamically creates an image (not based on parameters) which I do NOT want to save on the HDD.
I also have a HTML template (JSP) where I want to show that picture.
I create my image as following:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PieDataset dataset = createDataset();
JFreeChart chart = createChart(dataset, "OS Usage");
resp.setContentType("image/png");
ChartUtilities.writeChartAsPNG(resp.getOutputStream(), chart, 500, 400);
req.getRequestDispatcher("report.jsp").forward(req, resp);
}
My JSP looks like this:
<body>
<h1>OS usage</h1>
<p>Here are the results of OS usage in survey that we completed.<br>
<p><img alt="OS usage" src="/reportImage">
</body>
When that code is executed, I get what I expected, from the way I wrote my code, a image only, without any html.
My question is how to do it so the HTML renders as well.
Thx.
You should have two servlets:
One to generate the HTML page (by forwarding to a JSP). This generated page contains <img src="/reportImage" .../>. When the browser sees this tag, it sends a second request, to the URL /reportImage.
One to generate the image, mapped to the /reportImage URL. This servlet should only send the bytes of the image to the response output stream. It must not forward to a JSP.
declare count=0 in your servlet.. if u get image then increment the count value.. now tha value is 1.. in your jsp code put one condition if count==1 show that img else hide the tag
In my application I use a javascript function to set the src tag of an Iframe:
function loadDocument(id, doc) {
$("#DocumentContent").show();
$("#ButtonBox").show();
// Clear dynamic menu items
$("#DynamicMenuContent").html("");
$("#PageContent").html("");
// Load document in frame
$("#iframeDocument").attr("src", 'ViewDoc.aspx?id=' + id + '&doc=' + doc + '');
// Load menu items
$("#DynamicMenuContent").load("ShowButtons.aspx");
// Set document title
$("#documentTitle").load("GetDocumentInfo.aspx?p=title");
}
When I open Fiddler and debug this page, I notice that the 'ViewDoc.aspx' page is called twice.
When I put an alert() in the loadDocument function, I get only one alert message. In my viewdoc.aspx page there are no refresh or redirect statements or other statements that refreshes the page.
Is it possible this has something to do with browser? Is this default browser behavior?
the issue is pretty old, but....
do you have two elements with id=DynamicMenuContent ?
if there's one in the source page and one in the iframe, they may both be selected by $("#DynamicMenuContent").load...
if this is true and one is a div and the other a span, you could change it to $("div#DynamicMenuContent").load()...
hth