|
In case anybody else needs this... The following class will handle most of the preloader logic for you.
If you don't have a server side form in your page, set a label's Text to PreloadTool.GetPreloaderTable() and then use the StartRenderedPreload() method which will render the whole page for a preloader.
If you have a server side form in your page, the StartRenderedPreload() method will cause an Exception. Instead, use the StartPreload() method which renders only the result of PreloadTool.GetPreloaderTable() as your preloader. Example:
private void Page_Load(object sender, System.EventArgs e) {
PreloadTool pt = new PreloadTool(this);
if (!IsPostBack) { pt.StartPreload(); }
if (!IsPostBack) { pt.StopPreload(); }
}
Anyway, this is the utility class I came up with to help me out.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebReports {
public class PreloadTool {
private System.Web.UI.Page page;
public PreloadTool(System.Web.UI.Page page) {
this.page = page;
}
public void StartRenderedPreload() {
System.Text.StringBuilder sb = new System.Text.StringBuilder();
System.IO.StringWriter writer = new System.IO.StringWriter(sb);
System.Web.UI.HtmlTextWriter html = new HtmlTextWriter(writer);
page.RenderControl(html);
page.Response.Write("<div id=\"preload\">");
page.Response.Write(sb.ToString());
page.Response.Write("</div>");
page.Response.Buffer = true;
page.Response.Flush();
}
public void StartPreload() {
page.Response.Write("<div id=\"preload\">");
page.Response.Write(GetPreloaderTable());
page.Response.Write("</div>");
page.Response.Buffer = true;
page.Response.Flush();
}
public void StopPreload() {
System.Text.StringBuilder txt = new System.Text.StringBuilder();
txt = new System.Text.StringBuilder();
txt.Append("<script language='javascript'>\r\n");
txt.Append("if (navigator.appName == 'Microsoft Internet Explorer' || parseInt(navigator.appVersion) > 4) {\r\n");
txt.Append(" if (document.getElementById('preload')) {\r\n");
txt.Append(" var lmnt = document.getElementById('preload');\r\n");
txt.Append(" lmnt.style.visibility = 'hidden';\r\n");
txt.Append(" lmnt.parentNode.removeChild(lmnt);\r\n");
txt.Append(" } else if (document.layers['preload']) {\r\n");
txt.Append(" document.layers['preload'].visibility = 'hide';\r\n");
txt.Append(" }\r\n");
txt.Append("}\r\n");
txt.Append("</script>\r\n");
page.Response.Write(txt.ToString());
}
public string GetPreloaderTable() {
System.Text.StringBuilder start = new System.Text.StringBuilder();
start.Append("<link rel=\"stylesheet\" href=\"Report.css\" type=\"text/css\">\r\n");
start.Append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\">\r\n");
start.Append(" <tr>\r\n");
start.Append(" <td class=\"TitleBar\">\r\n");
start.Append(" <img id=\"body_logo\" src=\"Logo.gif\" style=\"border-width:0px;\" />\r\n");
start.Append(" </td>\r\n");
start.Append(" </tr>\r\n");
start.Append("</table>\r\n");
start.Append("<table align=\"center\" valign=\"middle\" height=\"75%\" width=\"100%\">\r\n");
start.Append("<tr><td align=\"center\" valign=\"bottom\">\r\n");
start.Append("Generating report, please wait...\r\n");
start.Append("</td></tr><tr><td align=\"center\" valign=\"top\">\r\n");
start.Append("<img src=\"progress.gif\">\r\n");
start.Append("</td></tr></table>");
return start.ToString();
}
}
}
Visit BoneSoft.com
|
|
|
|
|
Hi all,
I have a windows forms client and a webservice application. I use the client to scan an image and send it to the webservice for processing. The webservice method receives the image file and saves it to disk before calling another module to process it. The following code is for clarity:
tempFile = @"c:\temp2\myfile.bmp";<br />
FileStream file = File.OpenWrite(tempFile);<br />
CopyStream(requestContext.Attachments[0].Stream, file);
On the development machine (Windows XP Pro), everything works fine but when I transfer the webservice to the testing machine (Windows Server 2003 Web Edition) I get this UnauthorizedAccessException. I gave full control rights to the ASPNET account on the server but still no use.
I use the following code to determine the owner of the webservice thread:
string name = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
I send "name" back in the exception message and I get that in fact the thread is running under this account: NT AUTHORITY\NETWORK SERVICE. Does that sound normal?
Could anyone please direct me to some kind of solution?
Thank you,
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Sounds legit. Did you give that particular account access to your temp directory?
|
|
|
|
|
well, yes, there is NETWORK SERVICE in the list of users, I gave it full control but still got the exception. Now that I'm thinking about it, what's that NT AUTHORITY thing? is it like a computer name, like COMPUTERNAME\USERNAME thing? if so, I probably didn't give the permissions to the right NETWORK SERVICE. I could check on that tomorrow again (it's almost 11pm here). I also have an ASP.NET application running on the same server. I could try and make it do some file creation and saving and see what happens.
Don't hesitate to share any idea that comes to mind concerning that matter
Thanks again.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
I know that DotNetNuke uses a lot of file manipulation and says that for Windows 2003 you need to give {Server}/NetworkService read, write, and change control. That's all I was thinking.
|
|
|
|
|
Hi again,
Finally I managed to make it work. I had to give read/write permissions to NETWORK SERVICE on the COM DLL file I'm calling from the webservice to process the image. Of course, WRITE permissions are also required for NETWORK SERVICE on the temporary folder
Voila, just thought of letting you know and post the solution in case someone gets the same problem some day.
Talal
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
Thanks for posting that. I forgot you were running the COM DLL under the calling identity. It's good to hear everything's working.
|
|
|
|
|
Hi everybody,
i was wondering if we could execute the code in a button before the postback...
because i need to save data from a placeholder in a database, before the postback of the page...
can wa do that??
Thanks
|
|
|
|
|
This is possible using AJAX and call backs...
However, why is this necessary? Is it not possible to fix this by putting an if not isPostBack in your page load method?
|
|
|
|
|
so if i want to use ajax like you said, can you tell me plz the event in javascript that i should work with if i want to use a button?
for example, if i used a dropdownlist, i have to use onchange..
thanks for the reply
|
|
|
|
|
Um, onclick...
But i have my doubts that you really need to do this... Unless you really have a need to perform this asynchronously like this, you shouldn't...
|
|
|
|
|
the thing is, i have a variable session that i increment each time i push the button... but the problem is that i have to add the controls in the load_page so i can't lose them.. so when i push the button like i said, the controls are being added again because the init and the load are executed before the button event..
see what i mean??
|
|
|
|
|
in your load_page wrap your control adding logic inside a
if (!IsPostback) {
}
So it only executes when it's not a postback. Problem solved.
Visit BoneSoft.com
|
|
|
|
|
hi paddy i'm facing the same problem.
actually my client don't want a postback of pages.
as u said we can do this by Ajax.but i don't have any idea abt Ajax could u send me some code to perform this.
u can reply me on amit_avesh@yahoo.co.in
thanx
Aavesh
|
|
|
|
|
Dear All,
How I can update multiple rows (with multiple column) , Values are from another Table.
Pls reply URgent
|
|
|
|
|
INSERT INTO TableA (AColumn)<br />
SELECT AColumn<br />
FROM TableB
|
|
|
|
|
I think its better to use a cursor, it is faster too.
|
|
|
|
|
Umm, maybe better by some standards, but definately not faster. If you'll check your SQL to English dictionary, you'll see that "cursor" means "slow as hell."
Visit BoneSoft.com
|
|
|
|
|
Hi Friends,
I have two things that I am running short of ideas on how to solve.
I am working on medium sized search form where in I will have to do
considerable validations befor it submits the form.
1).I have to put a validation on a text box ( _txtVIN ) such that it
min and max charecters should be 8. In other words user shouldn't be
able to enter more than 8 charecters of the total VIN numner. At the
same user must enter 8 charecters if at all he eneters some thing in
the text field. I have put the max length property to put a cap on the
number of charectors entered. But no clue how do I do it in the case
min of 8 charecters?
2). I have 3 text boxes. I need to make sure that atleast one filed has
the text in it before it submits the form. In other words user must
enter atleast a value in any of the text boxes. I am not sure what
control would do best to do this?
say _txtYear, _txtMake, _txtModel and the form shoudln't submit unless
user provides atleast a value in the respective fileds.
Any inputs is greatly appreciated,
Thanks,
-L
|
|
|
|
|
1.) Use a RegularExpressionValidator with a regex like "\w{8}" or something.
2.) There is a RequiredFieldValidator , but that's based on one control at a time. You could probably make a custom one that attaches to all three. You can write some javascript on your submit button to prevent it from submitting, or you can just check the text boxes in your server side code.
|
|
|
|
|
Ok I will try providing a regexp for the first one and Yeah thats what kind I thought to do the server side code. I thought there has been some thing that I am not aware of so just posted here.
Thank you for the reply,
-L
|
|
|
|
|
Hi,
I’m try to find an easy efficient way to generate my web pages dynamically from an xml/text file.
What exactly I want?
I want that whenever a pages is loaded it will go and read an xml/text file which will include the style of the page (tables,div, web controls, etc) and will build the page according to that. Meaning that initially the page (“default.aspx”) has no html on it and its entire html is built on the fly, per request. Please keep in mind that that text/xml file may include names of webcontrols that will have to be added to the page as will and will render themselves.
In a nutshell, I’m trying to find a way to inject to an aspx file its “hard core” html (the html which exist at design time in the aspx file) before its start to load and render itself. Please keep in mind that I cannot/don’t want to start creating those files on the fly, hence, no file IO writing.
I there any simple way to implement such a thing?
I’m working with .NET 2.0
Any idea would be great,
thanks,
Ori.
|
|
|
|
|
You need some kind of xslt file(s) to change your xml to html. You could then load up your xml at runtime, bind it to an xml view control along with your xslt.
|
|
|
|
|
Hi,
Using the Fileupload control in asp.net 2.0, how is it possible to make the control show only certain file types. i.e. .xls.txt...
Thanks
|
|
|
|
|
It's not. That's controlled by the browser.
|
|
|
|