Showing posts with label troubles. Show all posts
Showing posts with label troubles. Show all posts

Tuesday, March 13, 2012

Troubles displaying a changing read-only value

I am writing a form with one value being a total of a couple other values from my page. I put this in a read-only textbox so it can't be changed, and when I change the other boxes values, the JavaScript automatically changes this value. However, when I generate the e-mail I use textboxTotalSpace.text to make it appear in my email, but this will only display the original value, and not the new one.

Does anyone know how I fix this?

Thanks.

TextBox server control will not pick up the changed values (during LoadPostData()) if the textbox is set to read only. Check this link for a fix:

http://aspadvice.com/blogs/joteke/archive/2006/04/12/16409.aspx

Hope this helps,

Vivek


Thanks Vivek, but I am unsure where I am supposed to add theTextBox1.Attributes.Add("readonly","readonly")


That should go in the Page_Load event.

protected void Page_Load(object sender, EventArgs e)
{
// add the javascript attributes
TextBox1.Attributes.Add("readonly", "readonly");
}

Thanks


Because you are changing data at client side using java script....


You can put this in the Page Load method.


suresh modiya:

Because you are changing data at client side using java script....

Changed text box value client side WILL show up in the server code behind because textbox implements IPostBackDataHandler interface and it loads its value from the forms POST data in the LoadPostBackData() method.

Its only when it is set to readonly that this data load will not work on postback, hence the alternative.

Vivek

Troubles in .cs compile with unc type oledb connections strings..

I have an .cs file I need to compile with csc.exe for codebehind
access (no VS.NET). Trouble is that my oledb connection needs to use
a unc type path.. when I use the unc path in conn I get
escape sequence errors from csc.exe.. so I tried a static
mapped drive with reversed \ / from a google I found. The
.cs compiles but the conn doesn't work.. so if I can find
a method to get unc style conn to compile, I think I would be
golden. It's a known working oledb conn used all over the place
in standard asp and aspx files.. any clues into getting the
escape sequences corrected would be appreciated.. here
is what the conn would looks like of the .cs
"Provider=Advantage OLE DB Provider; Data Source=\\server\path\dir; ServerTy
pe=ADS_REMOTE_SERVER;
TableType=ADS_CDX;FilterOptions=RESPECT_
WHEN_COUNTING;"
Thanks, BobIn a C# string, backslashes are escape characters. To escape a backslash,
escape it with a backslash.
HTH,
Kevin Spencer
Microsoft MVP
.Net Developer
Neither a follower nor a lender be.
"Bob [BVP]" <bb4@.pmount.com> wrote in message
news:uzkZyQy$EHA.1296@.TK2MSFTNGP10.phx.gbl...
> I have an .cs file I need to compile with csc.exe for codebehind
> access (no VS.NET). Trouble is that my oledb connection needs to use
> a unc type path.. when I use the unc path in conn I get
> escape sequence errors from csc.exe.. so I tried a static
> mapped drive with reversed \ / from a google I found. The
> .cs compiles but the conn doesn't work.. so if I can find
> a method to get unc style conn to compile, I think I would be
> golden. It's a known working oledb conn used all over the place
> in standard asp and aspx files.. any clues into getting the
> escape sequences corrected would be appreciated.. here
> is what the conn would looks like of the .cs
> "Provider=Advantage OLE DB Provider; Data Source=\\server\path\dir;
> ServerType=ADS_REMOTE_SERVER;
> TableType=ADS_CDX;FilterOptions=RESPECT_
WHEN_COUNTING;"
> Thanks, Bob
>
Thanks.. If I have \\server\share it would be \\\\server\\share ?
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:udIvrMz$EHA.2196@.TK2MSFTNGP14.phx.gbl...
> In a C# string, backslashes are escape characters. To escape a backslash,
> escape it with a backslash.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Neither a follower nor a lender be.
> "Bob [BVP]" <bb4@.pmount.com> wrote in message
> news:uzkZyQy$EHA.1296@.TK2MSFTNGP10.phx.gbl...
>

Troubles in .cs compile with unc type oledb connections strings..

I have an .cs file I need to compile with csc.exe for codebehind
access (no VS.NET). Trouble is that my oledb connection needs to use
a unc type path.. when I use the unc path in conn I get
escape sequence errors from csc.exe.. so I tried a static
mapped drive with reversed \ / from a google I found. The
..cs compiles but the conn doesn't work.. so if I can find
a method to get unc style conn to compile, I think I would be
golden. It's a known working oledb conn used all over the place
in standard asp and aspx files.. any clues into getting the
escape sequences corrected would be appreciated.. here
is what the conn would looks like of the .cs

"Provider=Advantage OLE DB Provider; Data Source=\\server\path\dir; ServerType=ADS_REMOTE_SERVER;
TableType=ADS_CDX;FilterOptions=RESPECT_WHEN_COUNT ING;"

Thanks, BobIn a C# string, backslashes are escape characters. To escape a backslash,
escape it with a backslash.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Bob [BVP]" <bb4@.pmount.com> wrote in message
news:uzkZyQy$EHA.1296@.TK2MSFTNGP10.phx.gbl...
> I have an .cs file I need to compile with csc.exe for codebehind
> access (no VS.NET). Trouble is that my oledb connection needs to use
> a unc type path.. when I use the unc path in conn I get
> escape sequence errors from csc.exe.. so I tried a static
> mapped drive with reversed \ / from a google I found. The
> .cs compiles but the conn doesn't work.. so if I can find
> a method to get unc style conn to compile, I think I would be
> golden. It's a known working oledb conn used all over the place
> in standard asp and aspx files.. any clues into getting the
> escape sequences corrected would be appreciated.. here
> is what the conn would looks like of the .cs
> "Provider=Advantage OLE DB Provider; Data Source=\\server\path\dir;
> ServerType=ADS_REMOTE_SERVER;
> TableType=ADS_CDX;FilterOptions=RESPECT_WHEN_COUNT ING;"
> Thanks, Bob
Thanks.. If I have \\server\share it would be \\\\server\\share ?

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:udIvrMz$EHA.2196@.TK2MSFTNGP14.phx.gbl...
> In a C# string, backslashes are escape characters. To escape a backslash,
> escape it with a backslash.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> .Net Developer
> Neither a follower nor a lender be.
> "Bob [BVP]" <bb4@.pmount.com> wrote in message
> news:uzkZyQy$EHA.1296@.TK2MSFTNGP10.phx.gbl...
> > I have an .cs file I need to compile with csc.exe for codebehind
> > access (no VS.NET). Trouble is that my oledb connection needs to use
> > a unc type path.. when I use the unc path in conn I get
> > escape sequence errors from csc.exe.. so I tried a static
> > mapped drive with reversed \ / from a google I found. The
> > .cs compiles but the conn doesn't work.. so if I can find
> > a method to get unc style conn to compile, I think I would be
> > golden. It's a known working oledb conn used all over the place
> > in standard asp and aspx files.. any clues into getting the
> > escape sequences corrected would be appreciated.. here
> > is what the conn would looks like of the .cs
> > "Provider=Advantage OLE DB Provider; Data Source=\\server\path\dir;
> > ServerType=ADS_REMOTE_SERVER;
> > TableType=ADS_CDX;FilterOptions=RESPECT_WHEN_COUNT ING;"
> > Thanks, Bob

Troubles reference this pointer in external class file

I'm wanting to reference page controls from a cs file in the app_code
directory. I'm getting a _Defaullt could not be found, missing
directive or assembly reference error. Very simple example below.
Default.aspx.cs:
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class1.UpdateButtonText(this);
}
}
Class1.cs
using System;
public class Class1
{
public Class1()
{
}
public static void UpdateButtonText(_Default global_Default)
{
}
}
Peter Kellner
http://peterkellner.netThis is impossible as the App_Code directory is compiled prior to your aspx
files.
-Brock
http://staff.develop.com/ballen

> I'm wanting to reference page controls from a cs file in the app_code
> directory. I'm getting a _Defaullt could not be found, missing
> directive or assembly reference error. Very simple example below.
> Default.aspx.cs:
> using System;
> using System.Web.UI;
> public partial class _Default : Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> Class1.UpdateButtonText(this);
> }
> }
> --
> Class1.cs
> using System;
> public class Class1
> {
> public Class1()
> {
> }
> public static void UpdateButtonText(_Default global_Default)
> {
> }
> }
> Peter Kellner
> http://peterkellner.net
On Fri, 9 Jun 2006 23:24:03 +0000 (UTC), Brock Allen
<ballen@.NOSPAMdevelop.com> wrote:

