Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Saturday, March 31, 2012

Server side form submit

I just thinking how i can hidden all the parameter of html form, e.g:
<input type="hidden" name="test1" value="test1"
As i know, J2EE can do the server side form submit..

How's the ASP.NET implementation?

Urgent! Thank you very much!!most hidden field uses are done away with by just using the ViewState, but if you must create one, you can use this code.

Page.RegisterHiddenField("myFieldName", "myFieldValue")

Server side HTML printing

Hi,
I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.
Any ideas'
Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegroups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas'
> Thanks in advance
>
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)
Dim html As String = _stringBuilder.ToString()
'here is where you can manipulate or save to file or database or maybe print
the html output string
writer.Write(html) 'this writes the page back out
End Sub
Mike

Server side HTML printing

Hi,

I am using a rich text editor (FCKEdit) on a webpage in which user can
enter formatted text.
The output of this control is HTML. Now on the code behind side, I need
to change some of this HTML and then print the HTML (the pretty
document - not the code) on the server printer.

Any ideas??

Thanks in advance<sprash25@.gmail.com> wrote in message
news:1149837637.843058.67720@.i39g2000cwa.googlegro ups.com...
> Hi,
> I am using a rich text editor (FCKEdit) on a webpage in which user can
> enter formatted text.
> The output of this control is HTML. Now on the code behind side, I need
> to change some of this HTML and then print the HTML (the pretty
> document - not the code) on the server printer.
> Any ideas??
> Thanks in advance
Well, I can help you with the capture of the html side. The printing is
another matter. This code will capture the html just before it get sent to
the client. You also google for 'asp.net output html save'

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

Dim _stringBuilder As StringBuilder = New StringBuilder()
Dim _stringWriter As StringWriter = New StringWriter(_stringBuilder)
Dim _htmlWriter As HtmlTextWriter = New HtmlTextWriter(_stringWriter)
MyBase.Render(_htmlWriter)

Dim html As String = _stringBuilder.ToString()

'here is where you can manipulate or save to file or database or maybe print
the html output string

writer.Write(html) 'this writes the page back out

End Sub

Mike

Server side functionality

Hi All,

I have an html button on .aspx page.

<INPUT class="sbttn" id="btnComplete0" onclick="onComplete
()" type="button" value="Mark Completed"
name="btnComplete0"
When the user clicks on the html button the OnComplete
function is called.

<script language="javascript">
function onComplete()
{

// Client side code

// Clicking the server control via code
WorkItemForm.btnComplete.click();

}
</script
I need to perform some server side functinality whenever
user clicks the html button. So I place a hidden server
control (id = btnComplete) on the .aspx page. In the
client side code I automatically click the server control
( WorkItemForm.btnComplete.click();).

On the click event of hidden server control, I write the
server side code in .aspx.cs page.

// Code in .aspx.cs page

private void btnComplete_Click(object sender,
System.EventArgs e)
{
// Calling Server Side Code
}

I am using btnComplete server control as an intermediate
to perform server side functionality.

Problem:

I want to get rid of server control.
Is there a way to perform server side functionality
directly without using server control.

I tried document.FormName.Submit();

This doesn't work. Is there some other way to do so?

Thanks & Regards,
-ReetuHi Reetu,

Here's some VB code that might help you. It uses the submit() method. Not sure
why it didn't work for you.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Literal1.Text = "<script>function
onCompleted(){alert('action');document.forms[0].submit();}</script>"
If IsPostBack Then
Label2.Text = "I was posted back at: " & Now.TimeOfDay.ToString
End If
End Sub

<form id="Form1" method="post" runat="server">
<p>
<asp:textbox id="TextBox1" runat="server"></asp:textbox></p>
<p>
<asp:label id="Label2" runat="server"></asp:label></p>
<p>
<asp:label id="Label1" runat="server"></asp:label></p>
<p>
<asp:literal id="Literal1" runat="server"></asp:literal></p>
<p> </p>
<p> </p>
<input class="sbttn" id="btnComplete0" onclick="onCompleted()"
type="button" value="Mark Completed"
name="btnComplete0">
</form
"Reetu" <reetu@.ascentn.com> wrote in message
news:06c901c35c60$5aabcc10$a301280a@.phx.gbl...
Hi All,

I have an html button on .aspx page.

<INPUT class="sbttn" id="btnComplete0" onclick="onComplete
()" type="button" value="Mark Completed"
name="btnComplete0"
When the user clicks on the html button the OnComplete
function is called.

<script language="javascript">
function onComplete()
{

// Client side code

// Clicking the server control via code
WorkItemForm.btnComplete.click();

}
</script
I need to perform some server side functinality whenever
user clicks the html button. So I place a hidden server
control (id = btnComplete) on the .aspx page. In the
client side code I automatically click the server control
( WorkItemForm.btnComplete.click();).

On the click event of hidden server control, I write the
server side code in .aspx.cs page.

// Code in .aspx.cs page

private void btnComplete_Click(object sender,
System.EventArgs e)
{
// Calling Server Side Code
}

I am using btnComplete server control as an intermediate
to perform server side functionality.

Problem:

I want to get rid of server control.
Is there a way to perform server side functionality
directly without using server control.

I tried document.FormName.Submit();

This doesn't work. Is there some other way to do so?

Thanks & Regards,
-Reetu

When your page is loaded, checl the HTML source of your page. Your
hidden button will not be rendered at all.

Instead, you can convert your button to a aspx button and add
Javascript event to it from the code behind using

Add this line of code to your page load event.
ButtonName.Attributes.add("onClick","return onComplete()")

Now when you click on your button it will raise the onclick event on
the client side and will call onComplete Javascript function. Inside
the Javascript if you return false, the form will not be submitted and
the server side event of your button will not fire. If you return
true, form will be submitted to the server and your button's onclick
event will be fired on the server.

--
Ram

"Reetu" <reetu@.ascentn.com> wrote in message news:<06c901c35c60$5aabcc10$a301280a@.phx.gbl>...
> Hi All,
> I have an html button on .aspx page.
> <INPUT class="sbttn" id="btnComplete0" onclick="onComplete
> ()" type="button" value="Mark Completed"
> name="btnComplete0">
> When the user clicks on the html button the OnComplete
> function is called.
> <script language="javascript">
> function onComplete()
> {
> // Client side code
> // Clicking the server control via code
> WorkItemForm.btnComplete.click();
> }
> </script>
>
> I need to perform some server side functinality whenever
> user clicks the html button. So I place a hidden server
> control (id = btnComplete) on the .aspx page. In the
> client side code I automatically click the server control
> ( WorkItemForm.btnComplete.click();).
> On the click event of hidden server control, I write the
> server side code in .aspx.cs page.
> // Code in .aspx.cs page
> private void btnComplete_Click(object sender,
> System.EventArgs e)
> {
> // Calling Server Side Code
> }
> I am using btnComplete server control as an intermediate
> to perform server side functionality.
> Problem:
> I want to get rid of server control.
> Is there a way to perform server side functionality
> directly without using server control.
> I tried document.FormName.Submit();
> This doesn't work. Is there some other way to do so?
> Thanks & Regards,
> -Reetu
Thanks a lot, it works.

Regards,
-Reetu

>--Original Message--
>When your page is loaded, checl the HTML source of your
page. Your
>hidden button will not be rendered at all.
>Instead, you can convert your button to a aspx button and
add
>Javascript event to it from the code behind using
>Add this line of code to your page load event.
>ButtonName.Attributes.add("onClick","return onComplete()")
>Now when you click on your button it will raise the
onclick event on
>the client side and will call onComplete Javascript
function. Inside
>the Javascript if you return false, the form will not be
submitted and
>the server side event of your button will not fire. If
you return
>true, form will be submitted to the server and your
button's onclick
>event will be fired on the server.
>--
>Ram
>"Reetu" <reetu@.ascentn.com> wrote in message
news:<06c901c35c60$5aabcc10$a301280a@.phx.gbl>...
>> Hi All,
>>
>> I have an html button on .aspx page.
>>
>> <INPUT class="sbttn" id="btnComplete0"
onclick="onComplete
>> ()" type="button" value="Mark Completed"
>> name="btnComplete0">
>>
>> When the user clicks on the html button the OnComplete
>> function is called.
>>
>> <script language="javascript">
>> function onComplete()
>> {
>>
>> // Client side code
>>
>> // Clicking the server control via code
>> WorkItemForm.btnComplete.click();
>>
>> }
>> </script>
>>
>>
>> I need to perform some server side functinality
whenever
>> user clicks the html button. So I place a hidden server
>> control (id = btnComplete) on the .aspx page. In the
>> client side code I automatically click the server
control
>> ( WorkItemForm.btnComplete.click();).
>>
>> On the click event of hidden server control, I write
the
>> server side code in .aspx.cs page.
>>
>> // Code in .aspx.cs page
>>
>> private void btnComplete_Click(object sender,
>> System.EventArgs e)
>> {
>> // Calling Server Side Code
>> }
>>
>> I am using btnComplete server control as an
intermediate
>> to perform server side functionality.
>>
>> Problem:
>>
>> I want to get rid of server control.
>> Is there a way to perform server side functionality
>> directly without using server control.
>>
>> I tried document.FormName.Submit();
>>
>> This doesn't work. Is there some other way to do so?
>>
>> Thanks & Regards,
>> -Reetu
>.

Server side includes

Most of my web sites use server side includes to insert pieces of HTML design into the top and bottom of a page.

This has always worked fine with dreamweaver but now I am using VS2005 It doesn't seem to open these includes when viewing the site pages and therefore cannot switch to the design view.

Is there a way around this as otherwise I am completely stuck with dreamweaver and I really want to switch over to .net.

David Meagor

http://FreeOnlineSurveys.com

In VS2005, you may useMaster Pages and Content Pages or usercontrols to replace the inclues you used in classic asp.

The master page feature looks useful but with 300 or so classic ASP pages which have yet to be converted this isn't going to be practical.

It's such a shame that MS haven't provided support for server side includes in their editor as macromedia have with dreamweaver - it seems like such a simple feature to implement.

David Meagor

http://freeonlinesurveys.com

Thursday, March 29, 2012

Server side operation from javascript

Hi
I want to do some server side operation on close of a browser. I created
a server side html button and invoked a post back event on close of
browser something like
__doPostBack('btnUnlock',''); What I realised this is unreliable as the
operation is yet not completed when the browser has closed and
essentially the thread would have been killed. Is there any way in
javascript wherein I post a message to the server, wait for the response
and then the window closes something like send message and wait for the
response.
Regards
RJN
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!RJN <rjn@.yahoo.com> wrote in news:#uju2BxoEHA.556@.tk2msftngp13.phx.gbl:

> Is there any way in
> javascript wherein I post a message to the server, wait for the response
> and then the window closes something like send message and wait for the
> response.
>
There is no way to ensure this will fire. Client side javascript can be
disabled or stopped in many ways.
Instead, use the Session End event handler in the Global.asax.
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
[url]http://members.ebay.com/aboutme/spot18/[/url]
Yes, there is a very simple way. Post your message (it doesn't have to be
hacker style _doPostBack, it can be any value passed to the server in one of
legal and documented ways) and, in the response, get server-side to emit
window.close() javascript statement.
Eliyahu
"RJN" <rjn@.yahoo.com> wrote in message
news:%23uju2BxoEHA.556@.tk2msftngp13.phx.gbl...
> Hi
> I want to do some server side operation on close of a browser. I created
> a server side html button and invoked a post back event on close of
> browser something like
> __doPostBack('btnUnlock',''); What I realised this is unreliable as the
> operation is yet not completed when the browser has closed and
> essentially the thread would have been killed. Is there any way in
> javascript wherein I post a message to the server, wait for the response
> and then the window closes something like send message and wait for the
> response.
> Regards
> RJN
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!

Server side operation from javascript

Hi

I want to do some server side operation on close of a browser. I created
a server side html button and invoked a post back event on close of
browser something like
__doPostBack('btnUnlock',''); What I realised this is unreliable as the
operation is yet not completed when the browser has closed and
essentially the thread would have been killed. Is there any way in
javascript wherein I post a message to the server, wait for the response
and then the window closes something like send message and wait for the
response.

Regards

RJN

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!RJN <rjn@.yahoo.com> wrote in news:#uju2BxoEHA.556@.tk2msftngp13.phx.gbl:

> Is there any way in
> javascript wherein I post a message to the server, wait for the response
> and then the window closes something like send message and wait for the
> response.

There is no way to ensure this will fire. Client side javascript can be
disabled or stopped in many ways.

Instead, use the Session End event handler in the Global.asax.

--
Lucas Tam (REMOVEnntp@.rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Yes, there is a very simple way. Post your message (it doesn't have to be
hacker style _doPostBack, it can be any value passed to the server in one of
legal and documented ways) and, in the response, get server-side to emit
window.close() javascript statement.

Eliyahu

"RJN" <rjn@.yahoo.com> wrote in message
news:%23uju2BxoEHA.556@.tk2msftngp13.phx.gbl...
> Hi
> I want to do some server side operation on close of a browser. I created
> a server side html button and invoked a post back event on close of
> browser something like
> __doPostBack('btnUnlock',''); What I realised this is unreliable as the
> operation is yet not completed when the browser has closed and
> essentially the thread would have been killed. Is there any way in
> javascript wherein I post a message to the server, wait for the response
> and then the window closes something like send message and wait for the
> response.
> Regards
> RJN
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

Saturday, March 24, 2012

Server variables in ASP.NET Html code

Given i have some control which has an "ImageURL" property. If this property
is set, then the HTML code for the web control looks something like:
<mns:image id=MyImg runat=server ImageURL="images/somepath.jpg"></mns:image>
Given i have some server variable Session("AppRoot") which declares the full
path to the root of the application, for example
Session("AppRoot") = "http://www.someserver.com/myapp/"
Now is there any way i can put the AppRoot variable directly into the HTML
control for the mns:image control, rather than having to put code in the .vb
file to do something like
MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
Could i somehow do SOMEthing like:
<mns:image id=MyImg runat=server
ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
</mns:image>There are a number of things I don't understand.
1-
If this is your own server control, or you have access to the source, why
not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
class before the render? This way you don't have to worry about doing it
either at the page level or the codebehind. If you don't write your own
that inherits from this one.
2-
Does the AppRoot actually belong to the sesssion? it's specific to each
user?
3-
You can simply use ~ to denote the application root, ala:
ImageUrl="~/images/somepath.jpg"
4-
The answer to your question is no..but the solution in #1 will solve her
right up.
Karl
"A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> Given i have some control which has an "ImageURL" property. If this
property
> is set, then the HTML code for the web control looks something like:
> <mns:image id=MyImg runat=server
ImageURL="images/somepath.jpg"></mns:image>
> Given i have some server variable Session("AppRoot") which declares the
full
> path to the root of the application, for example
> Session("AppRoot") = "http://www.someserver.com/myapp/"
> Now is there any way i can put the AppRoot variable directly into the HTML
> control for the mns:image control, rather than having to put code in the
.vb
> file to do something like
> MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
> Could i somehow do SOMEthing like:
> <mns:image id=MyImg runat=server
> ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
> </mns:image>
>
Well, i cannot code it into the code for the control, because the control is
made in a separate library meant ot be generic to NO app in specific.
I cannot use a Root path ("/" or "~") because the app does not root at the
root of the site.
The site's root is www.myserver.com/myapp, not www.myserver.com
Otherwise then i guess im just stuck having to alter the urls in the .vb
file then. Thats a little annoying. Itd be nice if you could somehow use
something like the databinding stuff to put out a server variable into
ASP.NET html code.
"Karl" <none> wrote in message news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
> There are a number of things I don't understand.
> 1-
> If this is your own server control, or you have access to the source, why
> not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
> class before the render? This way you don't have to worry about doing it
> either at the page level or the codebehind. If you don't write your own
> that inherits from this one.
> 2-
> Does the AppRoot actually belong to the sesssion? it's specific to each
> user?
> 3-
> You can simply use ~ to denote the application root, ala:
> ImageUrl="~/images/somepath.jpg"
> 4-
> The answer to your question is no..but the solution in #1 will solve her
> right up.
> Karl
> "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> property
> ImageURL="images/somepath.jpg"></mns:image>
> full
HTML
> .vb
>
~ uses the virtual app..so it should be ~ should be equal to /myapp
and you could still make the code generic to no specific app (as it is now
actually, it's specific to apps at the root level so it isn't very
generic)...but ~ should do the trick.
Karl
"A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
news:eqKHwWTiEHA.3536@.TK2MSFTNGP12.phx.gbl...
> Well, i cannot code it into the code for the control, because the control
is
> made in a separate library meant ot be generic to NO app in specific.
> I cannot use a Root path ("/" or "~") because the app does not root at the
> root of the site.
> The site's root is www.myserver.com/myapp, not www.myserver.com
> Otherwise then i guess im just stuck having to alter the urls in the .vb
> file then. Thats a little annoying. Itd be nice if you could somehow use
> something like the databinding stuff to put out a server variable into
> ASP.NET html code.
> "Karl" <none> wrote in message
news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
why
own
the
> HTML
the
>
Hmm, .. well, i tried using the ~ instead and taking out my code in .vb to
prepend the approot to the path, but it does not work with the ~.
Thanks though for the idea.
"Karl" <none> wrote in message news:OKTWrbTiEHA.1384@.TK2MSFTNGP10.phx.gbl...
> ~ uses the virtual app..so it should be ~ should be equal to /myapp
> and you could still make the code generic to no specific app (as it is now
> actually, it's specific to apps at the root level so it isn't very
> generic)...but ~ should do the trick.
> Karl
> "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> news:eqKHwWTiEHA.3536@.TK2MSFTNGP12.phx.gbl...
control
> is
the
> news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
> why
the
it
> own
each
her
> the
the
> the
>

Server variables in ASP.NET Html code

Given i have some control which has an "ImageURL" property. If this property
is set, then the HTML code for the web control looks something like:

<mns:image id=MyImg runat=server ImageURL="images/somepath.jpg"></mns:image
Given i have some server variable Session("AppRoot") which declares the full
path to the root of the application, for example
Session("AppRoot") = "http://www.someserver.com/myapp/"

Now is there any way i can put the AppRoot variable directly into the HTML
control for the mns:image control, rather than having to put code in the .vb
file to do something like
MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL

Could i somehow do SOMEthing like:

<mns:image id=MyImg runat=server
ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
</mns:imageThere are a number of things I don't understand.

1-
If this is your own server control, or you have access to the source, why
not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
class before the render? This way you don't have to worry about doing it
either at the page level or the codebehind. If you don't write your own
that inherits from this one.

2-
Does the AppRoot actually belong to the sesssion? it's specific to each
user?

3-
You can simply use ~ to denote the application root, ala:
ImageUrl="~/images/somepath.jpg"

4-
The answer to your question is no..but the solution in #1 will solve her
right up.

Karl

"A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> Given i have some control which has an "ImageURL" property. If this
property
> is set, then the HTML code for the web control looks something like:
> <mns:image id=MyImg runat=server
ImageURL="images/somepath.jpg"></mns:image>
> Given i have some server variable Session("AppRoot") which declares the
full
> path to the root of the application, for example
> Session("AppRoot") = "http://www.someserver.com/myapp/"
> Now is there any way i can put the AppRoot variable directly into the HTML
> control for the mns:image control, rather than having to put code in the
..vb
> file to do something like
> MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
> Could i somehow do SOMEthing like:
> <mns:image id=MyImg runat=server
> ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
> </mns:image>
Well, i cannot code it into the code for the control, because the control is
made in a separate library meant ot be generic to NO app in specific.

I cannot use a Root path ("/" or "~") because the app does not root at the
root of the site.
The site's root is www.myserver.com/myapp, not www.myserver.com

Otherwise then i guess im just stuck having to alter the urls in the .vb
file then. Thats a little annoying. Itd be nice if you could somehow use
something like the databinding stuff to put out a server variable into
ASP.NET html code.

"Karl" <none> wrote in message news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
> There are a number of things I don't understand.
> 1-
> If this is your own server control, or you have access to the source, why
> not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
> class before the render? This way you don't have to worry about doing it
> either at the page level or the codebehind. If you don't write your own
> that inherits from this one.
> 2-
> Does the AppRoot actually belong to the sesssion? it's specific to each
> user?
> 3-
> You can simply use ~ to denote the application root, ala:
> ImageUrl="~/images/somepath.jpg"
> 4-
> The answer to your question is no..but the solution in #1 will solve her
> right up.
> Karl
> "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> > Given i have some control which has an "ImageURL" property. If this
> property
> > is set, then the HTML code for the web control looks something like:
> > <mns:image id=MyImg runat=server
> ImageURL="images/somepath.jpg"></mns:image>
> > Given i have some server variable Session("AppRoot") which declares the
> full
> > path to the root of the application, for example
> > Session("AppRoot") = "http://www.someserver.com/myapp/"
> > Now is there any way i can put the AppRoot variable directly into the
HTML
> > control for the mns:image control, rather than having to put code in the
> .vb
> > file to do something like
> > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
> > Could i somehow do SOMEthing like:
> > <mns:image id=MyImg runat=server
> > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
> > </mns:image>
~ uses the virtual app..so it should be ~ should be equal to /myapp

and you could still make the code generic to no specific app (as it is now
actually, it's specific to apps at the root level so it isn't very
generic)...but ~ should do the trick.

Karl

"A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
news:eqKHwWTiEHA.3536@.TK2MSFTNGP12.phx.gbl...
> Well, i cannot code it into the code for the control, because the control
is
> made in a separate library meant ot be generic to NO app in specific.
> I cannot use a Root path ("/" or "~") because the app does not root at the
> root of the site.
> The site's root is www.myserver.com/myapp, not www.myserver.com
> Otherwise then i guess im just stuck having to alter the urls in the .vb
> file then. Thats a little annoying. Itd be nice if you could somehow use
> something like the databinding stuff to put out a server variable into
> ASP.NET html code.
> "Karl" <none> wrote in message
news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
> > There are a number of things I don't understand.
> > 1-
> > If this is your own server control, or you have access to the source,
why
> > not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in the
> > class before the render? This way you don't have to worry about doing it
> > either at the page level or the codebehind. If you don't write your
own
> > that inherits from this one.
> > 2-
> > Does the AppRoot actually belong to the sesssion? it's specific to each
> > user?
> > 3-
> > You can simply use ~ to denote the application root, ala:
> > ImageUrl="~/images/somepath.jpg"
> > 4-
> > The answer to your question is no..but the solution in #1 will solve her
> > right up.
> > Karl
> > "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> > news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> > > Given i have some control which has an "ImageURL" property. If this
> > property
> > > is set, then the HTML code for the web control looks something like:
> > > > <mns:image id=MyImg runat=server
> > ImageURL="images/somepath.jpg"></mns:image>
> > > > Given i have some server variable Session("AppRoot") which declares
the
> > full
> > > path to the root of the application, for example
> > > Session("AppRoot") = "http://www.someserver.com/myapp/"
> > > > Now is there any way i can put the AppRoot variable directly into the
> HTML
> > > control for the mns:image control, rather than having to put code in
the
> > .vb
> > > file to do something like
> > > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
> > > > Could i somehow do SOMEthing like:
> > > > <mns:image id=MyImg runat=server
> > > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
> > > </mns:image>
> >
Hmm, .. well, i tried using the ~ instead and taking out my code in .vb to
prepend the approot to the path, but it does not work with the ~.

Thanks though for the idea.

"Karl" <none> wrote in message news:OKTWrbTiEHA.1384@.TK2MSFTNGP10.phx.gbl...
> ~ uses the virtual app..so it should be ~ should be equal to /myapp
> and you could still make the code generic to no specific app (as it is now
> actually, it's specific to apps at the root level so it isn't very
> generic)...but ~ should do the trick.
> Karl
> "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> news:eqKHwWTiEHA.3536@.TK2MSFTNGP12.phx.gbl...
> > Well, i cannot code it into the code for the control, because the
control
> is
> > made in a separate library meant ot be generic to NO app in specific.
> > I cannot use a Root path ("/" or "~") because the app does not root at
the
> > root of the site.
> > The site's root is www.myserver.com/myapp, not www.myserver.com
> > Otherwise then i guess im just stuck having to alter the urls in the .vb
> > file then. Thats a little annoying. Itd be nice if you could somehow use
> > something like the databinding stuff to put out a server variable into
> > ASP.NET html code.
> > "Karl" <none> wrote in message
> news:e$mfDPTiEHA.1644@.tk2msftngp13.phx.gbl...
> > > There are a number of things I don't understand.
> > > > 1-
> > > If this is your own server control, or you have access to the source,
> why
> > > not simply put the code ImageUrl = Session("AppRoot") & ImageUrl in
the
> > > class before the render? This way you don't have to worry about doing
it
> > > either at the page level or the codebehind. If you don't write your
> own
> > > that inherits from this one.
> > > > 2-
> > > Does the AppRoot actually belong to the sesssion? it's specific to
each
> > > user?
> > > > 3-
> > > You can simply use ~ to denote the application root, ala:
> > > ImageUrl="~/images/somepath.jpg"
> > > > 4-
> > > The answer to your question is no..but the solution in #1 will solve
her
> > > right up.
> > > > Karl
> > > > "A Traveler" <hitchhikersguideto-news@.yahoo.com> wrote in message
> > > news:u8B8WfSiEHA.2952@.TK2MSFTNGP09.phx.gbl...
> > > > Given i have some control which has an "ImageURL" property. If this
> > > property
> > > > is set, then the HTML code for the web control looks something like:
> > > > > > <mns:image id=MyImg runat=server
> > > ImageURL="images/somepath.jpg"></mns:image>
> > > > > > Given i have some server variable Session("AppRoot") which declares
> the
> > > full
> > > > path to the root of the application, for example
> > > > Session("AppRoot") = "http://www.someserver.com/myapp/"
> > > > > > Now is there any way i can put the AppRoot variable directly into
the
> > HTML
> > > > control for the mns:image control, rather than having to put code in
> the
> > > .vb
> > > > file to do something like
> > > > MyImg.ImageURL = Session("AppRoot") & MyImg.ImageURL
> > > > > > Could i somehow do SOMEthing like:
> > > > > > <mns:image id=MyImg runat=server
> > > > ImageURL='<%# Session("AppRoot")%>images/somepath.jpg'>
> > > > </mns:image>
> > > > > >

Thursday, March 22, 2012

Server.Execute sluggish, faster way to retrieve HTML string?

Hi,

I need to retrieve the HTML string of one of my ASP pages, and whenever I make the attempt using my code, it brings the entire server to a hault for quite a while. The server's hardware specs are perfectly fine, and I've narrowed it down to the Server.Execute line. Is there anything I can do here? Here's my code:

StringWriter sw =new StringWriter();Server.Execute("page.aspx", sw);String strHtmlCode = sw.GetStringBuilder().ToString();

Thanks!

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");


This may be because page.aspx may be huge page and it will take long time in processing. Because of this, your current page execution will stop:)

Cheers

Bhavesh


lad.bhavesh:

This may be because page.aspx maybe huge page and it will take long time in processing. Because of this,your current page execution will stop:)

Cheers

Bhavesh


Including the one image and stylesheet, it's about 55 KB.


Mikesdotnetting:

Use HttpWebRequest/HttpWebResponse:

//using System.Net;
//using System.IO;
static string GetHtmlPage(string strURL)
{

String strResult;
WebResponse objResponse;
WebRequest objRequest = HttpWebRequest.Create(strURL);
objResponse = objRequest.GetResponse();
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
strResult = sr.ReadToEnd();
sr.Close();
}
return strResult;
}

String strHtmlCode = GetHtmlPage("http://domain/page.aspx");

I apologize - I should have been more clear on the context here. A session needs to be maintained in order to access this page. Is there anything else I can use? And believe me, I've tried googling :). I'm sure it's out there somewhere, but I can't seem to find it.

Will this do you?

http://msdn2.microsoft.com/en-us/library/system.net.httpwebrequest.cookiecontainer.aspx


That'll do it, thanks!

Server.Execute reference created objects

Hi,

I have a basic aspx page, in the Page_Init procedure I have a
server.execute of another aspx page that adds some html code to my
first page. However it also adds a control (an htmlimage), now my
question is how to I get access to that control from the class in my
first page? Whenever I try to access it I get a "object reference not
set to an instance..." error.

Thank you,
JonathanWell, I think you should knew the object name of that control, you can use
FindControl function.

the code should be something like this, I giving an example of FindControl
with TextBox

CType(FindControl("MyTextBox"), TextBox).Text = "Hello"

Change the "MyTextBox" to your object name, and "TextBox" to the object
type.

Tee

"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.c om...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan
Hi Sophos:

I'm not sure how Server.Execute can return an HtmlImage "control".
Server.Execute renders the page you ask it to execute, and you fetch
the same HTML a client would see if they requested the page with a
browser.

StringWriter writer = new StringWriter();
Server.Execute("otherpage.aspx",writer);
string html = writer.ToString();
writer.Close();

You should have an image tag in the string, an image tag put in by an
HtmlImage control. You could use regular expressions or String.IndexOf
to search for the image tag, but you won't find a control.

HTH,

--
Scott
http://www.OdeToCode.com

On 9 Jul 2004 12:12:33 -0700, sophos@.postmaster.co.uk (Sophos) wrote:

>Hi,
>I have a basic aspx page, in the Page_Init procedure I have a
>server.execute of another aspx page that adds some html code to my
>first page. However it also adds a control (an htmlimage), now my
>question is how to I get access to that control from the class in my
>first page? Whenever I try to access it I get a "object reference not
>set to an instance..." error.
>Thank you,
>Jonathan
You can't directly do what it is you're trying to do but here's a work
around:

