Resizing browser window in ActionScript - apache-flex

In my Flex page I have a link that navigates to different webpage and I want to control the size of that child webpage. For resizing, I am using JavaScript command within my ActionScript. Here is the ActionScript code:
private function openLinkEvent():void{
var baseUrl:String ="https://localhost:8080/someWebsite?customerName="customer.custName;
var jscommand:String ="window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");
}
I have 2 issues in this code:
If I do it with above mentioned way, new window is not opening and Flex page is showing error "baseUrl is undefined". Why I am not able to pass variable for my url instead of passing the url directly in window.open method?
If I directly pass the value of my baseURL("https://localhost:8080/someWebsite?customerName="customer.custName;) in window.open, it is taking value of customerName as customer.custName while it should take the real value of a customer saved in the session.
Just to clarify, when I pass baseUrl in following way, my application is working absolutely fine.
navigateToURL(new URLRequest(baseUrl))
But above command is not sufficient if I want to re-size the browser window. That is why I am using JS command integrated with ActionScript.

If I do it with above mentioned way, new window is not opening and
flex page is showing error "baseUrl is undefined". Why I am not able
to pass variable for my url instead of passing the url directly in
window.open method?
Well, baseUrl the variable is defined, however you are not using when creating your jsCommand. You are using a string entitled baseUrl; not the varibale.
This is what you have:
var jscommand:String ="window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
This is probably what you want:
var jscommand:String ="window.open('" + baseUrl + "','win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');";
Use string concatenation to create your jscommand string. so that the resulting value for jscommand is this:
window.open('https://localhost:8080/someWebsite?customerName=something','win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');
Instead of this:
window.open(baseUrl,'win','height=280,width=500,toolbar=no,scrollbars=no,resizable=no');
Hopefully that makes sense.
If I directly pass the value of my
baseURL("https://localhost:8080/someWebsite?customerName="customer.custName;)
in window.open, it is taking value of customerName as
customer.custName while it should take the real value of a customer
saved in the session.
Well, it is odd that you're missing the concatenation operator when creating your baseURL. Add the + between your string and the customer.custName:
var baseUrl:String ="https://localhost:8080/someWebsite?customerName=" + customer.custName;
I'm surprised that line was not giving a compile time error. However, since you have not elaborated on what type of class customer is, nor what custName means, it's hard to give a definitive on what is going on here. I assume that customer is an instance of a custom class you built and that custName is string property on it.

Related

Is there an equivalent to GetRouteUrl() at application/class level (.Net 4.8)?

Within classic webforms ASPX pages, I create URL routes using the following:
var url = this.GetRouteUrl("MyRouteName", new {UserId = 123}); // Generates /UserId/123
MyRouteName is defined within the Routes.RegisterRoutes() method used at startup.
However, I need to generate a URL within a helper method that lives at application-level. There is obviously no page context there, so I get an error.
The MSDN documentation states:
This method is provided for coding convenience. It is equivalent to
calling the RouteCollection.GetVirtualPath(RequestContext,
RouteValueDictionary) method. This method converts the object that is
passed in routeParameters to a RouteValueDictionary object by using
the RouteValueDictionary.RouteValueDictionary(Object) constructor.
I read these, but cannot figure out whether what I need to achieve is possible. An online search revealed some answers, but these are many years old an not easy to implement.
The following works to generate the equivalent of GetRouteUrl at application/class level:
var url = RouteTable.Routes.GetVirtualPath(null,
"MyRouteName",
new RouteValueDictionary(new { UserId = 123 })).VirtualPath;
Remember that only returns a local Url (e.g. /UserId/123) so if you need to domain name you'll have to prepend that as well:
var url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + RouteTable.Routes.GetVirtualPath(null,
"MyRouteName",
new RouteValueDictionary(new { UserId = 123 })).VirtualPath;
I have in my Global.asax file in the Application_Start
RouteTable.Routes.MapPageRoute("Level1", "{lvl1}", "~/Routing.aspx");//Any name will do for the aspx page.
RouteTable.Routes.MapPageRoute("Level2", "{lvl1}/{*lvl2}", "~/Routing.aspx");
Then my Routing.aspx.cs page handles the logic for what will happen with the request.
Mainly I Server.Transfer to an aspx page which will display the requested page.
Routing.aspx page picks up any "non-existing" page.
Hope this helps or at least gives you some more ideas.

Access request after upload (ASP classic)