>This is impossible as the App_Code directory is compiled prior to your aspx
>files.
>-Brock
>http://staff.develop.com/ballen
>
Thanks,
Makes sense to me now. When I moved Class2 directly into the aspx.cs
file it of course worked. Hadn't really thought about the order of
compilation.
-peter
----
using System;
using System.Web.UI;
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Class2.UpdateButtonText(this);
}
}
public class Class2
{
public Class2()
{
}
public static void UpdateButtonText(_Default global_Default)
{
throw new Exception("The method or operation is not
implemented.");
}
}
Peter Kellner
http://peterkellner.net

Troubles Querying Database in Application_Start


I'm having trouble with my security model, Application_Start, and accessing
my database.
My ASP.NET app is only going to be running in an intranet environment (not
on the public Internet). The production environment will have installed
everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
Win2k Server).
In IIS, I have disabled anonymous access so that only Integrated Windows
authentication is used. Then in my Web.config file I've set it up to use
Windows authentication, as such:
<appSettings>
<add key="connectionString"
value=" database=RegPerfectDb;server=localhost;T
rusted_Connection=true" />
</appSettings>
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
<identity impersonate="true" />
</system.web>
Then, in my Application_Start event in Global.asax, I need to run a query or
two to get some application-wide data from our database and store it in the
application cache.
When I try to access a database from Application_Start, I get the following
error:
System.Data.SqlClient.SqlException: Cannot open database requested in login
'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
It's as if it is using the default ASP.NET worker process account (which is
not what I want). I need it to authenticate/authorize the logged in user
(which has access to the database) and use that user to access the database.
So, my questions are: what am I doing wrong? how do I set up IIS,
Web.config, database connection, etc. so that everything is properly
authenticated/authorized to the logged in user so that I can query the
database in Application_Start?
Thanks in advance for your help.This is because when the application starts, it isn't running under any
particular user. That only happens for page requests - which is processed
after the application is started. Application_Start runs only once - and so
in what you are proposing, it would happen to run under whoever happened to
be the first person to access the application? It just doesn't work that
way.
Whatever you do in application_start can't rely on what user happened to
have made the first request to this app - so it needs a connection
independent of that.
"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value=" database=RegPerfectDb;server=localhost;T
rusted_Connection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
or
> two to get some application-wide data from our database and store it in
the
> application cache.
>
> When I try to access a database from Application_Start, I get the
following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
>
>
have a browse through the matrix.
how are you connecting to sql server ? trusted connection ? or sql user /
password ?
http://msdn.microsoft.com/library/d.../>
NetAP05.asp
if you are using trusted connection or SSPI then your MACHINENAME\ASPNET
account will have to be granted access to the database (if you want to
enable access from application as there is no user context) plus for normal
user access dont forget to use <impersonate> in web.config
copying from an old code project article (though i wouldnt give access to
ASPNET account as DBOwner i would just just read / write on certain stored
procs
This should work on all other IIS 5.1 (possibly other versions)
combinations. The only difference between IIS 5.1 and IIS 6 is the account
the ASP.NET process runs under. IIS 5.1 runs under a %MACHINENAME%\ASPNET
where %MACHINENAME% is the machine name.
osql -E -S %SERVER%\%INSTANCE% -Q "sp_grantlogin '%MACHINENAME%\ASPNET'"Now
our ASP.NET application will be able to log into the server. Now all thats
left is to grant access to the databases.
osql -E -S %SERVER%\%INSTANCE% -d %DATABASE%
-Q "sp_grantdbaccess '%MACHINENAME%\ASPNET'"
osql -E -S %SERVER%\%INSTANCE% -d %DATABASE%
-Q "sp_addrolemember 'db_owner', '%MACHINENAME%\ASPNET'"These 2 lines will
add access to one of the databases. So if you want to add access to another
database just change %DATABASE% and run both lines.
other way open Query Analyser and do an "EXEC stored proc values here"
--
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value=" database=RegPerfectDb;server=localhost;T
rusted_Connection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
or
> two to get some application-wide data from our database and store it in
the
> application cache.
>
> When I try to access a database from Application_Start, I get the
following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
>
>
Interesting. Does this only happen in Application_Start event? Does it
connect to SQL as the logged in user in a later event, say from Page_Load?
Greg
"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
> accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value=" database=RegPerfectDb;server=localhost;T
rusted_Connection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
> or
> two to get some application-wide data from our database and store it in
> the
> application cache.
>
> When I try to access a database from Application_Start, I get the
> following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
> login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
> is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
> database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
>
>
> Whatever you do in application_start can't rely on what user happened to
> have made the first request to this app - so it needs a connection
> independent of that.
Ah, that makes good sense. Missed that.
Thanks for the info. That totally makes sense. Do you or does anyone else
have any suggestions on how to do what I'm looking to do? Maybe, put the
code in Session_Start (but then I don't need it to run for every new
session)? Or'
Thanks!
"Marina" <someone@.nospam.com> wrote in message
news:OPn5fsbmEHA.3464@.tk2msftngp13.phx.gbl...
> This is because when the application starts, it isn't running under any
> particular user. That only happens for page requests - which is processed
> after the application is started. Application_Start runs only once - and
so
> in what you are proposing, it would happen to run under whoever happened
to
> be the first person to access the application? It just doesn't work that
> way.
> Whatever you do in application_start can't rely on what user happened to
> have made the first request to this app - so it needs a connection
> independent of that.
> "Ober" <ober@.yahoo.com> wrote in message
> news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
> accessing
(not
a
use
/>
query
> or
> the
> following
> login
> is
user
> database.
>
Is there any reason why you can't create a login for the ASPNET user?
Also, it is recommended that you use a single account to access your
database rather than use an account for each user. That way you will be
using your pooled connections more efficiently.
- Frank Mamone
"Ober" <ober@.yahoo.com> wrote in message
news:%23iZ16qdmEHA.3868@.TK2MSFTNGP11.phx.gbl...
> Thanks for the info. That totally makes sense. Do you or does anyone
else
> have any suggestions on how to do what I'm looking to do? Maybe, put the
> code in Session_Start (but then I don't need it to run for every new
> session)? Or'
> Thanks!
>
> "Marina" <someone@.nospam.com> wrote in message
> news:OPn5fsbmEHA.3464@.tk2msftngp13.phx.gbl...
processed
and
> so
> to
> (not
installed
on
> a
Windows
> use
> />
> query
in
'MACHINENAME\ASPNET'.
(which
> user
>

Troubles Querying Database in Application_Start


I'm having trouble with my security model, Application_Start, and accessing
my database.

My ASP.NET app is only going to be running in an intranet environment (not
on the public Internet). The production environment will have installed
everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
Win2k Server).

In IIS, I have disabled anonymous access so that only Integrated Windows
authentication is used. Then in my Web.config file I've set it up to use
Windows authentication, as such:

<appSettings
<add key="connectionString"
value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true" /
</appSettings
<system.web
<authentication mode="Windows" /
<authorization
<deny users="?" /
</authorization
<identity impersonate="true" /
</system.web
Then, in my Application_Start event in Global.asax, I need to run a query or
two to get some application-wide data from our database and store it in the
application cache.

When I try to access a database from Application_Start, I get the following
error:

System.Data.SqlClient.SqlException: Cannot open database requested in login
'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.

It's as if it is using the default ASP.NET worker process account (which is
not what I want). I need it to authenticate/authorize the logged in user
(which has access to the database) and use that user to access the database.

So, my questions are: what am I doing wrong? how do I set up IIS,
Web.config, database connection, etc. so that everything is properly
authenticated/authorized to the logged in user so that I can query the
database in Application_Start?

Thanks in advance for your help.This is because when the application starts, it isn't running under any
particular user. That only happens for page requests - which is processed
after the application is started. Application_Start runs only once - and so
in what you are proposing, it would happen to run under whoever happened to
be the first person to access the application? It just doesn't work that
way.

Whatever you do in application_start can't rely on what user happened to
have made the first request to this app - so it needs a connection
independent of that.

"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
or
> two to get some application-wide data from our database and store it in
the
> application cache.
>
> When I try to access a database from Application_Start, I get the
following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
have a browse through the matrix.
how are you connecting to sql server ? trusted connection ? or sql user /
password ?

http://msdn.microsoft.com/library/d.../SecNetAP05.asp

if you are using trusted connection or SSPI then your MACHINENAME\ASPNET
account will have to be granted access to the database (if you want to
enable access from application as there is no user context) plus for normal
user access dont forget to use <impersonate> in web.config

copying from an old code project article (though i wouldnt give access to
ASPNET account as DBOwner i would just just read / write on certain stored
procs
This should work on all other IIS 5.1 (possibly other versions)
combinations. The only difference between IIS 5.1 and IIS 6 is the account
the ASP.NET process runs under. IIS 5.1 runs under a %MACHINENAME%\ASPNET
where %MACHINENAME% is the machine name.

osql -E -S %SERVER%\%INSTANCE% -Q "sp_grantlogin '%MACHINENAME%\ASPNET'"Now
our ASP.NET application will be able to log into the server. Now all thats
left is to grant access to the databases.

osql -E -S %SERVER%\%INSTANCE% -d %DATABASE%
-Q "sp_grantdbaccess '%MACHINENAME%\ASPNET'"
osql -E -S %SERVER%\%INSTANCE% -d %DATABASE%
-Q "sp_addrolemember 'db_owner', '%MACHINENAME%\ASPNET'"These 2 lines will
add access to one of the databases. So if you want to add access to another
database just change %DATABASE% and run both lines.

other way open Query Analyser and do an "EXEC stored proc values here"
--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
or
> two to get some application-wide data from our database and store it in
the
> application cache.
>
> When I try to access a database from Application_Start, I get the
following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
Interesting. Does this only happen in Application_Start event? Does it
connect to SQL as the logged in user in a later event, say from Page_Load?

Greg

"Ober" <ober@.yahoo.com> wrote in message
news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
>
> I'm having trouble with my security model, Application_Start, and
> accessing
> my database.
>
> My ASP.NET app is only going to be running in an intranet environment (not
> on the public Internet). The production environment will have installed
> everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on a
> Win2k Server).
>
> In IIS, I have disabled anonymous access so that only Integrated Windows
> authentication is used. Then in my Web.config file I've set it up to use
> Windows authentication, as such:
>
> <appSettings>
> <add key="connectionString"
> value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true" />
> </appSettings>
>
> <system.web>
> <authentication mode="Windows" />
> <authorization>
> <deny users="?" />
> </authorization>
> <identity impersonate="true" />
> </system.web>
>
> Then, in my Application_Start event in Global.asax, I need to run a query
> or
> two to get some application-wide data from our database and store it in
> the
> application cache.
>
> When I try to access a database from Application_Start, I get the
> following
> error:
>
> System.Data.SqlClient.SqlException: Cannot open database requested in
> login
> 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
>
> It's as if it is using the default ASP.NET worker process account (which
> is
> not what I want). I need it to authenticate/authorize the logged in user
> (which has access to the database) and use that user to access the
> database.
>
>
> So, my questions are: what am I doing wrong? how do I set up IIS,
> Web.config, database connection, etc. so that everything is properly
> authenticated/authorized to the logged in user so that I can query the
> database in Application_Start?
>
> Thanks in advance for your help.
>
>
> Whatever you do in application_start can't rely on what user happened to
> have made the first request to this app - so it needs a connection
> independent of that.

Ah, that makes good sense. Missed that.
Thanks for the info. That totally makes sense. Do you or does anyone else
have any suggestions on how to do what I'm looking to do? Maybe, put the
code in Session_Start (but then I don't need it to run for every new
session)? Or??
Thanks!

"Marina" <someone@.nospam.com> wrote in message
news:OPn5fsbmEHA.3464@.tk2msftngp13.phx.gbl...
> This is because when the application starts, it isn't running under any
> particular user. That only happens for page requests - which is processed
> after the application is started. Application_Start runs only once - and
so
> in what you are proposing, it would happen to run under whoever happened
to
> be the first person to access the application? It just doesn't work that
> way.
> Whatever you do in application_start can't rely on what user happened to
> have made the first request to this app - so it needs a connection
> independent of that.
> "Ober" <ober@.yahoo.com> wrote in message
> news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
> > I'm having trouble with my security model, Application_Start, and
> accessing
> > my database.
> > My ASP.NET app is only going to be running in an intranet environment
(not
> > on the public Internet). The production environment will have installed
> > everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all on
a
> > Win2k Server).
> > In IIS, I have disabled anonymous access so that only Integrated Windows
> > authentication is used. Then in my Web.config file I've set it up to
use
> > Windows authentication, as such:
> > <appSettings>
> > <add key="connectionString"
> > value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true"
/>
> > </appSettings>
> > <system.web>
> > <authentication mode="Windows" />
> > <authorization>
> > <deny users="?" />
> > </authorization>
> > <identity impersonate="true" />
> > </system.web>
> > Then, in my Application_Start event in Global.asax, I need to run a
query
> or
> > two to get some application-wide data from our database and store it in
> the
> > application cache.
> > When I try to access a database from Application_Start, I get the
> following
> > error:
> > System.Data.SqlClient.SqlException: Cannot open database requested in
> login
> > 'DatabaseName'. Login fails. Login failed for user 'MACHINENAME\ASPNET'.
> > It's as if it is using the default ASP.NET worker process account (which
> is
> > not what I want). I need it to authenticate/authorize the logged in
user
> > (which has access to the database) and use that user to access the
> database.
> > So, my questions are: what am I doing wrong? how do I set up IIS,
> > Web.config, database connection, etc. so that everything is properly
> > authenticated/authorized to the logged in user so that I can query the
> > database in Application_Start?
> > Thanks in advance for your help.
Is there any reason why you can't create a login for the ASPNET user?