In your WebForm2, add code like this:
WebForm1 wf1 = (WebForm1)Context.Handler;

That will make WebForm1 available to the page you called with
Server.Execute. Now, in WebForm1, create an image control with its visible
property set to false, or even an array to hold the information you want to
copy. Set the protection of the image control to public.

Create a property to return the image:

public System.Web.UI.WebControls.Image MyImage
{
get { return Image1; }
set { Image1 = value; }
}

If you choose to use an array to get the values into, create a public
property in WebForm1 to return the array value:

private object imagePropertyValues[];

public object ImagePropertyValues[]
{
get { return imagePropertyValues; }
set { imagePropertyValues = value; }
}

In the code of your WebForm2, copy the properties you wish back to the
WebForm1 control or WebForm1 array. You can also copy the image object,
itself:

wf1.MyImage = Image1; // this line is in WebForm2.aspx.cs

That will let you retrieve property values back in WebForm1 but will not let
you dynamically control the values in WebForm2. If you want to dynamically
control the values in WebForm2, then create public properties or objects in
WebForm1 to hold those values prior to calling Server.Execute("WebForm2").
Then in the code for WebForm2, retrieve those values from the WebForm1
object you created in the first line of code above.

It's only slightly convoluted but you can, by using these concepts, set
values in WebForm2 and use those values in WebForm1 after WebForm2 completes
execution.

The one thing you cannot do is to change a value in WebForm2 controls after
WebForm2 returns. Think of WebForm2 as a method, and when it completes
execution, its fields are out of scope and cannot be accessed.

Dale

"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.c om...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan

Server.Execute reference created objects

Hi,
I have a basic aspx page, in the Page_Init procedure I have a
server.execute of another aspx page that adds some html code to my
first page. However it also adds a control (an htmlimage), now my
question is how to I get access to that control from the class in my
first page? Whenever I try to access it I get a "object reference not
set to an instance..." error.
Thank you,
JonathanWell, I think you should knew the object name of that control, you can use
FindControl function.
the code should be something like this, I giving an example of FindControl
with TextBox
CType(FindControl("MyTextBox"), TextBox).Text = "Hello"
Change the "MyTextBox" to your object name, and "TextBox" to the object
type.
Tee
"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.com...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan
Hi Sophos:
I'm not sure how Server.Execute can return an HtmlImage "control".
Server.Execute renders the page you ask it to execute, and you fetch
the same HTML a client would see if they requested the page with a
browser.
StringWriter writer = new StringWriter();
Server.Execute("otherpage.aspx",writer);
string html = writer.ToString();
writer.Close();
You should have an image tag in the string, an image tag put in by an
HtmlImage control. You could use regular expressions or String.IndexOf
to search for the image tag, but you won't find a control.
HTH,
Scott
http://www.OdeToCode.com
On 9 Jul 2004 12:12:33 -0700, sophos@.postmaster.co.uk (Sophos) wrote:

