C# - Loading A File From Page Methods?

Dec 7, 2010

I have a JavaScript function which calls a page method as follows:

function openFile(file) {
PageMethods.LoadFile(file);
}
[System.Web.Services.WebMethod]
public static void LoadFile(string fileName)
{
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.ContentType = "application/binary";
var filePath = @"C:MyFiles" + fileName;
HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename="{0}"", fileName));
HttpContext.Current.Response.WriteFile(filePath);
HttpContext.Current.Response.End();
}

The page method throws the following exception:

Microsoft JScript runtime error: Sys.Net.WebServiceFailedException: The server method 'LoadFile' failed with the following error: System.Threading.ThreadAbortException-- Thread was being aborted.

View 1 Replies


Similar Messages:

Best Practice: General Asmx Data Loading Web-method Or Multi Web-methods

Apr 3, 2011

which is better approach from performance point of view, is it better to use one web-service method to load data by passing Database Table name and keys or is it better to use separate method for each database table! knowing that i'm using .net asmx through ajax requests.it's obvious that one method is better from OO perspective since it have one function type 'data loading' but what about performance? does IIS affected by that or not? also is it better to make multi web-services 'asmx files' or just one!

View 3 Replies

Windows - .NET Web Page Loading - The First Page Loading Fails With HTTP 404 Error?

Jan 18, 2011

We have installed a web site written by others which is compiled with Visual Studio 2008 and hosted in Windows server 2008 R2.

The IIS connection timeout is set to 120 seconds. But for some pages, the first page loading fails with HTTP 404 error but sequential refresh can bring the page up. The same problem happens for some images which fail to load in web pages. We are not very sure it is network related issue or hosting issue.

View 1 Replies

AJAX :: Display Light Box Loading Image On Page When Update Panel Is Loading

Mar 6, 2013

I have update panel on the page to avoid postback and placed a dropdownlist control within that update panel. DrodownList is filled with Category names and also it's autopostback set to True.

Now whenever dropdownlist index change's on select, untill page loads complete  data it should show mesage as "Loading.... in center and middle of the page and background should become bit transparent". And when page load completely with data then that background and message should get disappear.

View 1 Replies

Want To Display A Loading Animation While Page Is Loading

Jun 23, 2010

I want to display a loading animation while my page is loading, and when loading is complete then obviously hide it.

I am working in ASP.NET using Masterpages, just wondering there is a a simple way of doing this using JQuery?

View 3 Replies

C# - Webclient Upload File Methods?

Nov 21, 2010

It seems that webclient supports PUT and POST uploading. Is there any difference?

View 1 Replies

Put Autocomplete Methods In Separate Web File?

Dec 16, 2010

I have a web site with a growing number of AJAX calls.

I have AJAX code that looks like this:

function setupNameAutocomplete(id) {
$(id).autocomplete({
source: function(request, response) {
$.ajax({
url: "selectName.aspx/getNameAutocomplete",

Originally, the above javascript code was used on a web page where a user typed in the name of a person to search for; I decided I wanted to have autocomplete on the name.

However, as I continued to develop the web site, I decided that I wanted to be able to use the same "name" autocomplete on many pages. Logically, it made sense to put my javascript code in an external .js file instead of repeating it on every page.

It also makes sense that I would want to put the .net code that handles the AJAX in its own file as well. The .net autocomplete code looks like this:

[WebMethod]
public static IEnumerable<string> getNameAutocomplete(string text)
{
IEnumerable<string> values = lookupNamesThatStartWith(text);
return values;
}

Naturally, it seemed like this codes belongs in an external .asmx or perhaps a .ashx file, but I can't get my javascript code working unless I call the above code from selectName.aspx.

How can I get my AJAX .net code in a seperate code file?

View 1 Replies

AJAX :: How To Call Page Methods From A Master Page

Oct 15, 2010

I have written web methods in code behind and I'm able to call them using PageMethods.(method name) in an ordinary aspx page.

If I'm trying to call the webmethods in a master page using PageMethods.(method name), it is throwing a jscript error pagemethods is undefined.

My code is like this:

[Code]....

[Code]....

View 10 Replies

Calling Page Methods Of UserControl / Page Using MSAJax?

Apr 9, 2010

Is it possible to call usercontrol methods/events using MSAJAX. I wanted to update my usercontrol by calling one of its events when a property from its parent page changes.

View 2 Replies

Using Extension Methods In Static Methods On Extended Classes?

Aug 16, 2010

I have an extension method as follows:

public static class PageExtensions
{
public static int GetUserId(this Page targetPage)
{
var user = Membership.GetUser(targetPage.User.Identity.Name);
return (int)user.ProviderUserKey;
}
}

Now in a page I need to use this method in a static WebMethod, so I have added another 'extension method' to PageExtensions:

public static int GetUserId()
{
return (int)Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey;
}

and I call it as follows in my WebMethod: PageExtensions.GetUserId()

View 1 Replies

Web Forms :: How To Change This Methods In To Use Dictionary Or Extension Methods

Jul 23, 2010

public class CacheHelper { /// <summary> /// Removes object with the specified key. /// </summary> /// <param name="key">The key.</param> [code]....

I have this methods for caching..I need to change this methods to use in aDictionary<string,object>

How do I need to change this code Because I am new to asp.net I am still learning..

View 12 Replies

Marking Event Handler Methods As Private In Global.asax.cs File

Mar 22, 2010

I got this security warning ReviewVisibleEventHandlers(CA2109)for all event handler methods that are present in Global.asax.cs file(Application_Start,Session_Start,Application_BeginRequest,Application_EndRequest,Application_AuthenticateRequest,Application_Error,Session_End,Application_End.

I am trying to fix this warning by marking all event handler methods that are present in Global.asax.cs file as private. Does it result in any side effects in web application execution?

View 2 Replies

AJAX :: Use Page Methods In Content Page?

Oct 4, 2010

I wish to create a website based on ajax functionality using Master and Content pages.I want to use page method or xmlhttprequest object to check some validations in registration form,which is a content page of my website. Is it possible to work so or is there any other method to do it.

The code I'v written using page method in normal aspx page working fine but it is not working in contnet page.

View 1 Replies

Web Forms :: Call Common Methods From A File Called CommonMethods In AppCode Folder

Jun 12, 2012

i have few most commonly used menthods defined in a file called  CommonMethods in App_Code Folder of my asp.net project. how can call them in an *.aspx.cs page.

View 1 Replies

Put Web Methods In Master Page?

Mar 2, 2011

How i can put Web Methods in master and i not put Update Panel in master page

View 1 Replies

Loading A Css File Dynamically?

Jan 26, 2011

I have the following code in my <head>

<% if(Context.User.IsInRole("Reseller")) {%>
<link href="<%: themelocation %>" rel="stylesheet" type="text/css" />
<%} else {%>
<link href="<%= Url.Content("~/Content/custom-theme/jquery-ui-1.8.5.custom.css") %>" rel="stylesheet" type="text/css" />
<%} %>

The issue is with themelocation, which is declared just above this block of code - like so:

<%
var reseller = new Reseller();
var storeSettings = new StoreSettings();
var themelocation = "";
if (Context.User.Identity.IsAuthenticated)
{
var resellerRepository = new ResellerRepository();
reseller = resellerRepository.GetResellerByUsername(Context.User.Identity.Name);
var storeSettingsRepository = new StoreSettingsRepository();
storeSettings = storeSettingsRepository.GetStoreSettings((int) reseller.StoreSettingsID);
themelocation = storeSettings.Theme.StylesheetLocation;
}
%>

Setting a break point shows that themelocation holds the string I need, but when the page is run - it generates a 400 - Bad Request error, and the net tab in firebug reveals its looking for this:

http://localhost:50982/%3C%:%20themelocation%20%%3E

Where am I going wrong here? Why is it using the variable name, and not what it contains?

I'm using ASP.NET MVC2, and all of this code is located on my master page.

View 1 Replies

MVC :: Javascript File Not Loading?

Jul 1, 2010

I am currently trying to develop an application based on the NerdDinner sample and integrating some other stuff.

This is a very basic thing but i just cant seem to get it working.

In the site.master page, i have included the following script and other standard script files.

[Code]....

View 4 Replies

Common Usage Are Page Methods In 4?

Mar 4, 2011

How common usage are Page Methods in ASP.NET 4?I would like an example of how it's used (not a code sample).

View 3 Replies

C# - Page Methods Throwing Undefined?

Dec 1, 2010

I am trying to use page methods to call a function and I am getting a "PageMethods is undefinded" error. I have used them before whilst using C# but not VB so I'm wondering if my syntax is wrong as all examples I can find are C#.I am also wondering if it's because my scriptmanager is on the master page?I've read about this error everywhere but everything I have appears to be correct!

My code:

Part of Master Page

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" EnablePageMethods="true" >
</asp:ScriptManager>[code]....

View 2 Replies

Web Forms :: Loading .txt File Into A TxtBox

Sep 30, 2010

I have a TxtBox and a DropDownList. Right now, the DDL contains 3 different items.

[Code]....

Instead of the string "001 was chosen", I would like to be able to load a .txt from the same server as the website, for instance sss/001.txt. So that the content of the txt file is being loaded into SSTLTxtBox.Text.

View 10 Replies

Configuration :: CSS File Not Loading After Deployment?

Nov 22, 2010

I've deployed a test project onto one of our web servers, and it doesn't appear that the CSS file is taking correctly. The page loads fine, but the styles aren't there. It looked fine in dev, but not now. Any thoughts on what's going on? I'm sure there is an easy solution, but I'm very new to the ASP.NET world.

View 6 Replies

Loading A PDF File And Creating A Copy From It?

Feb 9, 2010

I am creating a PDF template file and I will want to use that to create other files. I have been looking around and found the following code:

[Code]....

The problem is that pdfreader, pdfstamper, acroreader are underlined and it says it is not declared so I couldn't test it, I wasn't sure what I had to import in order for it to work. In addition, if you have any other way that is easier to use let me know.

View 5 Replies

Web Forms :: Calling Page Methods Through VB Script

Aug 3, 2010

I Wrote code to copy Client side DB to Server side by providing the credentials required. I have a simple form, Containing three textboxes and submit button. the textboxes takes UserId,Passwd and Servername of ORACLE(Client Machine's) and when user press submit button. the VB Script method invoked. here the function follows.

Public sub DBConnect()
Dim con,usr,pwd,server
usr= form.User.Value
pwd = form.Passwd.Value
server = form.Connect.Value
Dim strcon
strcon = "Data Source=" + server + "; User ID = " + usr + ";Password=" + pwd + ";"
con.open strcon
dim rs,str
str = "select * from emp"
set rs= con.Execute(str)
if rs is not nothing then
PageMethods.SendForm(rs)
end if
End sub

Here I am getting the record set this record set I have to access in the serverside to copy the values to my datatable. How can I acheive this? How to call Page methods through VB Script. Here is my Page method.........

View 4 Replies

AJAX :: Page Methods Starting New Session?

Jun 29, 2010

I'm using ASP.NET page methods to check for the updates. I'm using inproc sessions and windows authentication in IIS 6. When page is loaded, a session is started. But sometimes when the page method is called it starts a new session(created with current request return true also). Why that might happen ?

View 2 Replies

AJAX :: Page Methods Querystrings Are Null?

Oct 20, 2010

I'm having problems with accessing querystring params in my page method. Everywhere I read it says you can access querystrings just fine, but when I try it just returns null, what's the problem?

same problem I found - [URL]

View 14 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved