Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Saturday, March 31, 2012

the asp.net equivalent of the "Request.Form" in asp

i am having problems with a simple web service i am creating in asp.net using C#. does anybody know what Request.Form is in asp.net.
cheers
much appreciatedI've never done classic ASP code, but I think what you're looking for is Request.Params[]

Should still be Request.Form. What is the problem that you are having?


Hi,
Request.Form method was used in classic ASP(3.0)
<form action="hello.aspx" method="post">
Your name: <input type="text" name="fname" size="20">
<input type="submit" value="Submit">
</form>
<%
dim fname
fname=Request.Form("fname")
Response.Write("Hello " & fname)
%>
As in Asp.net forms are posted to itself So Request.Form was not actively used in asp.net.
Iam still now able to understand why you require this in web services.


You can still use Request.Form, but you'll have to make sure the value exists before trying to use it. In Classic ASP, if the value didn't exist it would return an empty string, but in ASP.NET you get Nothing (in VB.NET, which I believe is null in C#).

the asp.net application doesnt compile it self under the /bin directory, where it is?

I want to use my custom control (.cs) in my web application. Custom control
is in the same assembly as my application. I want to know the name of the
assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name.
But in asp.net 2.0 i can't find the assembly. It is not compiled under the
/bin folder. Where it is, or how can i give a reference to it?re:
> I want to use my custom control (.cs) in my web application.

Custom controls aren't located in *.cs files.
Classes are included in *.cs files.

Can you clarify what you are looking for ?

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message
news:uxcKX7t6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> I want to use my custom control (.cs) in my web application. Custom control is in the
> same assembly as my application. I want to know the name of the assembly (.dll) file so
> i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name. But in asp.net 2.0 i can't find the
> assembly. It is not compiled under the /bin folder. Where it is, or how can i give a
> reference to it?
I mean, not the *.ascx (User controls), custom control.

Let me ask my question in this way: I can't add my custom control in a web
page because i don't know what to write in the <@dotnet.itags.org.Page Assembly=''> register
tag.

"Juan T. Llibre" <nomailreplies@dotnet.itags.org.nowhere.com> wrote in message
news:Oo7QLKu6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> re:
>> I want to use my custom control (.cs) in my web application.
> Custom controls aren't located in *.cs files.
> Classes are included in *.cs files.
> Can you clarify what you are looking for ?
>
> Juan T. Llibre, ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Espaol : http://asp.net.do/foros/
> ======================================
> "Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message
> news:uxcKX7t6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>>
>> I want to use my custom control (.cs) in my web application. Custom
>> control is in the same assembly as my application. I want to know the
>> name of the assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister
>> Assembly="abc.dll"> name. But in asp.net 2.0 i can't find the assembly.
>> It is not compiled under the /bin folder. Where it is, or how can i give
>> a reference to it?
OK...

For that, check out :
http://support.microsoft.com/defaul...kb;en-us;321749

The proper tag is :
<%@dotnet.itags.org. Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly= "CustomControl" %
Custom is an alias that you associate with a namespace.
CustomControlNamespace is a namespace in which classes of an assembly are enclosed.
CustomControl is the name of the assembly file without an extension (.dll).


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message news:uI%23L45u6FHA.1000@dotnet.itags.org.tk2msftngp13.phx.gbl...
>I mean, not the *.ascx (User controls), custom control.
>
> Let me ask my question in this way: I can't add my custom control in a web
> page because i don't know what to write in the <@dotnet.itags.org.Page Assembly=''> register
> tag.
>
>
> "Juan T. Llibre" <nomailreplies@dotnet.itags.org.nowhere.com> wrote in message
> news:Oo7QLKu6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>> re:
>>> I want to use my custom control (.cs) in my web application.
>>
>> Custom controls aren't located in *.cs files.
>> Classes are included in *.cs files.
>>
>> Can you clarify what you are looking for ?

>> "Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message
>> news:uxcKX7t6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>>>
>>> I want to use my custom control (.cs) in my web application. Custom
>>> control is in the same assembly as my application. I want to know the
>>> name of the assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister
>>> Assembly="abc.dll"> name. But in asp.net 2.0 i can't find the assembly.
>>> It is not compiled under the /bin folder. Where it is, or how can i give
>>> a reference to it?
On Wed, 16 Nov 2005 10:52:05 -0800, "Umut Tezduyar"
<umut@dotnet.itags.org.tezduyar.com> wrote:

>I want to use my custom control (.cs) in my web application. Custom control
>is in the same assembly as my application.

Is this 2.0? (I assume so based on your previous questions). Your
custom control must be in App_Code, correct?

Something like this:

namespace OTC
{
public class MyCustomControl : WebControl
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("This is my custom control");
base.Render(writer);
}
}
}

>I want to know the name of the
>assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name.
>But in asp.net 2.0 i can't find the assembly. It is not compiled under the
>/bin folder. Where it is, or how can i give a reference to it?

ASP.NET builds App_Code as a separate assembly, and the runtime will
recognize "App_Code" as an assembly name in a reference directive.

<%@dotnet.itags.org. Register Assembly="App_Code" TagPrefix="otc" Namespace="OTC" %
...

<otc:MyCustomControl runat="Server" id="boo" /
--
Scott
http://www.OdeToCode.com/blogs/scott/

the asp.net application doesn't compile it self under the /bin directory, where it is

I want to use my custom control (.cs) in my web application. Custom control
is in the same assembly as my application. I want to know the name of the
assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name.
But in asp.net 2.0 i can't find the assembly. It is not compiled under the
/bin folder. Where it is, or how can i give a reference to it?re:
> I want to use my custom control (.cs) in my web application.
Custom controls aren't located in *.cs files.
Classes are included in *.cs files.
Can you clarify what you are looking for ?
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message
news:uxcKX7t6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> I want to use my custom control (.cs) in my web application. Custom contro
l is in the
> same assembly as my application. I want to know the name of the assembly (
.dll) file so
> i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name. But in asp.net 2.0 i c
an't find the
> assembly. It is not compiled under the /bin folder. Where it is, or how ca
n i give a
> reference to it?
I mean, not the *.ascx (User controls), custom control.
Let me ask my question in this way: I can't add my custom control in a web
page because i don't know what to write in the <@dotnet.itags.org.Page Assembly=''> register
tag.
"Juan T. Llibre" <nomailreplies@dotnet.itags.org.nowhere.com> wrote in message
news:Oo7QLKu6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> re:
> Custom controls aren't located in *.cs files.
> Classes are included in *.cs files.
> Can you clarify what you are looking for ?
>
> Juan T. Llibre, ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Espaol : http://asp.net.do/foros/
> ======================================
> "Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message
> news:uxcKX7t6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>
OK...
For that, check out :
http://support.microsoft.com/defaul...kb;en-us;321749
The proper tag is :
<%@dotnet.itags.org. Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly=
"CustomControl" %>
Custom is an alias that you associate with a namespace.
CustomControlNamespace is a namespace in which classes of an assembly are en
closed.
CustomControl is the name of the assembly file without an extension (.dll).
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Espaol : http://asp.net.do/foros/
======================================
"Umut Tezduyar" <umut@dotnet.itags.org.tezduyar.com> wrote in message news:uI%23L45u6FHA.1000@dotnet.itags.org.tk2msftngp13.p
hx.gbl...
>I mean, not the *.ascx (User controls), custom control.
>
> Let me ask my question in this way: I can't add my custom control in a web
> page because i don't know what to write in the <@dotnet.itags.org.Page Assembly=''> registe
r
> tag.
>
>
> "Juan T. Llibre" <nomailreplies@dotnet.itags.org.nowhere.com> wrote in message
> news:Oo7QLKu6FHA.2036@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
On Wed, 16 Nov 2005 10:52:05 -0800, "Umut Tezduyar"
<umut@dotnet.itags.org.tezduyar.com> wrote:

>I want to use my custom control (.cs) in my web application. Custom control
>is in the same assembly as my application.
>
Is this 2.0? (I assume so based on your previous questions). Your
custom control must be in App_Code, correct?
Something like this:
namespace OTC
{
public class MyCustomControl : WebControl
{
protected override void Render(HtmlTextWriter writer)
{
writer.Write("This is my custom control");
base.Render(writer);
}
}
}

>I want to know the name of the
>assembly (.dll) file so i can add it's <@dotnet.itags.org.Pegister Assembly="abc.dll"> name.
>But in asp.net 2.0 i can't find the assembly. It is not compiled under the
>/bin folder. Where it is, or how can i give a reference to it?
>
ASP.NET builds App_Code as a separate assembly, and the runtime will
recognize "App_Code" as an assembly name in a reference directive.
<%@dotnet.itags.org. Register Assembly="App_Code" TagPrefix="otc" Namespace="OTC" %>
...
<otc:MyCustomControl runat="Server" id="boo" />
Scott
http://www.OdeToCode.com/blogs/scott/

The ASP.NET Web Matrix Project

ASP.NET Web Matrix is a community-supported, easy-to-use WYSIWYG application development tool for ASP.NET. It can be installed via a quick 1.2 MB download (about 5 minutes using a 56Kb modem). Best of all it's absolutely free!
http://www.asp.net/webmatrix/Normally I would say this is the not an ad forum...but...WOW! This is excellent. I recommend everyone to get this. If you dont have VS .NET, obviously that is a good reason to get it, and if you do have VS .NET, this is faster and feels cleaner.