>Hi,
>I have a basic aspx page, in the Page_Init procedure I have a
>server.execute of another aspx page that adds some html code to my
>first page. However it also adds a control (an htmlimage), now my
>question is how to I get access to that control from the class in my
>first page? Whenever I try to access it I get a "object reference not
>set to an instance..." error.
>Thank you,
>Jonathan
You can't directly do what it is you're trying to do but here's a work
around:
In your WebForm2, add code like this:
WebForm1 wf1 = (WebForm1)Context.Handler;
That will make WebForm1 available to the page you called with
Server.Execute. Now, in WebForm1, create an image control with its visible
property set to false, or even an array to hold the information you want to
copy. Set the protection of the image control to public.
Create a property to return the image:
public System.Web.UI.WebControls.Image MyImage
{
get { return Image1; }
set { Image1 = value; }
}
If you choose to use an array to get the values into, create a public
property in WebForm1 to return the array value:
private object imagePropertyValues[];
public object ImagePropertyValues[]
{
get { return imagePropertyValues; }
set { imagePropertyValues = value; }
}
In the code of your WebForm2, copy the properties you wish back to the
WebForm1 control or WebForm1 array. You can also copy the image object,
itself:
wf1.MyImage = Image1; // this line is in WebForm2.aspx.cs
That will let you retrieve property values back in WebForm1 but will not let
you dynamically control the values in WebForm2. If you want to dynamically
control the values in WebForm2, then create public properties or objects in
WebForm1 to hold those values prior to calling Server.Execute("WebForm2").
Then in the code for WebForm2, retrieve those values from the WebForm1
object you created in the first line of code above.
It's only slightly convoluted but you can, by using these concepts, set
values in WebForm2 and use those values in WebForm1 after WebForm2 completes
execution.
The one thing you cannot do is to change a value in WebForm2 controls after
WebForm2 returns. Think of WebForm2 as a method, and when it completes
execution, its fields are out of scope and cannot be accessed.
Dale
"Sophos" <sophos@.postmaster.co.uk> wrote in message
news:9590ee74.0407091112.4f6ba07b@.posting.google.com...
> Hi,
> I have a basic aspx page, in the Page_Init procedure I have a
> server.execute of another aspx page that adds some html code to my
> first page. However it also adds a control (an htmlimage), now my
> question is how to I get access to that control from the class in my
> first page? Whenever I try to access it I get a "object reference not
> set to an instance..." error.
> Thank you,
> Jonathan

Server.HTMLDecode doesn't decode char 345

Hello!
I have a problem decoding the czech character:
r
The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.
Can anyone help me with this issue, or is it maybe a bug?
/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));
My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
maybe yours is using something else?
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
>
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:
string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );
where the text property sometimes contains the char ř
Is there some way that I can tell the HtmlDecode which encoding to use?
/Jonas
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).
All HtmlDecode does in the case of a numeric value (such as 345), is:
char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);
Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l
Karl
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>
Yes the encoding is set ut utf-8
the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode
Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine
private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}
return tmpResult;
}
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.
Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Server.HTMLDecode doesnt decode char 345

Hello!

I have a problem decoding the czech character:
r

The HTML code for this character is ř but when running
Server.HTMLdecode on that string it just returns ř instead of the real
char. (It works on a lot of other characters)
I need to decode this string in order to render an image with this character
as a part of a headline.

Can anyone help me with this issue, or is it maybe a bug?

/kindest regards, JonasThis works fine for me:
Response.Write(Server.HtmlDecode("ř"));

My web.config specifies:
<globalization requestEncoding="utf-8" responseEncoding="utf-8" /
maybe yours is using something else?

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
> Hello!
> I have a problem decoding the czech character:
> r
> The HTML code for this character is ř but when running
> Server.HTMLdecode on that string it just returns ř instead of the
> real char. (It works on a lot of other characters)
> I need to decode this string in order to render an image with this
> character as a part of a headline.
> Can anyone help me with this issue, or is it maybe a bug?
> /kindest regards, Jonas
Maybe it is because I'm usning the Server object in a function in a non web
environment - a regular class:

string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
text );

where the text property sometimes contains the char ř

Is there some way that I can tell the HtmlDecode which encoding to use?

/Jonas

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
>
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>> Hello!
>>
>> I have a problem decoding the czech character:
>> r
>>
>> The HTML code for this character is ř but when running
>> Server.HTMLdecode on that string it just returns ř instead of the
>> real char. (It works on a lot of other characters)
>> I need to decode this string in order to render an image with this
>> character as a part of a headline.
>>
>> Can anyone help me with this issue, or is it maybe a bug?
>>
>> /kindest regards, Jonas
>>
i don't think that's your problem (although within a class, there's no
reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
class from the context (ie, it can be reused outside of the web)).

All HtmlDecode does in the case of a numeric value (such as 345), is:

char c1 = (char) ((ushort) int.Parse("345"));
Response.Write(c1);

Is your page encoding set to utf-8? (if you put tracing on, at the top of
the trace information it says the encoding).l

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Jonas kermark" <jonas@.wipcore.se> wrote in message
news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
> Maybe it is because I'm usning the Server object in a function in a non
> web environment - a regular class:
> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
> text );
> where the text property sometimes contains the char ř
> Is there some way that I can tell the HtmlDecode which encoding to use?
> /Jonas
> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>> This works fine for me:
>> Response.Write(Server.HtmlDecode("ř"));
>>
>> My web.config specifies:
>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>
>> maybe yours is using something else?
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>> annoying)
>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>> come!)
>>
>>
>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>> Hello!
>>>
>>> I have a problem decoding the czech character:
>>> r
>>>
>>> The HTML code for this character is ř but when running
>>> Server.HTMLdecode on that string it just returns ř instead of the
>>> real char. (It works on a lot of other characters)
>>> I need to decode this string in order to render an image with this
>>> character as a part of a headline.
>>>
>>> Can anyone help me with this issue, or is it maybe a bug?
>>>
>>> /kindest regards, Jonas
>>>
>>
>>
Yes the encoding is set ut utf-8

the strange thing is that the decodedText property still contains the
"ř" string after HtmlDecode

Nevermind, thanks for your explanation of the HtmlDecode, I have now created
a SpecialDecode function instead that works fine

private static string SpecialDecode(string decodedText)
{
string tmpResult = decodedText;
bool found = true;
try
{
while(found)
{
if( tmpResult.IndexOf("&#") > -1 )
{
string chars = tmpResult.Substring( tmpResult.IndexOf("&#")+2, 3);
//decode
char c1 = (char) ((ushort) int.Parse(chars));
tmpResult = tmpResult.Replace("&#" + chars + ";", c1.ToString());
}
else
{
found = false;
}
}
}
catch{}

return tmpResult;
}