So, as I figured out, when I have a form with enctype="multipart/form-data" and I upload a file, I can no longer access the object request. The following error is shown:
Cannot use the generic Request collection after calling BinaryRead.
After checking some resources, I stumpled upon a statement, which says: "This is by design". Well, okay, not here to judge about design-decisions.
To give you a quick overview, let me walk you through the code:
if request("todo") = "add" then
Set Form = New ASPForm
category = request("category")
title = request("title")
if len(Form("upload_file").FileName) > 0 then
filename = Form("upload_file").FileName
DestinationPath = Server.mapPath("personal/allrounder/dokumente/")
Form.Files.Save DestinationPath
end if
end if
Nothing too special here so far. Later however, when I try to access my request object, the error mentioned above occures:
<% if request("todo") = "new" then %>
...
My question now, how to get rid of it or fix this. I don't want to open the upload in a popup if there is another way around. This is the only solution I could think off.
Perfectly would be an object, which checks Form and request. Alternatively maybe a check at the top of the file, which object I have to use?
Thanks for any suggestions.
There used to be a very popular ASP class/component that solved ASP file uploads. The site for that component has been taken down, but the code is mirrored here:
https://github.com/romuloalves/free-asp-upload
You can include this ASP page on your own page, and on your page instantiate the class to get access to the files in your form, but also to the form variables. Here is a piece of example code (Upload.Form accesses the form fields):
Dim uploadsDir : uploadsDir = server.mapPath(".") ' whatever you want
Dim Upload, ks, fileKey, mailto
Set Upload = New FreeASPUpload
call Upload.Save(uploadsDir)
ks = Upload.UploadedFiles.keys
for each fileKey in ks
Response.write(fileKey & " : " & Upload.UploadedFiles(fileKey).FileName & "<br/>")
next
mailto = Upload.form("mailTo")
Set Upload = Nothing
If you want to stick to your own implementation, you can probably figure out how to get to the form variables in a multipart/form-data encoded data stream by having a look at the code they use to do so.

Send query string parameter from a non-web application

Ok, I've been bugging with this for too long.
I need to call my website from a rough VB.net app. Then only thing I need is to attach a query string parameter to the calling url, so I can distinguish the pages to be shown to different VB app users.
So I want to click a button and launch that website, giving this parameter.
First I was bugging with adding the system.web libraries. Now I can't use Request/Response.QueryString as well.
I tried getting some example help from this post. but as I said before - I cannot make use of Request.QueryString as I cannot import it.
I am stuck here:
Process.Start("http://localhost:56093/WebSite1?id=")
I need to attach a query string parameter to the url and then open the website with that url.
Can someone just give me a sample code for my problem.
Query parameters are parsed by the web server/http handler off the URL you use to call the page. They consist of key and value pairs that come at the end of the URL. Your code is nearly there. Say you needed to pass through the parameters:
ID = 1234
Page = 2
Display = Portrait
Then you'd turn them into a URL like this:
http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait
Therefore in your code you'd have:
Process.Start("http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait");

parsing simple xml with jquery from asp.net webservice

I'm breaking my head over this for a while now and I have no clue what I do wrong.
The scenario is as followed, I'm using swfupload to upload files with a progressbar
via a webservice. the webservice needs to return the name of the generated thumbnail.
This all goes well and though i prefer to get the returned data in json (might change it later in the swfupload js files) the default xml data is fine too.
So when an upload completes the webservice returns the following xml as expected (note I removed the namespace in webservice):
<?xml version="1.0" encoding="utf-8"?>
<string>myfile.jpg</string>
Now I want to parse this result with jquery and thought the following would do it:
var xml = response;
alert($(xml).find("string").text());
But I cannot get the string value. I've tried lots of combinations (.html(), .innerhtml(), response.find("string").text() but nothing seems to work. This is my first time trying to parse xml via jquery so maybe I'm doing something fundemantally wrong. The 'response' is populated with the xml.
I hope someone can help me with this.
Thanks for your time.
Kind regards,
Mark
I think $(xml) is looking for a dom object with a selector that matches the string value of XML, so I guess it's coming back null or empty?
The First Plugin mentioned below xmldom looks pretty good, but if your returned XML really is as simply as your example above, a bit of string parsing might be quicker, something like:
var start = xml.indexOf('<string>') + 8;
var end = xml.indexOf('</string>');
var resultstring = xml.substring(start, end);
From this answer to this question: How to query an XML string via DOM in jQuery
Quote:
There are a 2 ways to approach this.
Convert the XML string to DOM, parse it using this plugin or follow this tutorial
Convert the XML to JSON using this plugin.
jQuery cannot parse XML. If you pass a string full of XML content into the $ function it will typically try to parse it as HTML instead using standard innerHTML. If you really need to parse a string full of XML you will need browser-specific and not-globally-supported methods like new DOMParser and the XMLDOM ActiveXObject, or a plugin that wraps them.
But you almost never need to do this, since an XMLHttpRequest should return a fully-parsed XML DOM in the responseXML property. If your web service is correctly setting a Content-Type response header to tell the browser that what's coming back is XML, then the data argument to your callback function should be an XML Document object and not a string. In that case you should be able to use your example with find() and text() without problems.
If the server-side does not return an XML Content-Type header and you're unable to fix that, you can pass the option type: 'xml' in the ajax settings as an override.

How do I identify the referrer page in ASP.NET?

In VS2003, I am trying to find out the particular page where the request is coming from. I want to identify the exact aspx page name.
Is there a way to only get the page name or some how strip the page name?
Currently I am using the following instruction...
string referencepage = HttpContext.Current.Request.UrlReferrer.ToString();
and I get the following result...
"http://localhost/MyPage123.aspx?myval1=3333&myval2=4444;
I want to get the result back with out any query string parameters and be able to identify the page MyPage123.aspx accurately...
How do I do that??
Instead of calling .ToString on the Uri, use the AbsolutePath property instead:
string referencepage = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
This should get you "/MyPage123.aspx" in your case.
Edit: Had LocalPath instead of AbsolutePath by mistake
Look at the Segments property of the URI class (which is what HttpContext.Current.Request.UrlReferrer returns).
Something like HttpContext.Current.Request.UrlReferrer.Segments[1] (changing the 1 indexer to get the correct segment you require).

Resources