Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Reading html from previous page

Reply
Thread Tools

Reading html from previous page

 
 
David C
Guest
Posts: n/a
 
      11-24-2008
What is the best way to read a section of html from the previous page? I
have used the example below for an individual control, but want to be able
to read the contents of a <div id="mydiv"></div> that was on the sending
page. Thanks.
David

If Not Page.PreviousPage Is Nothing Then
Dim SourceTextBox As TextBox
SourceTextBox = CType(PreviousPage.FindControl("userinfo"),
TextBox)
If Not SourceTextBox Is Nothing Then
userinfo.Text = SourceTextBox.Text
End If
End If


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      11-24-2008
you will need to create a HtmlTextWriter, and pass it to the Render method of
the div. be sure all properties of the div's child controls are set before
doing the server transfer. any control that counts on prerender will have
troubles, so there are some restrictions on what controls will work


-- bruce (sqlwork.com)


"David C" wrote:

> What is the best way to read a section of html from the previous page? I
> have used the example below for an individual control, but want to be able
> to read the contents of a <div id="mydiv"></div> that was on the sending
> page. Thanks.
> David
>
> If Not Page.PreviousPage Is Nothing Then
> Dim SourceTextBox As TextBox
> SourceTextBox = CType(PreviousPage.FindControl("userinfo"),
> TextBox)
> If Not SourceTextBox Is Nothing Then
> userinfo.Text = SourceTextBox.Text
> End If
> End If
>
>
>

 
Reply With Quote
 
 
 
 
David C
Guest
Posts: n/a
 
      11-24-2008
Bruce,
I'm not clear on what you mean. I am trying to create a generic emailing
page that will read the contents of a specific DIV (based on id) from the
calling page and plop it into the body of an smtp email. Currently, I have
one page that emails a GridView (table) that is in that same page. However,
the user has requested this same functionality from other pages, so I
thought I could just require a DIV with a specific id and when the email
aspx page opens, it would read it and send the email...then return back to
the calling page. Thanks.

David
"bruce barker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> you will need to create a HtmlTextWriter, and pass it to the Render method
> of
> the div. be sure all properties of the div's child controls are set before
> doing the server transfer. any control that counts on prerender will have
> troubles, so there are some restrictions on what controls will work
>
>
> -- bruce (sqlwork.com)
>
>
> "David C" wrote:
>
>> What is the best way to read a section of html from the previous page? I
>> have used the example below for an individual control, but want to be
>> able
>> to read the contents of a <div id="mydiv"></div> that was on the sending
>> page. Thanks.
>> David
>>
>> If Not Page.PreviousPage Is Nothing Then
>> Dim SourceTextBox As TextBox
>> SourceTextBox =
>> CType(PreviousPage.FindControl("userinfo"),
>> TextBox)
>> If Not SourceTextBox Is Nothing Then
>> userinfo.Text = SourceTextBox.Text
>> End If
>> End If
>>
>>
>>



 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      11-24-2008
David C wrote:

> Bruce, I'm not clear on what you mean. I am trying to create a generic
> emailing page that will read the contents of a specific DIV (based on
> id) from the calling page and plop it into the body of an smtp email.
> Currently, I have one page that emails a GridView (table) that is in
> that same page. However, the user has requested this same functionality
> from other pages, so I thought I could just require a DIV with a
> specific id and when the email aspx page opens, it would read it and
> send the email...then return back to the calling page. Thanks.


Does the user ever see the email aspx page? The problem is if the button on
the main page posts to your email page, the email page will only have access
to form controls (textboxes, dropdown boxes, etc). The email page won't
have access to html elements on the page (e.g. Divs).

If the user doesn't see (or needs to see) the email page, two ideas come to
mind.

1. Open your email page in a pop-up window via JavaScript when the button
is clicked. You can pass the data to the email page via JavaScript.

2. Probably better, create an Ajax-enabled web service you can pass the Div
contents to when a button is clicked. The user never leaves the page, but
the email is sent and you can show the user a "email sent" message when the
web service returns a successful result.

Ben
--
http://allben.net/

 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      11-24-2008
David C wrote:

> Bruce, I'm not clear on what you mean. I am trying to create a generic
> emailing page that will read the contents of a specific DIV (based on
> id) from the calling page and plop it into the body of an smtp email.
> Currently, I have one page that emails a GridView (table) that is in
> that same page. However, the user has requested this same functionality
> from other pages, so I thought I could just require a DIV with a
> specific id and when the email aspx page opens, it would read it and
> send the email...then return back to the calling page. Thanks.


Does the user ever see the email aspx page? The problem is if the button on
the main page posts to your email page, the email page will only have access
to form controls (textboxes, dropdown boxes, etc). The email page won't
have access to html elements on the page (e.g. Divs).

If the user doesn't see (or needs to see) the email page, two ideas come to
mind.

1. Open your email page in a pop-up window via JavaScript when the button
is clicked. You can pass the data to the email page via JavaScript.

2. Probably better, create an Ajax-enabled web service you can pass the Div
contents to when a button is clicked. The user never leaves the page, but
the email is sent and you can show the user a "email sent" message when the
web service returns a successful result.

Ben
--
http://allben.net/

 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      11-24-2008
Ben Amada wrote:

> The problem is if the button on the main page posts to your email page,
> the email page will only have access to form controls (textboxes,
> dropdown boxes, etc). The email page won't have access to html elements
> on the page (e.g. Divs).


I take that back. If the Div on the original page is set runat="server",
then you can access the div on the page posted to. I personally find the
web service a better approach, but ...