Excellent IDE.
Originally posted by Cander
Normally I would say this is the not an ad forum...but...WOW! This is excellent. I recommend everyone to get this. If you dont have VS .NET, obviously that is a good reason to get it, and if you do have VS .NET, this is faster and feels cleaner.

Excellent IDE.

WOW is right.

This is a must have for any one doing ASPX coding without VS.Studio(lack of IntelliSense will annoy Studio users).

I downloaded it yesterday and am VERY impressed that MS could create something this clean and lite-weight(only 1.2 MB download ??!)

It even comes with it's own "lite" WEB server for those who have no use for all the bells and whistles of IIS.

And while it doesn't create CodeBehind DLLs(a plus in my book), it does generate DLLs for any Webservice you want to access.

Very cool.

John
another thing that is cool is that it only requires the 21 meg framework. So even though you couldnt run the IIS stuff with it, and they say its for 2000 and XP, it may still be installable on 98/ME so you could at least build pages on that as VS .NET doesnt isntall on 98/ME. Heck they didnt mention NT 4 in the specs and I was able to isntall it on NT and it works fine.

NOTE: There are some bugs still in it and features missing since it is just a preview, but it still works great, and beats notepad and VS .NET hands down.
Hi
I am start Dev In asp.net Is ASP.NET Web Matrix can help me
Do thing easly ? and Do I need to use COM+ as I did before ?
Thank You !

Elizabeth

elizavb@dotnet.itags.org.yahoo.com
------------------
And while it doesn't create CodeBehind DLLs(a plus in my book), it does generate DLLs for any Webservice you want to access.
------------------

How could u do that? do u need only the wsdl file?
Originally posted by tasmisr
How could u do that? do u need only the wsdl file?

Yes....Click on "Tools-WebService Proxy Generator" and put the link in to the wsdl and it creates and compiles the webservice class for you.

Very nice.

That can be done also at a command prompt but Matrix makes it easier.
so, when it produces a .dll file, this file could easly be used in other languages, like java, to call the original webservice methods and properties , am I right?
Originally posted by tasmisr
so, when it produces a .dll file, this file could easly be used in other languages, like java, to call the original webservice methods and properties , am I right?

There are a number of different languages that will work with webservices. C++, C#, VB and (Microsofts version of Java), J++ will work. I found a COBOL version that was re-designed to work with .NET that worked(looked REALLY freaky tho :) ).

But....regular Java isn't going to know squat about Webservices.

John
No the .NET dll will not work with other non .NET languages. They will have their own way of calling the web services.

the asp.net web forms designer

<rant>
Just wondering if it's just me, or is the 2003 asp.net web forms designer an
HTML-mangling, unstable, poorly written POS?
</rant>
Paulturn off the auto formatting options..
and yes, it is.
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com
"PJ6" wrote:

> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer
an
> HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul
>
>
*yawn*
Then why not go back to using whatever non-MS product you're a fanboy of?
"PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer
an
> HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul
>
I'm totally new to web development. If you have a suggestion for an
alternative I'm all ears.
Paul
"Aidy" <sorry@dotnet.itags.org.noemail.zzz> wrote in message
news:elhnlrmrFHA.1684@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> *yawn*
> Then why not go back to using whatever non-MS product you're a fanboy of?
> "PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
> news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> an
>
VS.NET is not meant for you to really design professional pages in. It's
good for quick things - but most web designers use another product.
Then, the development for the code behind the page is done in VS.NET.
Sorry, but this is not news.
"PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer
> an HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul
>

the asp.net web forms designer

<rant>
Just wondering if it's just me, or is the 2003 asp.net web forms designer an
HTML-mangling, unstable, poorly written POS?
</rant
Paulturn off the auto formatting options..
and yes, it is.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"PJ6" wrote:

> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer an
> HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul
>
*yawn*

Then why not go back to using whatever non-MS product you're a fanboy of?

"PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer
an
> HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul
I'm totally new to web development. If you have a suggestion for an
alternative I'm all ears.

Paul

"Aidy" <sorry@dotnet.itags.org.noemail.zzz> wrote in message
news:elhnlrmrFHA.1684@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> *yawn*
> Then why not go back to using whatever non-MS product you're a fanboy of?
> "PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
> news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
>> <rant>
>> Just wondering if it's just me, or is the 2003 asp.net web forms designer
> an
>> HTML-mangling, unstable, poorly written POS?
>> </rant>
>>
>> Paul
>>
>>
VS.NET is not meant for you to really design professional pages in. It's
good for quick things - but most web designers use another product.
Then, the development for the code behind the page is done in VS.NET.

Sorry, but this is not news.

"PJ6" <nobody@dotnet.itags.org.nowhere.net> wrote in message
news:OFuwrTmrFHA.3352@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> <rant>
> Just wondering if it's just me, or is the 2003 asp.net web forms designer
> an HTML-mangling, unstable, poorly written POS?
> </rant>
> Paul

The best solution of URL rewriting method

Hi,
I want rewrite url, but I don't know, whoch method is the best:
    ISAPI filters at the IIS Web server levelor HTTP modules
    or HTTP handlers
Which method is the best solution?
Thanks
You may want to read this >>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp

Looks like URL rewriting using http modules seems to be a better idea...

The Best Seed for Random Numbers

I know by default the random number generator use the time, but what is the
best seed I can used in my web application?
The Program generate 6 unique random numbers and load each of them in a
textbox control. I need a good seed like ip address or something.
'Function to generate random numbers
Public Function GetRandomNumber() As Integer
Dim objRandom As New System.Random
Return objRandom.Next(1, 26)
End Function"Leon" <vnality@dotnet.itags.org.msn.com> wrote in message
news:OxdtZQcxEHA.1404@dotnet.itags.org.TK2MSFTNGP11.phx.gbl...
> I know by default the random number generator use the time, but what is
the
> best seed I can used in my web application?
> The Program generate 6 unique random numbers and load each of them in a
> textbox control. I need a good seed like ip address or something.
> 'Function to generate random numbers
> Public Function GetRandomNumber() As Integer
> Dim objRandom As New System.Random
> Return objRandom.Next(1, 26)
> End Function
>
I don't know if this is best or not but I use (this is for a random number
in string format) Also you can change the 8 to a higher number for a larger
random number.
Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next().tostring()
Why take ticks (long) and cast as a string only to cast it back to an
Integer?
Why take only the right 8 chars and not the whole value?
Dim myRandom As New Random(CType(Now.Ticks, Integer))
dim theNumber as Integer = myRandom.Next

> I don't know if this is best or not but I use (this is for a random number
> in string format) Also you can change the 8 to a higher number for a
> larger
> random number.
> Dim strID as string = DateTime.Now.Ticks.tostring()
> Dim rdm1 as Random
> rdm1 = new Random(ctype(right(strID,8),int32))
> strUnique = rdm1.next().tostring()
>
"Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> Why take ticks (long) and cast as a string only to cast it back to an
> Integer?
> Why take only the right 8 chars and not the whole value?
> Dim myRandom As New Random(CType(Now.Ticks, Integer))
> dim theNumber as Integer = myRandom.Next
>
number
>
Well I do this because I wanted a 16 character string and later on in the
code (not included) I add the remaining characters. Also I think if you use
the whole tick it was too big for Random.
"Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> Why take ticks (long) and cast as a string only to cast it back to an
> Integer?
> Why take only the right 8 chars and not the whole value?
> Dim myRandom As New Random(CType(Now.Ticks, Integer))
> dim theNumber as Integer = myRandom.Next
>
number
>
Also, the help on Random says
However, if your application runs on a fast computer the system clock might
not have time to change between invocations of this constructor; the seed
value might be the same for different instances of Random. In that case,
apply an algorithm to differentiate the seed value in each invocation.
Well, you can take a look at the .NET RNGCryptoServiceProvider.
This example is taken right off of MSDN:
Dim random() As Byte = New Byte(100) {}
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(random) ' bytes in random are now random
Take a look at this, it may be what you were looking for
"Leon" wrote:

> I know by default the random number generator use the time, but what is th
e
> best seed I can used in my web application?
> The Program generate 6 unique random numbers and load each of them in a
> textbox control. I need a good seed like ip address or something.
> 'Function to generate random numbers
> Public Function GetRandomNumber() As Integer
> Dim objRandom As New System.Random
> Return objRandom.Next(1, 26)
> End Function
>
>
Don't using the RNGCryptoServiceProvider slow down the web application?
"Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
message news:5E010EEC-665D-4FFA-8382-76DE85DF9C36@dotnet.itags.org.microsoft.com...
> Well, you can take a look at the .NET RNGCryptoServiceProvider.
> This example is taken right off of MSDN:
> Dim random() As Byte = New Byte(100) {}
> 'RNGCryptoServiceProvider is an implementation of an RNG
> Dim rng As New RNGCryptoServiceProvider()
> rng.GetBytes(random) ' bytes in random are now random
> Take a look at this, it may be what you were looking for
>
> "Leon" wrote:
>
So there is definately a trade off then. This is the one thing I don't like
about technology...there is no perfect solution. There is a gotcha when
doing something. Well, I guess thats live in general.lol!
"Leon" wrote:

> Don't using the RNGCryptoServiceProvider slow down the web application?
> "Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
> message news:5E010EEC-665D-4FFA-8382-76DE85DF9C36@dotnet.itags.org.microsoft.com...
>
>
This code works great, but it looks wrong. What do you see?
'Function to generate random numbers
Public Function GetRandomNumber() As Integer
Dim random() As Byte = New Byte(100) {}
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider
rng.GetBytes(random) ' bytes in random are now random
Dim objRandom As New System.Random(CInt(random(100)))
Return objRandom.Next(1, 26)
End Function
"Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
message news:9CA87134-C7C6-40F7-A51F-CBD0D1C98E6E@dotnet.itags.org.microsoft.com...
> So there is definately a trade off then. This is the one thing I don't
> like
> about technology...there is no perfect solution. There is a gotcha when
> doing something. Well, I guess thats live in general.lol!
> "Leon" wrote:
>
But casting to a string and taking the last 8 chars isn't going to change
the seed value if ticks is the same for 2 calls.
Also, by casting ticks to Integer (normally long), you are shrinking it down
to an acceptable seed value.
"vMike" <MichZaelY.GeZorgeY@dotnet.itags.org.noZorY.geZwaYrrenY.com> wrote in message
news:cmoi57$8f4$1@dotnet.itags.org.ngspool-d02.news.aol.com...
> "Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
> news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> number
> Also, the help on Random says
> However, if your application runs on a fast computer the system clock
> might
> not have time to change between invocations of this constructor; the seed
> value might be the same for different instances of Random. In that case,
> apply an algorithm to differentiate the seed value in each invocation.
>
>
>

The Best Seed for Random Numbers

I know by default the random number generator use the time, but what is the
best seed I can used in my web application?

The Program generate 6 unique random numbers and load each of them in a
textbox control. I need a good seed like ip address or something.

'Function to generate random numbers

Public Function GetRandomNumber() As Integer

Dim objRandom As New System.Random

Return objRandom.Next(1, 26)

End Function"Leon" <vnality@dotnet.itags.org.msn.com> wrote in message
news:OxdtZQcxEHA.1404@dotnet.itags.org.TK2MSFTNGP11.phx.gbl...
> I know by default the random number generator use the time, but what is
the
> best seed I can used in my web application?
> The Program generate 6 unique random numbers and load each of them in a
> textbox control. I need a good seed like ip address or something.
> 'Function to generate random numbers
> Public Function GetRandomNumber() As Integer
> Dim objRandom As New System.Random
> Return objRandom.Next(1, 26)
> End Function
I don't know if this is best or not but I use (this is for a random number
in string format) Also you can change the 8 to a higher number for a larger
random number.

Dim strID as string = DateTime.Now.Ticks.tostring()
Dim rdm1 as Random
rdm1 = new Random(ctype(right(strID,8),int32))
strUnique = rdm1.next().tostring()
Why take ticks (long) and cast as a string only to cast it back to an
Integer?
Why take only the right 8 chars and not the whole value?

Dim myRandom As New Random(CType(Now.Ticks, Integer))

dim theNumber as Integer = myRandom.Next

>>
> I don't know if this is best or not but I use (this is for a random number
> in string format) Also you can change the 8 to a higher number for a
> larger
> random number.
> Dim strID as string = DateTime.Now.Ticks.tostring()
> Dim rdm1 as Random
> rdm1 = new Random(ctype(right(strID,8),int32))
> strUnique = rdm1.next().tostring()
"Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> Why take ticks (long) and cast as a string only to cast it back to an
> Integer?
> Why take only the right 8 chars and not the whole value?
> Dim myRandom As New Random(CType(Now.Ticks, Integer))
> dim theNumber as Integer = myRandom.Next
> >>
> > I don't know if this is best or not but I use (this is for a random
number
> > in string format) Also you can change the 8 to a higher number for a
> > larger
> > random number.
> > Dim strID as string = DateTime.Now.Ticks.tostring()
> > Dim rdm1 as Random
> > rdm1 = new Random(ctype(right(strID,8),int32))
> > strUnique = rdm1.next().tostring()
Well I do this because I wanted a 16 character string and later on in the
code (not included) I add the remaining characters. Also I think if you use
the whole tick it was too big for Random.
"Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> Why take ticks (long) and cast as a string only to cast it back to an
> Integer?
> Why take only the right 8 chars and not the whole value?
> Dim myRandom As New Random(CType(Now.Ticks, Integer))
> dim theNumber as Integer = myRandom.Next
> >>
> > I don't know if this is best or not but I use (this is for a random
number
> > in string format) Also you can change the 8 to a higher number for a
> > larger
> > random number.
> > Dim strID as string = DateTime.Now.Ticks.tostring()
> > Dim rdm1 as Random
> > rdm1 = new Random(ctype(right(strID,8),int32))
> > strUnique = rdm1.next().tostring()
Also, the help on Random says

However, if your application runs on a fast computer the system clock might
not have time to change between invocations of this constructor; the seed
value might be the same for different instances of Random. In that case,
apply an algorithm to differentiate the seed value in each invocation.
Well, you can take a look at the .NET RNGCryptoServiceProvider.
This example is taken right off of MSDN:

Dim random() As Byte = New Byte(100) {}

'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(random) ' bytes in random are now random

Take a look at this, it may be what you were looking for

"Leon" wrote:

> I know by default the random number generator use the time, but what is the
> best seed I can used in my web application?
> The Program generate 6 unique random numbers and load each of them in a
> textbox control. I need a good seed like ip address or something.
> 'Function to generate random numbers
> Public Function GetRandomNumber() As Integer
> Dim objRandom As New System.Random
> Return objRandom.Next(1, 26)
> End Function
>
Don't using the RNGCryptoServiceProvider slow down the web application?

"Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
message news:5E010EEC-665D-4FFA-8382-76DE85DF9C36@dotnet.itags.org.microsoft.com...
> Well, you can take a look at the .NET RNGCryptoServiceProvider.
> This example is taken right off of MSDN:
> Dim random() As Byte = New Byte(100) {}
> 'RNGCryptoServiceProvider is an implementation of an RNG
> Dim rng As New RNGCryptoServiceProvider()
> rng.GetBytes(random) ' bytes in random are now random
> Take a look at this, it may be what you were looking for
>
> "Leon" wrote:
>> I know by default the random number generator use the time, but what is
>> the
>> best seed I can used in my web application?
>>
>> The Program generate 6 unique random numbers and load each of them in a
>> textbox control. I need a good seed like ip address or something.
>>
>> 'Function to generate random numbers
>>
>> Public Function GetRandomNumber() As Integer
>>
>> Dim objRandom As New System.Random
>>
>> Return objRandom.Next(1, 26)
>>
>> End Function
>>
>>
>
So there is definately a trade off then. This is the one thing I don't like
about technology...there is no perfect solution. There is a gotcha when
doing something. Well, I guess thats live in general.lol!

"Leon" wrote:

> Don't using the RNGCryptoServiceProvider slow down the web application?
> "Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
> message news:5E010EEC-665D-4FFA-8382-76DE85DF9C36@dotnet.itags.org.microsoft.com...
> > Well, you can take a look at the .NET RNGCryptoServiceProvider.
> > This example is taken right off of MSDN:
> > Dim random() As Byte = New Byte(100) {}
> > 'RNGCryptoServiceProvider is an implementation of an RNG
> > Dim rng As New RNGCryptoServiceProvider()
> > rng.GetBytes(random) ' bytes in random are now random
> > Take a look at this, it may be what you were looking for
> > "Leon" wrote:
> >> I know by default the random number generator use the time, but what is
> >> the
> >> best seed I can used in my web application?
> >>
> >> The Program generate 6 unique random numbers and load each of them in a
> >> textbox control. I need a good seed like ip address or something.
> >>
> >> 'Function to generate random numbers
> >>
> >> Public Function GetRandomNumber() As Integer
> >>
> >> Dim objRandom As New System.Random
> >>
> >> Return objRandom.Next(1, 26)
> >>
> >> End Function
> >>
> >>
> >>
>
This code works great, but it looks wrong. What do you see?
'Function to generate random numbers

Public Function GetRandomNumber() As Integer

Dim random() As Byte = New Byte(100) {}

'RNGCryptoServiceProvider is an implementation of an RNG

Dim rng As New RNGCryptoServiceProvider

rng.GetBytes(random) ' bytes in random are now random

Dim objRandom As New System.Random(CInt(random(100)))

Return objRandom.Next(1, 26)

End Function

"Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
message news:9CA87134-C7C6-40F7-A51F-CBD0D1C98E6E@dotnet.itags.org.microsoft.com...
> So there is definately a trade off then. This is the one thing I don't
> like
> about technology...there is no perfect solution. There is a gotcha when
> doing something. Well, I guess thats live in general.lol!
> "Leon" wrote:
>> Don't using the RNGCryptoServiceProvider slow down the web application?
>>
>> "Tampa .NET Koder" <TampaNETKoder@dotnet.itags.org.discussions.microsoft.com> wrote in
>> message news:5E010EEC-665D-4FFA-8382-76DE85DF9C36@dotnet.itags.org.microsoft.com...
>> > Well, you can take a look at the .NET RNGCryptoServiceProvider.
>> > This example is taken right off of MSDN:
>>> > Dim random() As Byte = New Byte(100) {}
>>> > 'RNGCryptoServiceProvider is an implementation of an RNG
>> > Dim rng As New RNGCryptoServiceProvider()
>> > rng.GetBytes(random) ' bytes in random are now random
>>> > Take a look at this, it may be what you were looking for
>>>>> > "Leon" wrote:
>>> >> I know by default the random number generator use the time, but what
>> >> is
>> >> the
>> >> best seed I can used in my web application?
>> >>
>> >> The Program generate 6 unique random numbers and load each of them in
>> >> a
>> >> textbox control. I need a good seed like ip address or something.
>> >>
>> >> 'Function to generate random numbers
>> >>
>> >> Public Function GetRandomNumber() As Integer
>> >>
>> >> Dim objRandom As New System.Random
>> >>
>> >> Return objRandom.Next(1, 26)
>> >>
>> >> End Function
>> >>
>> >>
>> >>
>>
>>
>
But casting to a string and taking the last 8 chars isn't going to change
the seed value if ticks is the same for 2 calls.

Also, by casting ticks to Integer (normally long), you are shrinking it down
to an acceptable seed value.

"vMike" <MichZaelY.GeZorgeY@dotnet.itags.org.noZorY.geZwaYrrenY.com> wrote in message
news:cmoi57$8f4$1@dotnet.itags.org.ngspool-d02.news.aol.com...
> "Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
> news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
>> Why take ticks (long) and cast as a string only to cast it back to an
>> Integer?
>> Why take only the right 8 chars and not the whole value?
>>
>> Dim myRandom As New Random(CType(Now.Ticks, Integer))
>>
>> dim theNumber as Integer = myRandom.Next
>>
>> >>
>> > I don't know if this is best or not but I use (this is for a random
> number
>> > in string format) Also you can change the 8 to a higher number for a
>> > larger
>> > random number.
>>> > Dim strID as string = DateTime.Now.Ticks.tostring()
>> > Dim rdm1 as Random
>> > rdm1 = new Random(ctype(right(strID,8),int32))
>> > strUnique = rdm1.next().tostring()
>>>>
> Also, the help on Random says
> However, if your application runs on a fast computer the system clock
> might
> not have time to change between invocations of this constructor; the seed
> value might be the same for different instances of Random. In that case,
> apply an algorithm to differentiate the seed value in each invocation.
>
>
"Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
news:eFB4dldxEHA.1988@dotnet.itags.org.TK2MSFTNGP12.phx.gbl...
> But casting to a string and taking the last 8 chars isn't going to change
> the seed value if ticks is the same for 2 calls.
> Also, by casting ticks to Integer (normally long), you are shrinking it
down
> to an acceptable seed value.
> "vMike" <MichZaelY.GeZorgeY@dotnet.itags.org.noZorY.geZwaYrrenY.com> wrote in message
> news:cmoi57$8f4$1@dotnet.itags.org.ngspool-d02.news.aol.com...
> > "Scott M." <s-mar@dotnet.itags.org.nospam.nospam> wrote in message
> > news:%23VCC7gcxEHA.1396@dotnet.itags.org.tk2msftngp13.phx.gbl...
> >> Why take ticks (long) and cast as a string only to cast it back to an
> >> Integer?
> >> Why take only the right 8 chars and not the whole value?
> >>
> >> Dim myRandom As New Random(CType(Now.Ticks, Integer))
> >>
> >> dim theNumber as Integer = myRandom.Next
> >>
> >> >>
You are right. After I posted it I realized it didn't make sense. I did have
trouble with random when using the full tick and that is why I changed it. I
see your point.

Wednesday, March 28, 2012

The best way to construct a page

Hi,

I'm looking for the best way to construct a web page. I have to create a ResourceManager for HMC 4.0.

First I have to list all my mailstore (Name, Mailstore, Free Space), each mailstore can be edited with a button, and I have a button to each mailstore that permit to list all the organizations.

When I Edit the mailstore, I need to have the name and the Mailstore. After I submit my new info, I have to list the mailstore.

If I click on organization I need to list the organizations on the same page. Each organization can be edited or the user can be listed like the organization.

The users can be edited too.

I think that I can do It with an DataGrid and an arrayList(the date isn't in a DB), I can list my mailstore but after that I can't do nothing. I can't get the mailstore name of the line of the button, I can't list the organizations.

I looked on google since 2days and I don't find anything that can help me to do that.

Thank you for your help

Eventhough you can use one grid to view/edit different datasources, it would be difficult if you want customization(appearance, validation etc). What I would suggest is having 3 grids (each one for mailstore, organization and user). Depending upon the user's choice you show the relevant grid and hide all the others.

snakpak:

I can't get the mailstore name of the line of the button, I can't list the organizations.

I couldn't understand the question. Please provide more info.


Where are you storing the data if not in a DB? I prefer to use Datalists to list anything. I make the name / description a link to view the details and include a LinkButton / HyperLink to Edit... Is this what you're looking for?


I used 3 datagrid, it works now! thanks your help

The Command event of dynamically loaded controls

Hi,

I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image button at runtime:

//-- Code snippet
protected System.Web.UI.WebControls.PlaceHolder ImageHolder;

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
LoadDynamicImageButton();
}

private void ImageButton_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Write("Image button clicked");
}

private void LoadDynamicImageButton()
{
ImageButton btn = new ImageButton();
btn.ImageUrl = "Images/Minus.png";
btn.Click += new ImageClickEventHandler(ImageButton_Click);
ImageHolder.Controls.Add(btn);
}
//-- End code snippet

The first time the page loads, the image button is created. When I click it,
it reloads the page but doesn't trigger its ImageClickEventHandler. If I
forcefully run LoadDynamicImageButton(), i.e., remove the IsPostBack check
in Page_Load() to recreate the image, its ImageClickEventHandler is
triggered. This happens with the Command event as well.

It seems that on post-back, if a dynamically loaded control is not loaded,
then its event handler is not wired. Its properties such as CommandName and
CommandArgument, OTOH, persists from the last load.

The problem is that if I dynamically load up the PlaceHolder control with
different controls according to the button clicked, this behavior forces all
those controls to be loaded twice - first to load all default controls just
to wire up their event handlers, then to reload them again according to the
event. There are also other factors, such as the assigning a differnet
ImageUrl, that seem to affect whether or not the event handler is triggered.
I'm still working on it to hopefully isolate the problem.

Is there a workaround?

Thanks,
Donald XieHi Donald,

Thanks for posting in the community!
From your description, you dynamically add some command controls such as
button or ImageButton into a webform within a placeholder.(in the page_load
event when the page is first loaded). Also, you registered a "Click" event
handler for the dynamicly added control. However, you found that when you
clicked the control , its event handler hadn't been called and if you did
the adding and registering event handler operation every time the page is
loaded in Page_load, it worked well, yes?

I've tested the code you provided and also tried using other controls such
as Button and did encoutnered the same problem. Currently, I am finding
proper resource to assist you and we will update as soon as posible. In the
meantime, if you have any new findings, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)
Hi Donald,

This is normal behavior and results from the way ASP.NET remembers the old
value for that text box in order to determine if the new value is different.

Each time the form is sent to the browser, ASP.NET stores the current text
box value (and other controls) in a hidden field which it sends to the
browser. When the browser posts the page back, the hidden field is sent to
the server along with the rest of the form. ASP.NET parses the list of old
values from the hidden field and attempts to associate each value with a
control. Then it compares the new value of the control with the old value
and triggers events.

The text box must be recreated to allow ASP.NET to associate it with the
old value from the hidden field. Only then can ASP.NET compare the new and
old values.

Here is a code sample which demonstrates one text box that correctly
triggers the changed event and three text boxes which fail for each of
three reasons.

**** HTML
<form id="Form1" method="post" runat="server">
<P>This sample contains a series of text boxes added to the page<BR>
programmatically with Controls.Add. The variations in these<BR>
text boxes demonstrate how to (and how not to) add a control<BR>
so that it can fire an event.<BR>
<BR>
</P>
<asp:panel id="Panel1" runat="server">
<P>
<asp:Label id="Label5" runat="server" Width="115px"> With
ViewState:</asp:Label>
<asp:PlaceHolder id="PlaceHolder1"
runat="server"></asp:PlaceHolder>
<asp:Label id="Label1" runat="server" Width="368px"
EnableViewState="False"></asp:Label></P>
<P>
<asp:Label id="Label6" runat="server" Width="115px" Height="19"> No
ViewState:</asp:Label>
<asp:PlaceHolder id="PlaceHolder2"
runat="server"></asp:PlaceHolder>
<asp:Label id="Label2" runat="server" Width="368px"
EnableViewState="False"></asp:Label></P>
<P>
<asp:Label id="Label7" runat="server" Width="115px"
Height="19px">Controls.AddAt:</asp:Label>
<asp:Label id="Label3" runat="server" Width="368px"
EnableViewState="False"></asp:Label></P>
<P>
<asp:Label id="Label8" runat="server" Width="115px"
Height="19px">!IsPostBack:</asp:Label>
<asp:PlaceHolder id="PlaceHolder4"
runat="server"></asp:PlaceHolder>
<asp:Label id="Label4" runat="server" Width="368px"
EnableViewState="False"></asp:Label></P>
</asp:panel>
<P><asp:button id="Button1" runat="server" Text="Submit" Width="100px"
Height="27px"></asp:button></P>
<P><hr></P>
<P>As you can see through experimenting with the above, the text<BR>
box labeled "With ViewState" is the only one that works properly.<BR>
<BR>
The "No ViewState" and the "Controls.AddAt" text boxes both<BR>
fire their changed events whenever they contain text, even if that<BR>
text has not changed.<BR>
<BR>
The "!IsPostBack" text box simply disappears upon postback.</P>
</form
**** CODE
private void Page_Load(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.TextBox MyTextBox;

MyTextBox = new TextBox();
MyTextBox.ID = "TextBox1";
MyTextBox.EnableViewState=true;
PlaceHolder1.Controls.Add(MyTextBox);
MyTextBox.TextChanged += new
System.EventHandler(this.TextBox_TextChanged);

MyTextBox = new TextBox();
MyTextBox.ID = "TextBox2";
MyTextBox.EnableViewState=false;
PlaceHolder2.Controls.Add(MyTextBox);
MyTextBox.TextChanged += new
System.EventHandler(this.TextBox_TextChanged);

MyTextBox = new TextBox();
MyTextBox.ID = "TextBox3";
MyTextBox.EnableViewState=true;
Panel1.Controls.AddAt(15,MyTextBox);
MyTextBox.TextChanged += new
System.EventHandler(this.TextBox_TextChanged);

if(!IsPostBack)
{
MyTextBox = new TextBox();
MyTextBox.ID = "TextBox4";
MyTextBox.EnableViewState=true;
PlaceHolder4.Controls.Add(MyTextBox);
MyTextBox.TextChanged += new
System.EventHandler(this.TextBox_TextChanged);
}
}

private void TextBox_TextChanged(object sender, System.EventArgs e)
{
TextBox txtBoxSender = (TextBox)sender;
string strTextBoxID = txtBoxSender.ID;

switch(strTextBoxID)
{
case "TextBox1":
Label1.Text = "Changed";
break;
case "TextBox2":
Label2.Text = "Changed";
break;
case "TextBox3":
Label3.Text = "Changed";
break;
case "TextBox4":
Label4.Text = "Changed";
break;
}
}

--
Please see these articles for more information.

Adding Controls to a Web Forms Page Programmatically
http://msdn.microsoft.com/library/e...gcontrolstowebf
ormspageprogrammatically.asp

HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/defaul...kb;EN-US;317794

Does this answer your question?

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computers security.

This posting is provided "AS IS", with no warranties, and confers no rights.

-------
> From: "Donald Xie" <donald_xie@dotnet.itags.org.msdn.nospam>
> Subject: The Command event of dynamically loaded controls
> Date: Fri, 30 Jan 2004 16:52:00 +0800
> Lines: 54
> X-Priority: 3
> X-MSMail-Priority: Normal
> X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> Message-ID: <#C2U35w5DHA.2580@dotnet.itags.org.TK2MSFTNGP11.phx.gbl>
> Newsgroups: microsoft.public.dotnet.framework.aspnet
> NNTP-Posting-Host: 202.181.80.84
> Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
.phx.gbl!TK2MSFTNGP11.phx.gbl
> Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:206364
> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
> Hi,
> I noticed an interesting effect when working with controls that are
> dynamically loaded. For instance, on a web form with a PlaceHolder control
> named ImageHolder, I dynamically add an image button at runtime:
> //-- Code snippet
> protected System.Web.UI.WebControls.PlaceHolder ImageHolder;
> private void Page_Load(object sender, System.EventArgs e)
> {
> if (!IsPostBack)
> LoadDynamicImageButton();
> }
> private void ImageButton_Click(object sender,
> System.Web.UI.ImageClickEventArgs e)
> {
> Response.Write("Image button clicked");
> }
> private void LoadDynamicImageButton()
> {
> ImageButton btn = new ImageButton();
> btn.ImageUrl = "Images/Minus.png";
> btn.Click += new ImageClickEventHandler(ImageButton_Click);
> ImageHolder.Controls.Add(btn);
> }
> //-- End code snippet
> The first time the page loads, the image button is created. When I click
it,
> it reloads the page but doesn't trigger its ImageClickEventHandler. If I
> forcefully run LoadDynamicImageButton(), i.e., remove the IsPostBack check
> in Page_Load() to recreate the image, its ImageClickEventHandler is
> triggered. This happens with the Command event as well.
> It seems that on post-back, if a dynamically loaded control is not loaded,
> then its event handler is not wired. Its properties such as CommandName
and
> CommandArgument, OTOH, persists from the last load.
> The problem is that if I dynamically load up the PlaceHolder control with
> different controls according to the button clicked, this behavior forces
all
> those controls to be loaded twice - first to load all default controls
just
> to wire up their event handlers, then to reload them again according to
the
> event. There are also other factors, such as the assigning a differnet
> ImageUrl, that seem to affect whether or not the event handler is
triggered.
> I'm still working on it to hopefully isolate the problem.
> Is there a workaround?
> Thanks,
> Donald Xie
Thanks for the excellent explanation, Mike. Yes that answers my question.

Now I'm trying to find a good solution for my problem. In a nutshell, I need
to load a hierarchical list of folders and files from a database and display
them on a tree - very much the same as the MSDN Library deeptree.asp. The
number of nodes is potentially large, so I'll only load all top level
folders plus folders in the branch selected by the user. Only one branch can
be expanded each time. My users can click a folder node to expand or
collapse it, based on the selected folder's state.

Since my client doesn't want to use a third party tree control, my first
thought i\was to programmatically create a list of ImageButton/LinkButton
pairs to display the folders. This dynamic control's behavior means that:

1. I'll need to load the folder list in the first pass to wire up the
controls and corresponding event handlers. After it's loaded, the event
handler will fire and give me the selected folder. Then,

2. I'll then load the folder list again with the selected folder
expanded/collapsed.

It doesn't seem like a very efficient solution now because it requires two
trips to the database to load the folder list. Caching doesn't sound very
attractive either because list can be quite big and changes frequently.

Any suggestions are very much appreciated.

Cheers,
Donald Xie

""Mike Moore [MSFT]"" <michmo@dotnet.itags.org.online.microsoft.com> wrote in message
news:AXcHok55DHA.3032@dotnet.itags.org.cpmsftngxa07.phx.gbl...
> Hi Donald,
> This is normal behavior and results from the way ASP.NET remembers the old
> value for that text box in order to determine if the new value is
different.
> Each time the form is sent to the browser, ASP.NET stores the current text
> box value (and other controls) in a hidden field which it sends to the
> browser. When the browser posts the page back, the hidden field is sent to
> the server along with the rest of the form. ASP.NET parses the list of old
> values from the hidden field and attempts to associate each value with a
> control. Then it compares the new value of the control with the old value
> and triggers events.
> The text box must be recreated to allow ASP.NET to associate it with the
> old value from the hidden field. Only then can ASP.NET compare the new and
> old values.
> Here is a code sample which demonstrates one text box that correctly
> triggers the changed event and three text boxes which fail for each of
> three reasons.
>
> **** HTML
> <form id="Form1" method="post" runat="server">
> <P>This sample contains a series of text boxes added to the page<BR>
> programmatically with Controls.Add. The variations in these<BR>
> text boxes demonstrate how to (and how not to) add a control<BR>
> so that it can fire an event.<BR>
> <BR>
> </P>
> <asp:panel id="Panel1" runat="server">
> <P>
> <asp:Label id="Label5" runat="server" Width="115px"> With
> ViewState:</asp:Label>
> <asp:PlaceHolder id="PlaceHolder1"
> runat="server"></asp:PlaceHolder>
> <asp:Label id="Label1" runat="server" Width="368px"
> EnableViewState="False"></asp:Label></P>
> <P>
> <asp:Label id="Label6" runat="server" Width="115px" Height="19"> No
> ViewState:</asp:Label>
> <asp:PlaceHolder id="PlaceHolder2"
> runat="server"></asp:PlaceHolder>
> <asp:Label id="Label2" runat="server" Width="368px"
> EnableViewState="False"></asp:Label></P>
> <P>
> <asp:Label id="Label7" runat="server" Width="115px"
> Height="19px">Controls.AddAt:</asp:Label>
> <asp:Label id="Label3" runat="server" Width="368px"
> EnableViewState="False"></asp:Label></P>
> <P>
> <asp:Label id="Label8" runat="server" Width="115px"
> Height="19px">!IsPostBack:</asp:Label>
> <asp:PlaceHolder id="PlaceHolder4"
> runat="server"></asp:PlaceHolder>
> <asp:Label id="Label4" runat="server" Width="368px"
> EnableViewState="False"></asp:Label></P>
> </asp:panel>
> <P><asp:button id="Button1" runat="server" Text="Submit" Width="100px"
> Height="27px"></asp:button></P>
> <P><hr></P>
> <P>As you can see through experimenting with the above, the text<BR>
> box labeled "With ViewState" is the only one that works
properly.<BR>
> <BR>
> The "No ViewState" and the "Controls.AddAt" text boxes both<BR>
> fire their changed events whenever they contain text, even if
that<BR>
> text has not changed.<BR>
> <BR>
> The "!IsPostBack" text box simply disappears upon postback.</P>
> </form>
>
> **** CODE
> private void Page_Load(object sender, System.EventArgs e)
> {
> System.Web.UI.WebControls.TextBox MyTextBox;
> MyTextBox = new TextBox();
> MyTextBox.ID = "TextBox1";
> MyTextBox.EnableViewState=true;
> PlaceHolder1.Controls.Add(MyTextBox);
> MyTextBox.TextChanged += new
> System.EventHandler(this.TextBox_TextChanged);
> MyTextBox = new TextBox();
> MyTextBox.ID = "TextBox2";
> MyTextBox.EnableViewState=false;
> PlaceHolder2.Controls.Add(MyTextBox);
> MyTextBox.TextChanged += new
> System.EventHandler(this.TextBox_TextChanged);
> MyTextBox = new TextBox();
> MyTextBox.ID = "TextBox3";
> MyTextBox.EnableViewState=true;
> Panel1.Controls.AddAt(15,MyTextBox);
> MyTextBox.TextChanged += new
> System.EventHandler(this.TextBox_TextChanged);
> if(!IsPostBack)
> {
> MyTextBox = new TextBox();
> MyTextBox.ID = "TextBox4";
> MyTextBox.EnableViewState=true;
> PlaceHolder4.Controls.Add(MyTextBox);
> MyTextBox.TextChanged += new
> System.EventHandler(this.TextBox_TextChanged);
> }
> }
> private void TextBox_TextChanged(object sender, System.EventArgs e)
> {
> TextBox txtBoxSender = (TextBox)sender;
> string strTextBoxID = txtBoxSender.ID;
> switch(strTextBoxID)
> {
> case "TextBox1":
> Label1.Text = "Changed";
> break;
> case "TextBox2":
> Label2.Text = "Changed";
> break;
> case "TextBox3":
> Label3.Text = "Changed";
> break;
> case "TextBox4":
> Label4.Text = "Changed";
> break;
> }
> }
>
> --
> Please see these articles for more information.
> Adding Controls to a Web Forms Page Programmatically
http://msdn.microsoft.com/library/e...gcontrolstowebf
> ormspageprogrammatically.asp
> HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
> http://support.microsoft.com/defaul...kb;EN-US;317794
> Does this answer your question?
> Thank you, Mike
> Microsoft, ASP.NET Support Professional
> Microsoft highly recommends to all of our customers that they visit the
> http://www.microsoft.com/protect site and perform the three
straightforward
> steps listed to improve your computers security.
> This posting is provided "AS IS", with no warranties, and confers no
rights.
>
> -------
> > From: "Donald Xie" <donald_xie@dotnet.itags.org.msdn.nospam>
> > Subject: The Command event of dynamically loaded controls
> > Date: Fri, 30 Jan 2004 16:52:00 +0800
> > Lines: 54
> > X-Priority: 3
> > X-MSMail-Priority: Normal
> > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
> > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
> > Message-ID: <#C2U35w5DHA.2580@dotnet.itags.org.TK2MSFTNGP11.phx.gbl>
> > Newsgroups: microsoft.public.dotnet.framework.aspnet
> > NNTP-Posting-Host: 202.181.80.84
> > Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTN GXA05.phx.gbl!TK2MSFTNGP08
> phx.gbl!TK2MSFTNGP11.phx.gbl
> > Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.aspnet:206364
> > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
> > Hi,
> > I noticed an interesting effect when working with controls that are
> > dynamically loaded. For instance, on a web form with a PlaceHolder
control
> > named ImageHolder, I dynamically add an image button at runtime:
> > //-- Code snippet
> > protected System.Web.UI.WebControls.PlaceHolder ImageHolder;
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > if (!IsPostBack)
> > LoadDynamicImageButton();
> > }
> > private void ImageButton_Click(object sender,
> > System.Web.UI.ImageClickEventArgs e)
> > {
> > Response.Write("Image button clicked");
> > }
> > private void LoadDynamicImageButton()
> > {
> > ImageButton btn = new ImageButton();
> > btn.ImageUrl = "Images/Minus.png";
> > btn.Click += new ImageClickEventHandler(ImageButton_Click);
> > ImageHolder.Controls.Add(btn);
> > }
> > //-- End code snippet
> > The first time the page loads, the image button is created. When I click
> it,
> > it reloads the page but doesn't trigger its ImageClickEventHandler. If I
> > forcefully run LoadDynamicImageButton(), i.e., remove the IsPostBack
check
> > in Page_Load() to recreate the image, its ImageClickEventHandler is
> > triggered. This happens with the Command event as well.
> > It seems that on post-back, if a dynamically loaded control is not
loaded,
> > then its event handler is not wired. Its properties such as CommandName
> and
> > CommandArgument, OTOH, persists from the last load.
> > The problem is that if I dynamically load up the PlaceHolder control
with
> > different controls according to the button clicked, this behavior forces
> all
> > those controls to be loaded twice - first to load all default controls
> just
> > to wire up their event handlers, then to reload them again according to
> the
> > event. There are also other factors, such as the assigning a differnet
> > ImageUrl, that seem to affect whether or not the event handler is
> triggered.
> > I'm still working on it to hopefully isolate the problem.
> > Is there a workaround?
> > Thanks,
> > Donald Xie
Hi Donald,

Thank you for the response. Regarding on the issue, we are
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)
Hi Donald,

As for the situation you mentioned in the last reply, here is my
suggestions on it:
1. If we manually build a "tree" programatically via a list of ImageButtons
or LinkButtons, I'm afraid there will cause some performance issues since
every time page loaded , it need to create and add these dynamic controls
so as to associate their states from viewstate, also register the event
handler for them. This will be a large challenge to the serverside.

2. Would you like to have a try on the TreeView control in the Microsoft
Internet Explorer WebControls? This treeview control has been added to the
MS's web control collections and have detailed reference and tutorial in
MSDN. Also, the IE webcontrols' source code is opened to public , you're
feel to extend their existed functions. Here is some tech references and
articls on the TreeView web control:

#TreeView WebControl Reference
http://msdn.microsoft.com/library/e...ingtreeviewiewe
bcontrol.asp?frame=true

And here is a test page I used to test dynamically add nodes when a certain
node is expanded. The treeview has
4 hierarchies and each contains 20 nodes. When a node is first time
expanded or selected, it dynamically add its child nodes. Please have a
look to see whether it possible for you to use this TreeView control.

In addition, if you have the "Application Center Test" installed, you may
try having a test on different approachs such as using TreeView or manually
add button lists so as to see the realtime performance. And here are
another two tech articles, one is about the MSDN site's TreeView 's
implementation in C#. I think they may be helpful to you,too.

#Hierarchical Data Binding in ASP.NET
http://msdn.microsoft.com/library/e...databinding.asp
?frame=true

#The MSDN Table of Contents in C#
http://msdn.microsoft.com/library/e...001.asp?frame=t
rue

Please check out the above suggestions. If you have any questions or if my
suggestions not quite suitable for your situation, please feel free to post
here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Hi Donald,

Sorry for forgetting attach My test page's code in the last reply, here is
the Page code:
#If you haven't the IE web control's reference or code, you may get them at
http://www.asp.net/ControlGallery/C...l=75&tabindex=2

----------aspx page-----------
<%@dotnet.itags.org. Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls"
Assembly="Microsoft.Web.UI.WebControls" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DynaTree</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><FONT face="">
<iewc:TreeView id="trvMain"
runat="server"></iewc:TreeView></FONT></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
</body>
</HTML
--------code behind class-----
public class DynaTree : System.Web.UI.Page
{
protected Microsoft.Web.UI.WebControls.TreeView trvMain;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
LoadData();
BindTreeNodes(trvMain.Nodes,GetChildNodes("0"));
trvMain.AutoPostBack = true;
}
}

protected void LoadData()
{
DataTable tb = new DataTable();
tb.Columns.Add("nid");
tb.Columns.Add("pid");
tb.Columns.Add("name");
tb.Columns.Add("url");
tb.Columns.Add("target");

int i=0;
int j=0;
int k=0;
int l=0;
int nodeindex = 1;

for(i=1;i<=20;i++)
{
DataRow row1 = tb.NewRow();
row1["nid"] = i.ToString();
row1["pid"] = "0";
row1["name"] = "FirstLevelNode_"+nodeindex.ToString();
row1["url"] = "";
row1["target"] = "";
tb.Rows.Add(row1);

for(j=1;j<=20;j++)
{

DataRow row2 = tb.NewRow();
row2["nid"] = i.ToString() + j.ToString();
row2["pid"] = i.ToString();
row2["name"] = "SecondLevelNode_"+j.ToString();
row2["url"] = "";
row2["target"] = "";
tb.Rows.Add(row2);

for(k=1;k<=20;k++)
{

DataRow row3 = tb.NewRow();
row3["nid"] = i.ToString() + j.ToString() + k.ToString();
row3["pid"] = i.ToString() + j.ToString();
row3["name"] = "ThirdLevelNode_"+k.ToString();
row3["url"] = "";
row3["target"] = "";
tb.Rows.Add(row3);

for(l=1;l<20;l++)
{
DataRow row4 = tb.NewRow();
row4["nid"] = i.ToString() + j.ToString() + k.ToString() +
l.ToString();
row4["pid"] = i.ToString() + j.ToString() + k.ToString();
row4["name"] = "ForthLevelNode_"+k.ToString();
row4["url"] = "";
row4["target"] = "";
tb.Rows.Add(row4);
}

}
}
}

Session["TEMP_DATA"] = tb;

}

protected DataRow[] GetChildNodes(string pid)
{
DataTable tb = (DataTable)Session["TEMP_DATA"];
DataRow[] rows = tb.Select("pid = '" + pid +"'");

return rows;
}

protected void BindTreeNodes(TreeNodeCollection nodes, DataRow[] rows)
{

for(int i=0;i<rows.Length;i++)
{
TreeNode node = new TreeNode();
node.ID = rows[i]["nid"].ToString();
node.Text = rows[i]["name"].ToString();
node.NavigateUrl = rows[i]["url"].ToString();
node.Target = rows[i]["target"].ToString();

TreeNode emptynode = new TreeNode();
emptynode.ID = node.ID + "#$#EMPTY";

node.Nodes.Add(emptynode);
nodes.Add(node);
}

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{

InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.trvMain.Expand += new
Microsoft.Web.UI.WebControls.ClickEventHandler(thi s.trvMain_Expand);
this.trvMain.SelectedIndexChange += new
Microsoft.Web.UI.WebControls.SelectEventHandler(th is.trvMain_SelectedIndexCh
ange);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void trvMain_Expand(object sender,
Microsoft.Web.UI.WebControls.TreeViewClickEventArg s e)
{
TreeNode pnode = ((TreeView)sender).GetNodeFromIndex(e.Node);
TreeNode emptynode = pnode.Nodes[0];

if(emptynode.ID.IndexOf("#$#EMPTY") != -1)
{
pnode.Nodes.Clear();
BindTreeNodes(pnode.Nodes,GetChildNodes(pnode.ID)) ;
}

}

private void trvMain_SelectedIndexChange(object sender,
Microsoft.Web.UI.WebControls.TreeViewSelectEventAr gs e)
{
TreeNode oldnode = ((TreeView)sender).GetNodeFromIndex(e.OldNode);
TreeNode newnode = ((TreeView)sender).GetNodeFromIndex(e.NewNode);

if(newnode.Nodes.Count>0)
{
TreeNode emptynode = newnode.Nodes[0];

if(emptynode.ID.IndexOf("#$#EMPTY") != -1)
{
newnode.Nodes.Clear();
BindTreeNodes(newnode.Nodes,GetChildNodes(newnode. ID));
}
}

}

}
Hi Steven,

Thanks so much for your suggestions and the sample code - they are exactly
the information I need.

The TreeView control is the more conventional, and the MSDN TOC in C# is
very elegant and certainly well proven. I will go through both to see which
is the best for this application.

The hierarchical data binding approach is in essense what I'm doing
manually, as the depth of each node is variable. However I suspect that it
also suffers the same render-twice problem if we want to do more than just
displaying the nodes and get their state on post back.

Best,
Donald Xie

"Steven Cheng[MSFT]" <v-schang@dotnet.itags.org.online.microsoft.com> wrote in message
news:8JbKxSx6DHA.3524@dotnet.itags.org.cpmsftngxa07.phx.gbl...
> Hi Donald,
>
> As for the situation you mentioned in the last reply, here is my
> suggestions on it:
> 1. If we manually build a "tree" programatically via a list of
ImageButtons
> or LinkButtons, I'm afraid there will cause some performance issues since
> every time page loaded , it need to create and add these dynamic controls
> so as to associate their states from viewstate, also register the event
> handler for them. This will be a large challenge to the serverside.
> 2. Would you like to have a try on the TreeView control in the Microsoft
> Internet Explorer WebControls? This treeview control has been added to the
> MS's web control collections and have detailed reference and tutorial in
> MSDN. Also, the IE webcontrols' source code is opened to public , you're
> feel to extend their existed functions. Here is some tech references and
> articls on the TreeView web control:
> #TreeView WebControl Reference
http://msdn.microsoft.com/library/e...ingtreeviewiewe
> bcontrol.asp?frame=true
> And here is a test page I used to test dynamically add nodes when a
certain
> node is expanded. The treeview has
> 4 hierarchies and each contains 20 nodes. When a node is first time
> expanded or selected, it dynamically add its child nodes. Please have a
> look to see whether it possible for you to use this TreeView control.
> In addition, if you have the "Application Center Test" installed, you may
> try having a test on different approachs such as using TreeView or
manually
> add button lists so as to see the realtime performance. And here are
> another two tech articles, one is about the MSDN site's TreeView 's
> implementation in C#. I think they may be helpful to you,too.
> #Hierarchical Data Binding in ASP.NET
http://msdn.microsoft.com/library/e...databinding.asp
> ?frame=true
> #The MSDN Table of Contents in C#
http://msdn.microsoft.com/library/e...001.asp?frame=t
> rue
>
> Please check out the above suggestions. If you have any questions or if my
> suggestions not quite suitable for your situation, please feel free to
post
> here.
>
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
Hi Donald,

Thanks for your response. I'm glad that my suggestions are helpful to you.
As for the things I mentioned in the last reply, here some of my further
suggestions:
As for the "MSDN TOC in C#", since it is not provided as a Web Server
Control and the DataSource is based on serveral xml files. If you'd like to
use this means, I think you may try dynamically generic the certain XML
files from your own datasource. That'll save your times.

Anyway, which approach to choose all depends on the real time performance.
Hope you'll soon figure out the most appropriate means.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Monday, March 26, 2012

The connection was closed.

Hi, I have a web page that call another one with this code:

WebClient SendSite = new WebClient();
SendSite.Headers.Add("Content-Type", "application/x-www-form-
urlencoded");
string StrReqSend = "Par1=aaa&Par2=2222";
byte[] Param = System.Text.Encoding.ASCII.GetBytes(StrReqSend);
byte[] Rps = SendSite.UploadData("http://localhost/nomeprogetto/
prova.aspx", "POST", Param);

The web page called read the parameters, run the code and return 1 or
0.

The code that prepare the answer is the follow:

private void WriteResult(string StrResult)
{
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(StrResult);
Response.Flush();
Response.Close();
}

When I run the code happen an error:

Unable to read data from the transport connection: The connection was
closed.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.IO.IOException: Unable to read data from the
transport connection: The connection was closed.

How can I solve the problem?

Thanks in advice.Try commenting out Response.Close(); and see what happens.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)

************************************************
Think outside the box!
************************************************
<support@dotnet.itags.org.missmobile.netwrote in message
news:1180699146.296715.194340@dotnet.itags.org.o5g2000hsb.googlegro ups.com...

Quote:

Originally Posted by

Hi, I have a web page that call another one with this code:
>
WebClient SendSite = new WebClient();
SendSite.Headers.Add("Content-Type", "application/x-www-form-
urlencoded");
string StrReqSend = "Par1=aaa&Par2=2222";
byte[] Param = System.Text.Encoding.ASCII.GetBytes(StrReqSend);
byte[] Rps = SendSite.UploadData("http://localhost/nomeprogetto/
prova.aspx", "POST", Param);
>
The web page called read the parameters, run the code and return 1 or
0.
>
The code that prepare the answer is the follow:
>
private void WriteResult(string StrResult)
{
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(StrResult);
Response.Flush();
Response.Close();
}
>
When I run the code happen an error:
>
Unable to read data from the transport connection: The connection was
closed.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
>
Exception Details: System.IO.IOException: Unable to read data from the
transport connection: The connection was closed.
>
>
How can I solve the problem?
>
Thanks in advice.
>


On 2 Giu, 00:56, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@dotnet.itags.org.comcast.netNoSpamMwrote:

Quote:

Originally Posted by

Try commenting out Response.Close(); and see what happens.
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBAhttp://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
>
************************************************
Think outside the box!
************************************************<supp...@dotnet.itags.org.missmobile.netwrote in message
>
news:1180699146.296715.194340@dotnet.itags.org.o5g2000hsb.googlegro ups.com...
>
>
>

Quote:

Originally Posted by

Hi, I have a web page that call another one with this code:


>

Quote:

Originally Posted by

WebClient SendSite = new WebClient();
SendSite.Headers.Add("Content-Type", "application/x-www-form-
urlencoded");
string StrReqSend = "Par1=aaa&Par2=2222";
byte[] Param = System.Text.Encoding.ASCII.GetBytes(StrReqSend);
byte[] Rps = SendSite.UploadData("http://localhost/nomeprogetto/
prova.aspx", "POST", Param);


>

Quote:

Originally Posted by

The web page called read the parameters, run the code and return 1 or
0.


>

Quote:

Originally Posted by

The code that prepare the answer is the follow:


>

Quote:

Originally Posted by

private void WriteResult(string StrResult)
{
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(StrResult);
Response.Flush();
Response.Close();
}


>

Quote:

Originally Posted by

When I run the code happen an error:


>

Quote:

Originally Posted by

Unable to read data from the transport connection: The connection was
closed.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.


>

Quote:

Originally Posted by

Exception Details: System.IO.IOException: Unable to read data from the
transport connection: The connection was closed.


>

Quote:

Originally Posted by

How can I solve the problem?


>

Quote:

Originally Posted by

Thanks in advice.- Nascondi testo tra virgolette -


>
- Mostra testo tra virgolette -


Hi, if I comment Response.Close(); works fine but i receive too HTML
code.

The page must contain only the value of "StrResult" because the same
page are request by a lot of VB6 application.

I can't upgrade all VB6 application...

Thanks in advice

Matteo

The connection was closed.

Hi, I have a web page that call another one with this code:
WebClient SendSite = new WebClient();
SendSite.Headers.Add("Content-Type", "application/x-www-form-
urlencoded");
string StrReqSend = "Par1=aaa&Par2=2222";
byte[] Param = System.Text.Encoding.ASCII.GetBytes(StrReqSend);
byte[] Rps = SendSite.UploadData("http://localhost/nomeprogetto/
prova.aspx", "POST", Param);
The web page called read the parameters, run the code and return 1 or
0.
The code that prepare the answer is the follow:
private void WriteResult(string StrResult)
{
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "text/plain";
Response.ContentEncoding = System.Text.Encoding.Default;
Response.Write(StrResult);
Response.Flush();
Response.Close();
}
When I run the code happen an error:
Unable to read data from the transport connection: The connection was
closed.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.IO.IOException: Unable to read data from the
transport connection: The connection was closed.
How can I solve the problem?
Thanks in advice.Try commenting out Response.Close(); and see what happens.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
Co-author: Microsoft Expression Web Bible (upcoming)
****************************************
********
Think outside the box!
****************************************
********
<support@dotnet.itags.org.missmobile.net> wrote in message
news:1180699146.296715.194340@dotnet.itags.org.o5g2000hsb.googlegroups.com...
> Hi, I have a web page that call another one with this code:
> WebClient SendSite = new WebClient();
> SendSite.Headers.Add("Content-Type", "application/x-www-form-
> urlencoded");
> string StrReqSend = "Par1=aaa&Par2=2222";
> byte[] Param = System.Text.Encoding.ASCII.GetBytes(StrReqSend);
> byte[] Rps = SendSite.UploadData("http://localhost/nomeprogetto/
> prova.aspx", "POST", Param);
> The web page called read the parameters, run the code and return 1 or
> 0.
> The code that prepare the answer is the follow:
> private void WriteResult(string StrResult)
> {
> Response.ClearHeaders();
> Response.ClearContent();
> Response.ContentType = "text/plain";
> Response.ContentEncoding = System.Text.Encoding.Default;
> Response.Write(StrResult);
> Response.Flush();
> Response.Close();
> }
> When I run the code happen an error:
> Unable to read data from the transport connection: The connection was
> closed.
> Description: An unhandled exception occurred during the execution of
> the current web request. Please review the stack trace for more
> information about the error and where it originated in the code.
> Exception Details: System.IO.IOException: Unable to read data from the
> transport connection: The connection was closed.
>
> How can I solve the problem?
> Thanks in advice.
>
On 2 Giu, 00:56, "Cowboy \(Gregory A. Beamer\)"
<NoSpamMgbwo...@dotnet.itags.org.comcast.netNoSpamM> wrote:
> Try commenting out Response.Close(); and see what happens.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBAhttp://gregorybeamer.spaces.live.com
> Co-author: Microsoft Expression Web Bible (upcoming)
> ****************************************
********
> Think outside the box!
> ****************************************
********<supp...@dotnet.itags.org.missmobile.net> w
rote in message
> news:1180699146.296715.194340@dotnet.itags.org.o5g2000hsb.googlegroups.com...
>
>
>
>
>
>
>
>
>
>
>
> - Mostra testo tra virgolette -
Hi, if I comment Response.Close(); works fine but i receive too HTML
code.
The page must contain only the value of "StrResult" because the same
page are request by a lot of VB6 application.
I can't upgrade all VB6 application...
Thanks in advice
Matteo

The ConnectionString property has not been initialized

Hi all,

I have developed a web page using asp.net. When testing ( debugging ) it from the VS 2005 it works properly.

In the load of the page I created a SqlConnection and specified the ConnectionString

The problem is when calling the page from a Fox Pro 9.0 application I get this message:

The ConnectionString property has not been initialized.

It seems that when calling the page from Fox Pro the ConnectionString is written incorrectly in the load method of the page

So does anyone have any suggestion?

Regards

Could you please specify the connection string over here. Also make sure that you have used new keyword while defining the connection string

Regards,

Suhas


Hi,

There is a article onconnection string here.

The ConnectionString property has not been initialized.

I am trying to use a connection string from web.config file for the first time. Here is my code.

Try
Dim cmd As String = _
("SELECT [Name], BirthDate, StartDate From " & _
"Employees WHERE PayGroup='20' AND Status='A'")

Dim conn As String = _
System.Configuration. _
ConfigurationManager. _
AppSettings("myConString")

Dim myConn As New SqlConnection(conn)
Dim myCmd As New SqlDataAdapter(cmd, myConn)
Dim ds As New DataSet
myCmd.Fill(ds)
gvEmp.DataSource = ds
gvEmp.DataBind()

Catch ex As Exception
Response.Write(ex.Message & "<br>")
Finally

End Try

I am getting The ConnectionString property has not been initialized. What am I doing wrong?Show your web.config code.
<connectionStrings>
<add name="myConString" connectionString="Data Source=myServer;Initial Catalog=Employees;User ID=myUser;Password=mypass"
providerName="System.Data.SqlClient" />
</connectionStrings>

The ConnectionString property has not been initialized.

Tried all kinds of things. I get the error.
The ConnectionString property has not been initialized.
Any help appreciated.
----
--
This is the web.config info
<configuration>
<appSettings>
<add key="connectionstring" value="Data Source=path to database;
database=testingsite;User Id=UserID;Password=password" />
</appSettings>
----
----
--
Here is the doc mentioned in the error.
Imports System.Data.SqlClient
Public Class Catalog
Public Shared Function GetDepartments() As SqlDataReader
' Create the connection object
Dim connection As New SqlConnection(connectionString)
' Create and initialize the command object
Dim command As New SqlCommand("dbo.GetDepartments", connection)
command.CommandType = CommandType.StoredProcedure
' Open the connection
connection.Open()
' Return a SqlDataReader to the calling function
Return command.ExecuteReader(CommandBehavior.CloseConnection)
End Function
Private Shared ReadOnly Property connectionString() As String
Get
Return ConfigurationSettings.AppSettings("ConnectionString")
End Get
End Property
End ClassLaura K wrote:
> Tried all kinds of things. I get the error.
> The ConnectionString property has not been initialized.
>
> Any help appreciated.
> ----
--
> This is the web.config info
> <configuration>
> <appSettings>
> <add key="connectionstring" value="Data Source=path to database;
> database=testingsite;User Id=UserID;Password=password" />
> </appSettings>
> ----
----
--
> Here is the doc mentioned in the error.
>
> Imports System.Data.SqlClient
>
> Public Class Catalog
> Public Shared Function GetDepartments() As SqlDataReader
> ' Create the connection object
> Dim connection As New SqlConnection(connectionString)
> ' Create and initialize the command object
> Dim command As New SqlCommand("dbo.GetDepartments", connection)
> command.CommandType = CommandType.StoredProcedure
> ' Open the connection
> connection.Open()
> ' Return a SqlDataReader to the calling function
> Return command.ExecuteReader(CommandBehavior.CloseConnection)
> End Function
> Private Shared ReadOnly Property connectionString() As String
> Get
> Return ConfigurationSettings.AppSettings("ConnectionString")
> End Get
> End Property
> End Class
>
I know the tags are case-sensitive in web.config. Can't remember about
the keys/vals values. Try changing the case sensitivity of your
.AppSettings call or the key name in the config (make them the same).
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
I tried dozen of case changes. That doesn't seem to be it.
Any other ideas?
"Craig Deelsnyder" <cdeelsny@dotnet.itags.org.NO_SPAM_4_MEyahoo.com> wrote in message
news:O4c2gb2UFHA.3584@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> Laura K wrote:
> I know the tags are case-sensitive in web.config. Can't remember about
> the keys/vals values. Try changing the case sensitivity of your
> .AppSettings call or the key name in the config (make them the same).
> --
> Craig Deelsnyder
> Microsoft MVP - ASP/ASP.NET
Try this:-
<add key="ConnectionString" value="Data Source=(local);
database=Northwind; Integrated Security=SSPI" />
MAKE SURE U ARE PASSING THE CORRECT KEY IN UR APPLICATION.
Patrick
*** Sent via Developersdex http://www.examnotes.net ***
> <add key="connectionstring" value="Data Source=path to database;
> database=testingsite;User Id=UserID;Password=password" />
When this says "path to database", what exactly is the value you're specifyi
ng?
It should be "servername" or "servername\instance".
-Brock
DevelopMentor
http://staff.develop.com/ballen
Patrick Olurotimi Ige wrote:
> Try this:-
> <add key="ConnectionString" value="Data Source=(local);
> database=Northwind; Integrated Security=SSPI" />
> MAKE SURE U ARE PASSING THE CORRECT KEY IN UR APPLICATION.
> Patrick
>
> *** Sent via Developersdex http://www.examnotes.net ***
Heh, I blew right past that part :) Obviously that's pry the problem...
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
When I say path to database it is remote.
sql3.webcontrolcenter.com
"Brock Allen" <ballen@dotnet.itags.org.NOSPAMdevelop.com> wrote in message
news:680347632511475258348832@dotnet.itags.org.msnews.microsoft.com...
> When this says "path to database", what exactly is the value you're
> specifying? It should be "servername" or "servername\instance".
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
Brock good u figured out that issue ..
And Laura have u finally fixed the connection?
Patrick
*** Sent via Developersdex http://www.examnotes.net ***
Nope connection not fixed. I am also posting this on another forum. Here
is a list of docs. would love to have help. I am totally lost on this one.
Here is the exact same thing as I posted on the other forum. Any help
appreciated.
Here is the situation. I am following a book, "Beginning ASP.NET 1.1
E-Commerce. The book has me working on a local SQL server. I am working
remotly and trying to make the changes needed to do it that way.
Instead of posting code I will post a txt version of the docs.
This contains the code for the connection
http://209.200.112.194/txtdocs/catalog.vb.txt
This is a user control code behind
http://209.200.112.194/txtdocs/depa...ist.ascx.vb.txt
this is the user control - view source to see the code
http://209.200.112.194/txtdocs/departmentslist.ascx.txt
web config
http://209.200.112.194/txtdocs/web.config.txt
Help?
Laura
"Patrick Olurotimi Ige" <naijacoder@dotnet.itags.org.hotmail.com> wrote in message
news:Otxjw$EVFHA.2616@dotnet.itags.org.TK2MSFTNGP14.phx.gbl...
> Brock good u figured out that issue ..
> And Laura have u finally fixed the connection?
> Patrick
>
> *** Sent via Developersdex http://www.examnotes.net ***
Laura maybe you can give a try like this:-
Don't use:-
ConfigurationSettings.AppSettings("ConnectionString")
Try including your connectionstring in ur code like:-
Dim connection As New SqlConnection("Data Source=SERVERNAME;Initial
Catalog=YOURDATABASE;User Id=sa;Password=asdasd;")
Hope that helps
** See how it goes**
Patrick
*** Sent via Developersdex http://www.examnotes.net ***