Also, it is recommended that you use a single account to access your
database rather than use an account for each user. That way you will be
using your pooled connections more efficiently.

- Frank Mamone

"Ober" <ober@.yahoo.com> wrote in message
news:%23iZ16qdmEHA.3868@.TK2MSFTNGP11.phx.gbl...
> Thanks for the info. That totally makes sense. Do you or does anyone
else
> have any suggestions on how to do what I'm looking to do? Maybe, put the
> code in Session_Start (but then I don't need it to run for every new
> session)? Or??
> Thanks!
>
> "Marina" <someone@.nospam.com> wrote in message
> news:OPn5fsbmEHA.3464@.tk2msftngp13.phx.gbl...
> > This is because when the application starts, it isn't running under any
> > particular user. That only happens for page requests - which is
processed
> > after the application is started. Application_Start runs only once -
and
> so
> > in what you are proposing, it would happen to run under whoever happened
> to
> > be the first person to access the application? It just doesn't work that
> > way.
> > Whatever you do in application_start can't rely on what user happened to
> > have made the first request to this app - so it needs a connection
> > independent of that.
> > "Ober" <ober@.yahoo.com> wrote in message
> > news:e0dDiobmEHA.3392@.TK2MSFTNGP15.phx.gbl...
> > > > > I'm having trouble with my security model, Application_Start, and
> > accessing
> > > my database.
> > > > > > My ASP.NET app is only going to be running in an intranet environment
> (not
> > > on the public Internet). The production environment will have
installed
> > > everything locally (i.e., IIS, SQL Server, .NET Framework, etc., all
on
> a
> > > Win2k Server).
> > > > > > In IIS, I have disabled anonymous access so that only Integrated
Windows
> > > authentication is used. Then in my Web.config file I've set it up to
> use
> > > Windows authentication, as such:
> > > > > > <appSettings>
> > > > <add key="connectionString"
> > > value="database=RegPerfectDb;server=localhost;Trusted_Con nection=true"
> />
> > > > </appSettings>
> > > > > > <system.web>
> > > > <authentication mode="Windows" />
> > > > <authorization>
> > > > <deny users="?" />
> > > > </authorization>
> > > > <identity impersonate="true" />
> > > > </system.web>
> > > > > > Then, in my Application_Start event in Global.asax, I need to run a
> query
> > or
> > > two to get some application-wide data from our database and store it
in
> > the
> > > application cache.
> > > > > > When I try to access a database from Application_Start, I get the
> > following
> > > error:
> > > > > > System.Data.SqlClient.SqlException: Cannot open database requested in
> > login
> > > 'DatabaseName'. Login fails. Login failed for user
'MACHINENAME\ASPNET'.
> > > > > > It's as if it is using the default ASP.NET worker process account
(which
> > is
> > > not what I want). I need it to authenticate/authorize the logged in
> user
> > > (which has access to the database) and use that user to access the
> > database.
> > > > > > > > So, my questions are: what am I doing wrong? how do I set up IIS,
> > > Web.config, database connection, etc. so that everything is properly
> > > authenticated/authorized to the logged in user so that I can query the
> > > database in Application_Start?
> > > > > > Thanks in advance for your help.
> > > > > > >

Troubles sending email with System.Net.Mail (ASP.NET 2.0)

Hi All,

I am having difficulties sending an email from a web page that I created to my own email. This particular web pages is suppose to be a feedback form where people can leave feedback about the site and it should send the message to my email. The Exception message I get is: "Failure sending mail." Here is the piece of code I use to handle the email sending. If anyone can shed some light on this issue, it would be greatly appreciated :)

protectedvoid btnSubmit_Click(object sender,EventArgs e)

{

try

{

SmtpClient emailClient =newSmtpClient();

MailMessage email =newMailMessage();

emailClient.Host ="localhost";

emailClient.Port = 25;

email.To.Add(newMailAddress("kevintrinh.n@dotnet.itags.org.gmail.com"));

email.From =newMailAddress(txtEmail.Text);

email.Subject ="Enquiry";

email.Body ="Testing";

email.IsBodyHtml =false;

emailClient.Send(email);

}

catch(Exception ex)

{

Response.Write(ex.Message);

}

}

Cheers guys

Check the SMTP logs to start troubleshooting this.

Jeff


You'll need more detailed error info to get help.

One quick thing to check, is antivirus software on your computer blocking your code from sending email?


I have a feedback page, too, and it works great. Here's my code:

The Click Event:

public void SendMail_Click(object sender, EventArgs e)

{

SendMail();

}


public void SendMail()
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
mail.From = new MailAddress(WebConfigurationManager.AppSettings["DefaultMailFrom"], "Internet User: " + txtName.Text);
mail.To.Add(WebConfigurationManager.AppSettings["DefaultMailTo"]);
if (txtEmail.Text.Trim() != "")
mail.ReplyTo = new MailAddress(txtEmail.Text.Trim());

//set the content
mail.Subject = txtSubject.Text;
mail.Body = txtBody.Text;
mail.Body += "\n\nReferring page: " + lnkReferrerF.NavigateUrl;

//send the message
SmtpClient smtp = new SmtpClient(WebConfigurationManager.AppSettings["DefaultMailServer"]);
smtp.Send(mail);
}

And then under <AppSettings> in the web.config file I have:

<add key="DefaultMailFrom" value="mailer@.site.com" />
<add key="DefaultMailReplyTo" value="david@.site.com" />
<add key="DefaultMailTo" value="david@.site.com" />

<add key="DefaultMailServer" value="mailserver name" />

Hope this helps.


Kevin-

If you're currently trying to run this on your local PC, make sure you have an SMTP server running on your box. Open up the IIS Configuration in your Control Panel > Administrative Tools and make sure the Default SMTP Virtual Server is started.

Thanks~


Hi everyone,

Thanks for all the insight...I really appreciate it. I will take a look at all your suggestions and follow up. Thanks again guys :)

Cheers


Dear Friend,

Also check out if you are running any anti virus scanners. Sometimes those applications blocks the port for sending out the emails. You may need to configure them to send out the emails.


tanglin05:

Kevin-

If you're currently trying to run this on your local PC, make sure you have an SMTP server running on your box. Open up the IIS Configuration in your Control Panel > Administrative Tools and make sure the Default SMTP Virtual Server is started.

Thanks~

Hi Todd,

I think this is my problem. I've taken a look on the net and all the tutorials explain the procedure to configure the virtual smtp server for all windows other than VISTA. Just wondering if you know how to configure the settings on vista or if you/anyone know of any links that may point me in the right direction?
In the mean time I will continue looking for explanations online :)

Thanks mate.


Kevin-

I'm away from my desktop right now, so I don't have Vista handy. Based on these posts I found on the Net, it appears SMTP may not be in Vista (?!):

http://tfl09.blogspot.com/2007/03/smtp-in-vista-or-not.html

http://weblogs.asp.net/steveschofield/archive/2006/12/19/iis7-post-23-vista-and-smtp-server-where-is-it.aspx

I can't verify this right now, so if anyone knows otherwise please correct me. The links I provided have references to shareware SMTP servers that you can install to solve your problem, so this may help you get on your way.

Thanks~


Todd you're a champ mate...I downloaded a free smtp server and it sends nowBig Smile');" title="Big Smile -Big Smile">

Just some tips for anyone else with a similar problem. If you are trying to send emails from you local machine, make sure the ISP you are going through does not block port 25 (else your emails cannot be sent). I found that I could send from uni but I couldn't send from home (for the above reason)

If everything seems ok with your code and server setup however you do not receive any emails.....check your SPAM folder!! (This is also what happened to me; spent 2 long hours trying to work out why I wasn't receiving any emails!)

I found the following SMTP server application to be the most useful one out there as it allows you to test whether port 25 is open. You can download the free 30day trial here1st SMTP Server

Hope this helps anyone facing the same email problems as I didSmile');" title="Smile -Smile">

Thanks again everyone for your helpYes');" title="Yes -Yes">

Troubles reference this pointer in external class file

I'm wanting to reference page controls from a cs file in the app_code
directory. I'm getting a _Defaullt could not be found, missing
directive or assembly reference error. Very simple example below.

Default.aspx.cs:

using System;
using System.Web.UI;

public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)
{
Class1.UpdateButtonText(this);
}
}

------

Class1.cs

using System;

public class Class1
{
public Class1()
{
}

public static void UpdateButtonText(_Default global_Default)
{
}
}
Peter Kellner
http://peterkellner.netThis is impossible as the App_Code directory is compiled prior to your aspx
files.

-Brock
http://staff.develop.com/ballen

> I'm wanting to reference page controls from a cs file in the app_code
> directory. I'm getting a _Defaullt could not be found, missing
> directive or assembly reference error. Very simple example below.
> Default.aspx.cs:
> using System;
> using System.Web.UI;
> public partial class _Default : Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void Button1_Click(object sender, EventArgs e)
> {
> Class1.UpdateButtonText(this);
> }
> }
> ------
> Class1.cs
> using System;
> public class Class1
> {
> public Class1()
> {
> }
> public static void UpdateButtonText(_Default global_Default)
> {
> }
> }
> Peter Kellner
> http://peterkellner.net
On Fri, 9 Jun 2006 23:24:03 +0000 (UTC), Brock Allen
<ballen@.NOSPAMdevelop.com> wrote:

>This is impossible as the App_Code directory is compiled prior to your aspx
>files.
>-Brock
>http://staff.develop.com/ballen
>
Thanks,

Makes sense to me now. When I moved Class2 directly into the aspx.cs
file it of course worked. Hadn't really thought about the order of
compilation.

-peter

----------------

using System;
using System.Web.UI;

public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}

protected void Button1_Click(object sender, EventArgs e)
{
Class2.UpdateButtonText(this);
}
}

public class Class2
{
public Class2()
{
}

public static void UpdateButtonText(_Default global_Default)
{
throw new Exception("The method or operation is not
implemented.");
}
}
Peter Kellner
http://peterkellner.net

Troubles with cookies

Hi,

I've some troubles using cookies in my ASP.NET application (C#).
I write a cookie in a page which is in the /login subfolder of the web and I
set an appropriate expire date. But if I intend to read that cookie from
other pages which lie directly at the root folder of the web app, I only get
an empty value and the expire date "1/1/1". What is wrong? Can't I read all
cookies of the web no matter where they were set? Can anyone help me?

AzatUsually when you issue a cookie, it's available site-wide. The Path property
indicates what level in the app the cookie belongs to and it defaults to
"/", which means the cookie is available site wide.

I'm wondering if either the client has disabled cookies or if the time on
the client machine is out of synch with the server.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hi,
> I've some troubles using cookies in my ASP.NET application (C#).
> I write a cookie in a page which is in the /login subfolder of the web
> and I
> set an appropriate expire date. But if I intend to read that cookie
> from
> other pages which lie directly at the root folder of the web app, I
> only get
> an empty value and the expire date "1/1/1". What is wrong? Can't I
> read all
> cookies of the web no matter where they were set? Can anyone help me?
> Azat

Troubles with DropDownList

Hi

I've got problem with DropDownList, because when I change values, I've still got the first value of List.

So, how to set new selected value of DropDownList?I guess you have the following code concept in your page: "on a page_load, retrieve the data from a database or some other source and bind it to the control". This is right but incomplete. In fact Page_Load is fired also on a postback, so when a user selects something in the dropdownlist and the page is posted back (automatically or manually) to the server, the Page_Load is executed again. In order to execute the binding code only when needed, use this skeleton of code:

if (!Page.IsPostBack) {
//do the binding
}
//do other things that are not affected by a postback
.

Now, you're rebinding the controls every time the page is loaded; this code will perform the binding only when no postback is done (thus, only on the first request to the page).
Great Thanks
Now everything is working :)

Troubles with INSERT command

Hi, I am currently trying to INSERT selected rows from table Cart intotable Orders. Table Cart has columns Id_record(autonumber),Id_title(LongInt), Customer(text), Table Orders has the same columnsand also column Order_ID. When I delete this colums Order_ID and insertonly values from table cart like this, it works.
queryString = "INSERT INTO [Orders] SELECT * FROM [Cart] WHERE Cart.Customer = @dotnet.itags.org.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.user", OleDbType.Char, 20))
dbCommand.Parameters("@dotnet.itags.org.user").Value = user.Identity.Name

Troubles begin, when I try to insert also that randomly generated number into my table Orders. I use this code...
Dim myConnection as OleDbConnection = new OleDbConnection(connectionString)
queryString = "INSERT INTO [Orders] SELECT *, @dotnet.itags.org.random as Order_ID FROM [Cart] WHERE Cart.Customer = @dotnet.itags.org.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.user", OleDbType.Char, 20))
dbCommand.Parameters("@dotnet.itags.org.user").Value = user.Identity.Name
Randomize()
dbCommand.Parameters.Add(New OleDbParameter("@dotnet.itags.org.random", OleDbType.Integer, 20))
dbCommand.Parameters("@dotnet.itags.org.random").Value = ((Int32.MaxValue) * Rnd)
I always ger error "Duplicate output destination in Id_record" andhave no idea, how to fix it. Could pls somebody help me? Or could ugive me some link on some good INSERT tutorial?

If both the tables are not EXCTLY similar in columns you would get errors. So list out the column names xplicitly.
INSERT INTO col1, col2, col3 SELECT cart.col1, cart,col2, cart.col3 FROM cart WHERE Cart.Customer = @.user"

Exclude the identity column since you cannot manually insert into it.


Hm, so I changed my query into something like this, but now im gettingOverflow error. Does someone know what Overflow error means? Could bethis error caused bz the fact, that Id_record is autonumber in Carttable but I am trying to isnert it as integer in Orders table?

Dim myConnection as OleDbConnection = new OleDbConnection(connectionString)
queryString = "INSERT INTO [Orders] (Id_record,Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer,@.user FROM [Cart] WHERE Cart.Customer = @.user"
Dim dbCommand as OleDbCommand = new OleDbCommand(queryString, myConnection)
Randomize()
Dim Rand As Int32 = ((Int32.MaxValue) * Rnd)
dbCommand.Parameters.Add(New OleDbParameter("@.random", OleDbType.Integer, 20))
dbCommand.Parameters("@.random").Value = Rand
dbCommand.Parameters.Add(New OleDbParameter("@.user", OleDbType.Char, 20))
dbCommand.Parameters("@.user").Value = user.Identity.Name


queryString = "INSERT INTO [Orders] (Id_record, Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer, @.user FROM [Cart] WHERE Cart.Customer = @.user"

is Orders.Id_order column a autonumber column? if so you cant explicity insert into this column.
providing the sqldatatype(integer?) of Cart.Id_record is the same type as Orders.ID_record it shouldnt be a problem.
Well, Cart.ID_Record is the autonumber and Orders.ID_record is theinteger. I need to insert this autonumber into Orders.Id_record asinteger.
Orders.Id_order is normal Integer.
Edit: Hm, when i remove the last column from orders and try to insertjust first 3 columns, everything works fine. So the problem is either in the declaration of random variable or in the was it is placed in SQO query.


queryString = "INSERT INTO [Orders] (Id_record, Id_title, Customer, Id_order) SELECT Id_record, Id_title, Customer,@.user FROM [Cart] WHERE Cart.Customer = @.user"


whats with the @.user in the select list?
waht are you trying to do there with it?

Troubles with INSERT INTO Statement...

hey all, im currently trying to do an insert statement, using textbox's and a variable. the only thing is its inserting txtTextBox.Text into the db instead of the value of that textbox...and i get this error when trying to insert my variable...

Exception Details: System.Data.SqlClient.SqlException: The name 'RndmNum' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Source Error:

Line 42: dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"
Line 43: dbCommand = New SqlCommand(dbQuery,dbConnection)
Line 44: dbCommand.ExecuteNonQuery()
Line 45: dbConnection.Close
Line 46:

this is my insert statement:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('txtName.Text', 'txtType.Text', 'txtLocation.Text', 'txtDesc.Text', RndmNum)"

thanks everyone,
JustinYou are sending txtName.Text as a string. Your dbQuery needs to look like this:

dbQuery = "INSERT INTO table (name, fault_type, fault_location, fault_description, fault_number) VALUES ('" & txtName.Text & "', '" & txtType.Text & "', '" & txtLocation.Text & "', '" & txtDesc.Text & "', " & RndmNum & ")"

Troubles with using a user control

Im using a Top Navigation Bar Web control in my application.
This Bar uses Images. Im trying to dynalically assign the relative URL
path as image path. That is, a particular image can have src attribute
as "../../images" or "images/" etc based on a public property of
control, callingDepth. This property is set in control delaration in
aspx page.
Im using src="http://pics.10026.com/?src=<% #fixRelPath("Images/med_upper_left1.gif") %> function
call in the ASPx pages.
The problem is that this function is not at all called all through page
load.
Any Clue on what i'm missing.
Thanks for Help.Expressions surrounded by <% # and %> are evaluated when the control
is DataBound. So you need to call the DataBind on the object, or a
container of that object.
For more info on DataBinding Expressions, see
http://www.dotnetjunkies.com/quicks...atabinding.aspx

Troubles with using a user control

Im using a Top Navigation Bar Web control in my application.
This Bar uses Images. Im trying to dynalically assign the relative URL
path as image path. That is, a particular image can have src attribute
as "../../images" or "images/" etc based on a public property of
control, callingDepth. This property is set in control delaration in
aspx page.
Im using src="http://pics.10026.com/?src=<% #fixRelPath("Images/med_upper_left1.gif") %> function
call in the ASPx pages.
The problem is that this function is not at all called all through page
load.
Any Clue on what i'm missing.
Thanks for Help.Expressions surrounded by <% # and %> are evaluated when the control
is DataBound. So you need to call the DataBind on the object, or a
container of that object.

For more info on DataBinding Expressions, see
http://www.dotnetjunkies.com/quicks...atabinding.aspx

Troubles working with dates

Hello people im new on this, but im going to try to explain my self as well as possible.

Im working with Vb.net code.

I'm having this trouble, i have a datagrid in wich i add a colum wich calculates the time that a "ticket" has been in the system. The calculation function is called when the datagrid is been loaded.

Im having troubles when im trying to use the system in another machine that doesnt have Vstudio.

the page give me this error, and i try to change the var type to string and it doesnt work either.

CAST FROM STRING "31/03/2006" TO TYPE "DATE" IS NOT VALID

this is the code im using

Private Sub calcula_duracion(ByVal estado_sol As String)
Dim i As Integer
Dim ahora, entonces As DateTime
Dim tempdate1, tempdate2, tempdate3 As DateTime
Dim dias, horas, minutos, segundos, result As String

For i = 0 To dsconsulta.Tables(0).Rows.Count - 1
If estado_sol = "Pendiente" Or estado_sol = "Eliminada" Then
ahora = Now
ElseIf estado_sol = "Aceptada" Then
ahora = dsconsulta.Tables(0).Rows(i).Item("fec_aceptacion")
ElseIf estado_sol = "Rechazada" Or estado_sol = "Solucionada" Then
ahora = dsconsulta.Tables(0).Rows(i).Item("fec_solucion")
ElseIf estado_sol = "Aceptada" Then
ahora = dsconsulta.Tables(0).Rows(i).Item("fec_aceptacion")
End If

lbltot.Text = dsconsulta.Tables(0).Rows.Count
entonces = dsconsulta.Tables(0).Rows(i).Item("fec_creacion")
tempdate1 = Format(entonces, "dd/MM/yyyy")
tempdate3 = Format(ahora, "dd/MM/yyyy")
tempdate2 = Format(ahora, "HH:mm")
If tempdate2 < CDate("8:00AM") Then
ahora = tempdate3 + " " + CDate("8:00AM")
ElseIf tempdate2 > CDate("6:00PM") Then
ahora = tempdate3 + " " + CDate("8:00AM")
ahora = ahora.AddDays(1)
End If

If DateDiff(DateInterval.Day, tempdate1, tempdate3) > 0 Then
dias = DateDiff(DateInterval.Day, tempdate1, tempdate3)
ahora = ahora.AddDays(-dias)
If DateDiff(DateInterval.Hour, entonces, ahora) < 0 Then
horas = DateDiff(DateInterval.Hour, ahora, entonces)
entonces = entonces.AddHours(-horas)
Else
horas = DateDiff(DateInterval.Hour, entonces, ahora)
ahora = ahora.AddHours(-horas)
End If
minutos = DateDiff(DateInterval.Minute, entonces, ahora)
ahora = ahora.AddMinutes(-minutos)
segundos = DateDiff(DateInterval.Second, entonces, ahora)
result = dias & "d " & horas & ":" & minutos & ":" & segundos
ElseIf DateDiff(DateInterval.Hour, entonces, ahora) > 0 Then
dias = "0"
horas = DateDiff(DateInterval.Hour, entonces, ahora)
ahora = ahora.AddHours(-horas)
minutos = DateDiff(DateInterval.Minute, entonces, ahora)
ahora = ahora.AddMinutes(-minutos)
segundos = DateDiff(DateInterval.Second, entonces, ahora)
result = dias & "d " & horas & ":" & minutos & ":" & segundos
ElseIf DateDiff(DateInterval.Minute, entonces, ahora) > 0 Then
dias = "0"
horas = "00"
minutos = DateDiff(DateInterval.Minute, entonces, ahora)
ahora = ahora.AddMinutes(-minutos)
segundos = DateDiff(DateInterval.Second, entonces, ahora)
result = dias & "d " & horas & ":" & minutos & ":" & segundos
ElseIf DateDiff(DateInterval.Second, entonces, ahora) > 0 Then
dias = "0"
horas = "00"
minutos = "00"
segundos = DateDiff(DateInterval.Second, entonces, ahora)
result = dias & "d " & horas & ":" & minutos & ":" & segundos
Else
result = "0d 00:00:00"
End If
dsconsulta.Tables(0).Rows(i).Item("Duracion") = result
Next
End Sub

tnx for ur time and help

I see that you are using a DD/MM/YYYY format for your date. Is it possible that the Regional settings of the new machine have a different date format?

i've check that out and in the deploy machine it works fine because i have there visual studio and the sql server, but when i move the application to a network where the server is in a different pc that the one who has the IIS it doesnt work, and the IIS pc has the same regional settings that the deploy machine??

tnx