if (PreviousPage.IsCrossPagePostBack)
{
System.Web.UI.HtmlControls.HtmlGenericControl div =
PreviousPage.FindControl("userinfo") as
System.Web.UI.HtmlControls.HtmlGenericControl;

if (div != null)
string DivContent = div.InnerHtml;
}

.... or in VB ...

If (PreviousPage.IsCrossPagePostBack) Then

Dim div As System.Web.UI.HtmlControls.HtmlGenericControl = _
TryCast(PreviousPage.FindControl("userinfo"), _
System.Web.UI.HtmlControls.HtmlGenericControl)

If Not IsNothing(div) Then
Dim DivContent As String = div.InnerHtml
End If

End If

--
Ben
http://allben.net/

 
Reply With Quote
 
David C
Guest
Posts: n/a
 
      11-24-2008
Ben,
Currently, the user does not need to see the email page. I was hoping to do
everything in the Page_Load event and then redirect back to the page that
called OR just do it from a pop-up window. I am not familiar with coding a
web service so I wouldn't have any idea how to handle that.

David
"Ben Amada" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> David C wrote:
>
>> Bruce, I'm not clear on what you mean. I am trying to create a generic
>> emailing page that will read the contents of a specific DIV (based on
>> id) from the calling page and plop it into the body of an smtp email.
>> Currently, I have one page that emails a GridView (table) that is in
>> that same page. However, the user has requested this same functionality
>> from other pages, so I thought I could just require a DIV with a
>> specific id and when the email aspx page opens, it would read it and
>> send the email...then return back to the calling page. Thanks.

>
> Does the user ever see the email aspx page? The problem is if the button
> on the main page posts to your email page, the email page will only have
> access to form controls (textboxes, dropdown boxes, etc). The email page
> won't have access to html elements on the page (e.g. Divs).
>
> If the user doesn't see (or needs to see) the email page, two ideas come
> to mind.
>
> 1. Open your email page in a pop-up window via JavaScript when the button
> is clicked. You can pass the data to the email page via JavaScript.
>
> 2. Probably better, create an Ajax-enabled web service you can pass the
> Div contents to when a button is clicked. The user never leaves the page,
> but the email is sent and you can show the user a "email sent" message
> when the web service returns a successful result.
>
> Ben
> --
> http://allben.net/
>



 
Reply With Quote
 
Ben Amada
Guest
Posts: n/a
 
      11-24-2008
David C wrote:

> Ben, Currently, the user does not need to see the email page. I was
> hoping to do everything in the Page_Load event and then redirect back to
> the page that called OR just do it from a pop-up window. I am not
> familiar with coding a web service so I wouldn't have any idea how to
> handle that.


Okay. You can still access the Div on a crosspage postback (see my other
post). Or you can use the pop-up window. One other option is to perform a
regular postback (non-crosspage), and call a function in a custom class you
have to send the email. This class would go in the App_Code folder and
would be accessible by any page in your project. This last option is more
of a traditional approach in ASP.NET. Good luck.

--
Ben
http://allben.net/

 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      11-25-2008
with some restictions on the controls in the div, do the following:

var div = Page.PreviousPage.FindControl("divName');
if (div != null)
{
// render the div

var sb = new StringBuilder();
using (var sw = new StringWriter(sb))
{
using (var htmlTW = new HtmlTextWriter(sw))
{
div.RenderControl(htmlTW);
}
}

// get the html

var html = sb.ToString();
}

-- bruce (sqlwork.com)


"David C" wrote:

> Bruce,
> I'm not clear on what you mean. I am trying to create a generic emailing
> page that will read the contents of a specific DIV (based on id) from the
> calling page and plop it into the body of an smtp email. Currently, I have
> one page that emails a GridView (table) that is in that same page. However,
> the user has requested this same functionality from other pages, so I
> thought I could just require a DIV with a specific id and when the email
> aspx page opens, it would read it and send the email...then return back to
> the calling page. Thanks.
>
> David
> "bruce barker" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > you will need to create a HtmlTextWriter, and pass it to the Render method
> > of
> > the div. be sure all properties of the div's child controls are set before
> > doing the server transfer. any control that counts on prerender will have
> > troubles, so there are some restrictions on what controls will work
> >
> >
> > -- bruce (sqlwork.com)
> >
> >
> > "David C" wrote:
> >
> >> What is the best way to read a section of html from the previous page? I
> >> have used the example below for an individual control, but want to be
> >> able
> >> to read the contents of a <div id="mydiv"></div> that was on the sending
> >> page. Thanks.
> >> David
> >>
> >> If Not Page.PreviousPage Is Nothing Then
> >> Dim SourceTextBox As TextBox
> >> SourceTextBox =
> >> CType(PreviousPage.FindControl("userinfo"),
> >> TextBox)
> >> If Not SourceTextBox Is Nothing Then
> >> userinfo.Text = SourceTextBox.Text
> >> End If
> >> End If
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cross Page Posting using public property on previous page =?Utf-8?B?dGhlV2l6YXJkMQ==?= ASP .Net 2 04-20-2006 08:27 PM
view state in previous page using cross page postback bill ASP .Net 6 02-17-2006 08:32 PM
How to I know the previous page is clicked to forward the current page? ABC ASP .Net 2 01-14-2006 09:30 PM
How to I know the previous page is clicked to forward the current page? ABC ASP .Net 2 01-14-2006 01:53 PM
Issues with navigating to previous page and keeping custom page properties available Greg Krzeszkowski ASP .Net 3 03-03-2005 04:59 PM



Advertisments