Web Forms :: Render Page To String In Separate Thread?
Feb 24, 2010
I've got a page that I'm using as an e-mail template. I'd like to spin off a new thread, take the rendered page, and put it into an e-mail. Is this possible? If so, how? I haven't had luck so far.
View 3 Replies
Similar Messages:
Sep 2, 2010
i have the code for asynchronous call to the database. i execute the sql command into the begin method that will executed onto the separate thread. now i want to execute the another database call asynchronously so that this also execute onto the separate thread. code for one database cal is here....
private SqlConnection con, con1;
private SqlCommand cmd, cmd1;
private SqlDataReader dr, dr1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
AddOnPreRenderCompleteAsync(new BeginEventHandler(Begin),
new EndEventHandler(End)
);
}
}
/////////////BEGIN METHOD
IAsyncResult Begin(object sender, EventArgs e,AsyncCallback cb, object state)
{
string connect = "Data Source=.\SQLEXPRESS;Asynchronous Processing=true;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
con = new SqlConnection(connect);
con.Open();
cmd = new SqlCommand("SELECT FirstName,LastName,Age,Company,Profile FROM Person",con);
return cmd.BeginExecuteReader(cb, state);
}
//////END METHOD
void End(IAsyncResult ar)
{
dr = cmd.EndExecuteReader(ar);
Label2.Text = System.Threading.Thread.CurrentThread.GetHashCode().ToString();
GridView1.DataSource = dr;
GridView1.DataBind();
}
View 1 Replies
Mar 13, 2010
Normally i have a static class that reads and writes to HttpContext.Current.Cache
However since adding threading to my project, the threads all get null reference exceptions when trying to retrieve this object.
Is there any other way i can access it, workarounds or another cache i can use?
View 2 Replies
May 20, 2010
Is there a way that I can create a page and master page and have some of the values dynamicly loaded thru selecting items in the querystring parameters.....
then is there a way that I can render that page only to a text string? by calling it with some querystring parameters and have it render to a string?
I guess my question is only the second part as I already know how to create a page with masterpage etc...
I also know how to create an email and snd it. I just dont know how to render the page to a string
I guess what I mean is that I want to render the page on the server in code behind and then have a text string which would be the rendered HTML in a string variable of some sort... I dont want to render the page to a users browser... in fact there would be no user at all connected (there is no need to be)What I want to do is (in a code module) load up a page created and stored in my wed app directory. I want to be able to load it from a code module and to bhe able to load it with some parametsrs and just get the rendered HTML.
I am trying to write a module which will send a HTML email to registered users and I want that HTML to be dynamicly created depending on some values in the recipient user,s profile.
View 3 Replies
Feb 3, 2010
I have some code that is used to replace certain page output with other text. The way I accomplish this is by setting the Response.Filter to a Stream, Flushing the Response, and then reading that Stream back into a string. From there I can manipulate the string and output the resulting code. You can see the basic code for this over at [URL] However, I noticed that Page Caching no longer works after the first Response.Flush call.
I put together a simple ASP.NET WebApp as an example. I have a Default.aspx with an @OutputCache set for 30 seconds. All this does is output DateTime.Now.ToLongTimeString(). I override Render. If I do a Response.Flush (even after the base.Render) the page does not get cached. This is regardless of any programmatic cacheability that I set. So it seems that Response.Flush completely undermines any page caching in use. Why is this?
extra credit: is there a way to accomplish what I want (render output to a string) that will not result in Page Cache getting bypassed?
ASPX Page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestCacheVsFlush._Default" %>
<%@ OutputCache Duration="30" VaryByParam="none" %>
<%= DateTime.Now.ToLongTimeString() %>
Code-behind (Page is Cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
Code-behind (Page is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Flush();
}
Code-behind (Page still is not cached):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.Cache.SetCacheability(HttpCacheability.Server);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(30));
Response.Flush();
}
View 1 Replies
Feb 9, 2011
I am trying to use aspx pages as an email templates. There will likely be a bunch of objects on the page which will be used as replacements in the html. Because it's an aspx page I'll be able to use databinding, repeaters, etc. At run time, I want to be able to instantiate the aspx page from its path, pass in a bunch of properties, and then get the rendered result of the page and email it. This seems pretty straightforward from a asp.net website (maybe using BuildManager or Server.Execute.) However, I want to be able to use the same templates via a console application by just loading up a page object from its filepath. Is this possible?
View 1 Replies
Apr 2, 2010
I want to remove checked items from checklistbox (winform control) in class file method which i am calling asynchronously using deletegate. but it showing me this error message:-
Cross-thread operation not valid: Control 'checkedListBox1' accessed from a thread other than the thread it was created on.
i have tried invoke required but again got the same error. Sample code is below:
[code]....
View 1 Replies
Sep 29, 2010
Iam getting the below string in a variable"result" after xslt tranformation. if i do Page.ParseControl(result) iam able to render controls to the page. But the requirement is different. I have 4 place holders in that aspx page.I need to bind div id="Section1" to placeholder1, div id="Section2" to placeholder2 and similar the other two sections also to the corresponding place holder. how can i loop and add controls to corresponding place holder.
<div id="Section1" xmlns:asp="remove">
<asp:Label id="lblSection1" runat="server" text="section1" />
<asp:RequiredFieldValidator ErrorMessage="Mandatory Field-1" runat="server" ControlToValidate="txtNameSection1" />
[Code]....
View 1 Replies
Sep 29, 2010
Iam getting the below string in a variable"result" after xslt tranformation. if i do Page.ParseControl(result) iam able to render controls to the page. But the requirement is different. I have 4 place holders in that aspx page.I need to bind div id="Section1" to placeholder1, div id="Section2" to placeholder2 and similar the other two sections also to the corresponding place holder. how can i loop and add controls to corresponding place holder.
[Code]....
View 1 Replies
May 12, 2010
i'm just new in ASP.Net.
I want to render a Web User Control (has many server controls inside of it) as a HTML string, is there anyway to do it?
View 3 Replies
Aug 27, 2010
I want a example of multithreading .i want to use it in a web form not on console.i am using C#.net .and how to use thread.sleep method for a particular thread.
View 5 Replies
May 5, 2010
I have a textbox for a child's name. The user may enter just the first name, first name + middle name, or first name + middle name + last name for their child. How do I separate this string of texts appart so that I can compare it to the parent's last name textbox before inserting into the database? For example, if one part of the three parts in a child's name matches the parent's last name textbox then delete this part out of the child's full name before inserting into the database.
View 9 Replies
Nov 21, 2010
I have the following code:
Model:
[Code]....
Controller:
[Code]....
and the View:
[Code]....
The thing is that the HtmlContent string is getting "auto decoded" so the paragraph-elemnts gets renderd as <p>(sry might mix up decoding and encodeing..Im always getting confused by those)
anyway..I want the string to render as proper Html...how can this be achieved?
View 3 Replies
Oct 28, 2010
I want to create separate textbox for numbers and string using c# code. I should not use jquery or javascript.
Condition:
Numeric Textbox: It should not allow characters, special characters.
String Textbox: Should not allow numbers, Special characters.
View 3 Replies
Jul 13, 2010
I would like to get the html code a view would generate in a string, modify it in my controller, then add it to my JsonResult.
I found code that would do what i'm talking about from a partial. I would like to do it from an aspx View though.
Extra explanation:
Let's say I have a page Frame.aspx that /Controller/Frame will return I would like to get my hand on the response before it out so I can to wrap it with jsonp. I do not wish to edit the return result in code every time, this is why I want to load the view programmatically.
/Controller/Frame currently returns Frame.aspx's content: <html><body>hello</body></html>
Let's say there's a function that renders a view in a string builder
StringBuilder sb = new StringBuilder();
RenderView(sb, "Frame");
now take sb and wrap it with jsonp:
[code]....
View 3 Replies
Feb 28, 2010
Let's say I have a string that I retrieve from a DB like: "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et {{Hyperlink|navigateurl='/foo.aspx'}} dolore magna aliquyam."
This string may now get assigned to the Text-property of a label. What I want is to parse {{Hyperlink|navigateurl='/foo.aspx'}} and replace it with
<asp:HyperLink ID="IDLink" runat="server" Text="foo" NavigateUrl="/foo.aspx"/>
and assign the whole text including the HyperLink-Control to the Label.
Is that even possible? I think I could use reflection to create the control and set the properties. (the HyperLink-Control was just an example) But can I manage to insert the asp.net control back into the string to ensure the hyperlinks rendering as server contorl?
I hope you understand what I want. If not, feel free to post comments.
Edit1:
what do you mean by "assign the whole text including the HyperLink-Control to the Label."? can you xplain a bit, the reason for doing so ?
I think it won't work to assign the control into the string, because a asp.net control cannot be fit into a string.
After some thinking I found a way to achieve my goal. That would be to create a placeholder (I name it A). Therein some Literal control will be added. In addition I would create a placeholder (I name it B), add my Hyperlink into B, and add A into B. But I think is way to overkill.
The reason why I started thinking about this, was to gain access to Server.MapPath without replacing occurences in the string. I want to be able to use relative paths in my CMS, that get rendered like the NavigateUrl property from a hyperlink. Nevertheless I think my question with the dynamically creation is worth thinking about
View 2 Replies
Sep 29, 2010
In parent page there is an imagebutton. What I want to when user click this image button, another page will open with width=200 and height=100 with no toolbar.
View 11 Replies
Oct 11, 2010
I need to dynamically modify the contents of a column in a GridView1 before it is displayed. Basically, I need to convert every 'Environment.NewLine' in a field to a so it displays as a new line on an ASP.NET page. How do I do this?
View 2 Replies
Jul 7, 2010
I am trying to render a hyperlink to html. ( etc)
When the page loads it works fine. (and lots 10 links) on the update panel it hits the same function and tries to get another 10 links. I set the navigationURL to something like
"../Folder/Mypage.aspx?498592ghjgfosdfgo"
It is set identically both times(load and updatepanel postback) but when i try to render it to html the second time (on the update panel) it adds "../" to the front so i end up with
"../../Folder/Mypage.aspx?498592ghjgfosdfgo"
The function where it changes here
Public Shared Function RenderControl(ByVal c As Control) As String
Dim sw As New IO.StringWriter
Dim htmlw As New HtmlTextWriter(sw)
c.RenderControl(htmlw)
Return sw.ToString
End Function
c is the hyperlink which has the propertry navigationurl (this never gets changed) but the sw which ends up looking like this on load
<a id="lnkView" href="../Folder/mypage.aspx?AnTfh0ZsFP9NCxiBpM+Zd11cI+AUOF93HZQtumPgzMKky0PejGrda9I6kCFn070dOsIfq0M2AgI=">View</a>}
and this on panel update
<a id="lnkView" href="../../Folder/mypage.aspx?AnTfh0ZsFP9NCxiBpM+Zd11cI+AUOF93HZQtumPgzMKky0PejGrda9I6kCFn070dOsIfq0M2AgI=">View</a>}
View 1 Replies
Jan 27, 2010
How can we debbug a multi-thread program to see local variables of each thread using visual studio 2008.
View 1 Replies
Nov 24, 2010
I'm new to threading and have used it successfully, but limited. I can spawn a thread and have the main thread reference variables in the spawned thread, but I don't know how to allow the spawned thread to reference (and update) variables in the main thread.
Any example threading code I've seen on the web appears to be WAY more complicated than what I do, so I am unable to understand or integrate into my code.
Here is a quick example of how I use threading:
[code].....
View 3 Replies
Jun 17, 2010
I have an application that initially display 4 grid views at page load. This process takes 50-60 seconds and I would like to change the process to display the web page, show message like "Data being loaded, please wait..." and then spin off a thread that fills the various grid view. When this is done I would programatically like to do a post back to show the result. Not sure if this is possible? I tried something like this:
[Code]....
View 1 Replies
Mar 24, 2010
I am reading the Asp.net security documentation on msdn.I come across these tow terms and get really confused.
# WindowsIdentity = WindowsIdentity.GetCurrent()
which returns the identity of the security context of the currently executing Win32 thread.
# Thread = Thread.CurrentPrincipal
which returns the principal of the currently executing .NET thread which rides on top of the Win32 thread.
View 1 Replies
Jun 25, 2010
I have a password page and when someone enters an incorrect password I want to simply foil a brute force attack by having
bool isGoodPassword = (password == expected_password);
lock (this)
{
if (!isGoodPassword)
Thread.Sleep(2000);
}
I would expect that this would allow all correct passwords without stalling, but if one user enters a bad password another successful password from a different user would also be blocked. However, the lock doesn't seem to lock across ASP.NET threads.
View 4 Replies
Jan 14, 2010
I have access to two seperate databases (mySQL) located on two servers. I need to get the data, link the tables on a key field and display the results in a datagrid. My challenge is that if the search criteria changes for the display it affects rows returned from on table and should thus automatically affect the linked table and resulting data returned.
what the best approach would be to achieving this? So far I have set up a dataset with a dataadapter and table for each connection and then linked the tables in the dataset. The problem that I'm having is getting the linked resultsets to work.
On my form I have the datagrid with two Objectdatasources one for each dataadapter and i believe that's where I'm going wrong...
View 1 Replies