"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e2uGEB2lFHA.3936@.TK2MSFTNGP10.phx.gbl...
>i don't think that's your problem (although within a class, there's no
>reason not to use System.Web.HttpUtility.HtmlDecode which decouples your
>class from the context (ie, it can be reused outside of the web)).
> All HtmlDecode does in the case of a numeric value (such as 345), is:
> char c1 = (char) ((ushort) int.Parse("345"));
> Response.Write(c1);
> Is your page encoding set to utf-8? (if you put tracing on, at the top of
> the trace information it says the encoding).l
> Karl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/ - New and Improved (yes, the popup is
> annoying)
> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
> come!)
> "Jonas kermark" <jonas@.wipcore.se> wrote in message
> news:OELxjb1lFHA.2904@.TK2MSFTNGP14.phx.gbl...
>> Maybe it is because I'm usning the Server object in a function in a non
>> web environment - a regular class:
>>
>> string decodedText = System.Web.HttpContext.Current.Server.HtmlDecode(
>> text );
>>
>> where the text property sometimes contains the char ř
>>
>> Is there some way that I can tell the HtmlDecode which encoding to use?
>>
>> /Jonas
>>
>> "Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
>> wrote in message news:%23o0ElR1lFHA.3552@.TK2MSFTNGP10.phx.gbl...
>>> This works fine for me:
>>> Response.Write(Server.HtmlDecode("ř"));
>>>
>>> My web.config specifies:
>>> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
>>>
>>> maybe yours is using something else?
>>>
>>> Karl
>>>
>>> --
>>> MY ASP.Net tutorials
>>> http://www.openmymind.net/ - New and Improved (yes, the popup is
>>> annoying)
>>> http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
>>> come!)
>>>
>>>
>>> "Jonas kermark" <jonas@.wipcore.se> wrote in message
>>> news:uY3DJazlFHA.2080@.TK2MSFTNGP14.phx.gbl...
>>>> Hello!
>>>>
>>>> I have a problem decoding the czech character:
>>>> r
>>>>
>>>> The HTML code for this character is ř but when running
>>>> Server.HTMLdecode on that string it just returns ř instead of the
>>>> real char. (It works on a lot of other characters)
>>>> I need to decode this string in order to render an image with this
>>>> character as a part of a headline.
>>>>
>>>> Can anyone help me with this issue, or is it maybe a bug?
>>>>
>>>> /kindest regards, Jonas
>>>>
>>>
>>>
>>
>>
Karl Seguin wrote:

> This works fine for me:
> Response.Write(Server.HtmlDecode("ř"));
> My web.config specifies:
> <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
> maybe yours is using something else?
> Karl

Numeric references are based on Unicode code points, thus
requestEncoding and responseEncoding don't apply.

Cheers,
--
http://www.joergjooss.de
mailto:news-reply@.joergjooss.de

Server.HTMLEncode

Hey guys, im kinda struggling on this issue. I have a form that uses an html editor. My validation is set to true bc i have email, phone, and required field validations. What my task is is trying to convert the input captured in my textbox area(html editor) and convert it bc i need to keep the html code. heres my code. any help would be great. i've tried all kinds of ways to server.htmlencode it...thx

Sub Page_Load( s As Object, e As EventArgs )
If not Page.IsPostback then
'If Page.IsValid then
ThanksPnl.visible = False
FormPnl.Visible = True

TxtContent2.Text = Server.HtmlEncode(TxtContent.Text)

'End If
End If
End Sub

<tr>
<td valign="top" width="130px">Comments/Request:</td>
<td valign="top" align="left">
<asp:textbox ID="TxtContent" CausesValidation="False" width="300px" HtmlEncode="False" TextMode="Multiline" rows="10" runat="server" />
<asp:label ID="TxtContent2" CausesValidation="False" width="300px" HtmlEncode="False" TextMode="Multiline" rows="10" runat="server" />

<script language="JavaScript">
generate_wysiwyg('TxtContent');
</script></td>
</tr>

Confused

Do you want the lable "TxtContents2" to display the encoded contents of textbox? If so, I hope this one works for you

Sub Page_Load( s As Object, e As EventArgs )
If Page.IsPostback then
'If Page.IsValid then
ThanksPnl.visible = False
FormPnl.Visible = True

TxtContent2.Text = Server.HtmlEncode(TxtContent.Text)

'End If
End If
End Sub

<tr>
<td valign="top" width="130px">Comments/Request:</td>
<td valign="top" align="left">
<asp:textbox ID="TxtContent" CausesValidation="False" width="300px" HtmlEncode="False" TextMode="Multiline" rows="10" runat="server" />
<asp:label ID="TxtContent2" CausesValidation="False" width="300px" HtmlEncode="False" TextMode="Multiline" rows="10" runat="server" />

<script language="JavaScript">
generate_wysiwyg('TxtContent');
</script></td>
</tr>

server.htmlencode method

hi to all,

As we know that the server.htmlencode method makes html encodeing so what i understand hat if i have a text like that <b>Test string</b>

then when i apply the server.htmlencode method on that text then the output will be :

<b>Test String</b>

and the output after applying this method will be displayed on a Web browser as:

<b>Test string</b>

so my question why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

so ineed some clarification on that topic.

your help is highly appreciated

Best regards

wissam1:

why we directly send the text <b>Test string</b> to the web browser without using the server.htmlencode method to make encoding?

If you do not encode, it will behave as markup (you would see a bolden string in your sample), with all security concerns eventually involved. If instead you do encode, it will render as a plain string.

That's all i guess.

HTH. -LV


HI

HtmlEncoding is done mostly to avoid XSS (Cross Site Scripting) attacks.
Google for more on that.!

Thanks