Showing posts with label object. Show all posts
Showing posts with label object. Show all posts

Monday, March 26, 2012

NEWBIE: passing error to javascript alert

Hello,
is there a way call a javascript function directly from within asp
page?
Example, here is page load event in C#

protected void Page_Load(object sender, EventArgs e){

// create error
int Var0 = 0;
try {
int iVar1 = 8/Var0;
}

catch (Exception ex){

string sExMsg = ex.Message;

//javascript works fine with string constant
Response.Write("<script type='text/javascript'>alert('In Catch');</
script>");

//can write error to page no problem
Response.Write(sExMsg);

// would like a popup with error
Response.Write("<script language='javascript'>doAlert(" + sExMsg +
");</script>");
Response.Write("<script language='javascript'>function doAlert(sExMsg)
{alert(sExMsg);}</script>");

//write error to log since I can't pop-it-up
//StreamWriter sw = File.AppendText(Server.MapPath("~/error.log"));
//sw.WriteLine(sExMsg);
//sw.Close();

}

}

Any help for a newbie is appreciated

Gi<gijeet@.yahoo.comwrote in message
news:1193076186.658316.66870@.e9g2000prf.googlegrou ps.com...

Quote:

Originally Posted by

Any help for a newbie is appreciated


ClientScript.RegisterStartupScript(GetType(), "error", "alert('In Catch');",
true);

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
ClientScript.RegisterStartupScript(GetType(), "error", "alert('In Catch');",

Quote:

Originally Posted by

true);


Thanks but not sure how to use this. Where do I put this? class
level before page load event? within page load? do I need a
RegisterStartupScript for each alert I wish to use?

Gi
<gijeet@.yahoo.comwrote in message
news:1193079485.948563.150590@.i38g2000prf.googlegr oups.com...

Quote:

Originally Posted by

Quote:

Originally Posted by

>ClientScript.RegisterStartupScript(GetType(), "error", "alert('In
>Catch');",
>true);


>
Thanks but not sure how to use this. Where do I put this?


Wherever you like, so long as you don't Redirect from the page...

Basically, it will send down the JavaScript to run after the page had
loaded...

Quote:

Originally Posted by

do I need a RegisterStartupScript for each alert I wish to use?


Yes.

Incidentally, why are you actually doing this...?

--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Incidentally, why are you actually doing this...?
basically for debugging. I don't like response.writes and I'm trying
to learn javascript. but if you know of a better way to popup alerts,
let me know.
use the debugger to debug. alert debugging is asp classic style :)

"gijeet@.yahoo.com" wrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

Incidentally, why are you actually doing this...?


basically for debugging. I don't like response.writes and I'm trying
to learn javascript. but if you know of a better way to popup alerts,
let me know.
>
>
>
>
>
>


This can help you:
How to Pass Messages and Actions between Server and Client
http://usableasp.net/DeveloperPage...erAndClient.htm
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<gijeet@.yahoo.comwrote in message
news:1193076186.658316.66870@.e9g2000prf.googlegrou ps.com...

Quote:

Originally Posted by

Hello,
is there a way call a javascript function directly from within asp
page?
Example, here is page load event in C#
>
protected void Page_Load(object sender, EventArgs e){
>
// create error
int Var0 = 0;
try {
int iVar1 = 8/Var0;
}
>
catch (Exception ex){
>
string sExMsg = ex.Message;
>
>
//javascript works fine with string constant
Response.Write("<script type='text/javascript'>alert('In Catch');</
script>");
>
//can write error to page no problem
Response.Write(sExMsg);
>
// would like a popup with error
Response.Write("<script language='javascript'>doAlert(" + sExMsg +
");</script>");
Response.Write("<script language='javascript'>function doAlert(sExMsg)
{alert(sExMsg);}</script>");
>
//write error to log since I can't pop-it-up
//StreamWriter sw = File.AppendText(Server.MapPath("~/error.log"));
//sw.WriteLine(sExMsg);
//sw.Close();
>
}
>
}
>
Any help for a newbie is appreciated
>
Gi
>


"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldDinN@.mMvVpPsS.orgwrote in
message news:%23DynzGXFIHA.4880@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

This can help you:
How to Pass Messages and Actions between Server and Client
http://usableasp.net/DeveloperPage...erAndClient.htm


Not much use in this particular case, though, as the OP's requirements for
this were for debugging a la ASP Classic...

--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Saturday, March 24, 2012

Newbie: Questions about Cache object

Hi,
I'm trying to use Cache object for the first item. I've some questions
about that:
(1) Should Add, Remove and Insert method calls need to be synchronized ?
(2) Is it possible to add a cache dependency for cascading deletes i.e. if
cache key A is removed(based on time based expiration), so is key B which is
depnedent on it ?
Thanks in advance and regards
Navin1) If you want to be absolutely threadsafe using the Cache, use the Lock
keyword in your insert etc. methods.
2) Cascading deletes from the cache should be easy to implement using the
CacheItemRemovedCallback delegate , where in the callback target for item A
you would go ahead and remove Item B.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Navin Mishra" wrote:

> Hi,
> I'm trying to use Cache object for the first item. I've some questions
> about that:
> (1) Should Add, Remove and Insert method calls need to be synchronized ?
> (2) Is it possible to add a cache dependency for cascading deletes i.e. if
> cache key A is removed(based on time based expiration), so is key B which
is
> depnedent on it ?
> Thanks in advance and regards
> Navin
>
>
Thanks for quick response. For (2), is there any example ? In callback, how
I access the Cache object as it is part og request context ? Can a key item
dependency be used instead ?
Thanks again and regards
"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.com> wrote in message
news:CA9F6ABA-FF0B-40EA-BAB2-D2077B90670C@.microsoft.com...
> 1) If you want to be absolutely threadsafe using the Cache, use the Lock
> keyword in your insert etc. methods.
> 2) Cascading deletes from the cache should be easy to implement using the
> CacheItemRemovedCallback delegate , where in the callback target for item
A
> you would go ahead and remove Item B.
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
> "Navin Mishra" wrote:
>
if
which is

Newbie: Questions about Cache object

Hi,

I'm trying to use Cache object for the first item. I've some questions
about that:

(1) Should Add, Remove and Insert method calls need to be synchronized ?
(2) Is it possible to add a cache dependency for cascading deletes i.e. if
cache key A is removed(based on time based expiration), so is key B which is
depnedent on it ?

Thanks in advance and regards

Navin1) If you want to be absolutely threadsafe using the Cache, use the Lock
keyword in your insert etc. methods.

2) Cascading deletes from the cache should be easy to implement using the
CacheItemRemovedCallback delegate , where in the callback target for item A
you would go ahead and remove Item B.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

"Navin Mishra" wrote:

> Hi,
> I'm trying to use Cache object for the first item. I've some questions
> about that:
> (1) Should Add, Remove and Insert method calls need to be synchronized ?
> (2) Is it possible to add a cache dependency for cascading deletes i.e. if
> cache key A is removed(based on time based expiration), so is key B which is
> depnedent on it ?
> Thanks in advance and regards
> Navin
>
Thanks for quick response. For (2), is there any example ? In callback, how
I access the Cache object as it is part og request context ? Can a key item
dependency be used instead ?

Thanks again and regards

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.com> wrote in message
news:CA9F6ABA-FF0B-40EA-BAB2-D2077B90670C@.microsoft.com...
> 1) If you want to be absolutely threadsafe using the Cache, use the Lock
> keyword in your insert etc. methods.
> 2) Cascading deletes from the cache should be easy to implement using the
> CacheItemRemovedCallback delegate , where in the callback target for item
A
> you would go ahead and remove Item B.
> Peter
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
> "Navin Mishra" wrote:
> > Hi,
> > I'm trying to use Cache object for the first item. I've some questions
> > about that:
> > (1) Should Add, Remove and Insert method calls need to be synchronized ?
> > (2) Is it possible to add a cache dependency for cascading deletes i.e.
if
> > cache key A is removed(based on time based expiration), so is key B
which is
> > depnedent on it ?
> > Thanks in advance and regards
> > Navin

newbie: runtime error

Hey
asp.net 2.0
When I run the code below I get a runtime error ("Object reference not set
to an instance of an object. "):
Here is the code:
public static ICollection getInbox()
{
ArrayList al = new ArrayList();
ConnectionStringSettings css =
ConfigurationManager.ConnectionStrings["aspnet_DB"];
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
try
{
IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView row in INames)
{
al.Add(row["UserName"]);
}
}
catch (SqlException sqlException)
{
Debug.WriteLine(sqlException.Message.ToString());
}
sds.Dispose();
return al;
}
The error occur at this line in the code:
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
Just in case here is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDire
ctory|aspnetdb.mdf;User
Instance=true" />
</appSettings>
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>
Any ideas what I'm doing wrong here?
JeffJeff wrote:
> Hey
> asp.net 2.0
>
> When I run the code below I get a runtime error ("Object reference not set
> to an instance of an object. "):
> Here is the code:
> public static ICollection getInbox()
> {
> ArrayList al = new ArrayList();
> ConnectionStringSettings css =
> ConfigurationManager.ConnectionStrings["aspnet_DB"];
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> try
> {
> IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
> foreach (DataRowView row in INames)
> {
> al.Add(row["UserName"]);
> }
> }
> catch (SqlException sqlException)
> {
> Debug.WriteLine(sqlException.Message.ToString());
> }
> sds.Dispose();
> return al;
> }
> The error occur at this line in the code:
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> Just in case here is my web.config file:
> <?xml version="1.0"?>
> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
> <appSettings>
> <add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
> Security=True;AttachDBFilename=|DataDire
ctory|aspnetdb.mdf;User
> Instance=true" />
> </appSettings>
> <system.web>
> <roleManager enabled="true"/>
> <authentication mode="Forms"/>
> <compilation debug="true"/>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
> </system.web>
> </configuration>
> Any ideas what I'm doing wrong here?
> Jeff
Hi Jeff,
If looks like css is null. I'm guessing this is because there is no
<connectionStrings> in the web.config.
See http://www.devx.com/dotnet/Article/27562
David Hogue

newbie: runtime error

Hey

asp.net 2.0

When I run the code below I get a runtime error ("Object reference not set
to an instance of an object. "):

Here is the code:

public static ICollection getInbox()
{
ArrayList al = new ArrayList();
ConnectionStringSettings css =
ConfigurationManager.ConnectionStrings["aspnet_DB"];
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");
try
{
IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
foreach (DataRowView row in INames)
{
al.Add(row["UserName"]);
}
}
catch (SqlException sqlException)
{
Debug.WriteLine(sqlException.Message.ToString());
}
sds.Dispose();
return al;
}

The error occur at this line in the code:
SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
UserName from aspnet_Users");

Just in case here is my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
Instance=true" />
</appSettings>
<system.web>
<roleManager enabled="true"/>
<authentication mode="Forms"/>
<compilation debug="true"/>
<profile enabled="true">
<properties>
<add name="Picture" type="System.Byte[]" />
<add name="PictureType" type="string" />
</properties>
</profile>
</system.web>
</configuration>

Any ideas what I'm doing wrong here?

JeffJeff wrote:
> Hey
>
> asp.net 2.0
>
>
> When I run the code below I get a runtime error ("Object reference not set
> to an instance of an object. "):
>
> Here is the code:
>
> public static ICollection getInbox()
> {
> ArrayList al = new ArrayList();
> ConnectionStringSettings css =
> ConfigurationManager.ConnectionStrings["aspnet_DB"];
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
> try
> {
> IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);
> foreach (DataRowView row in INames)
> {
> al.Add(row["UserName"]);
> }
> }
> catch (SqlException sqlException)
> {
> Debug.WriteLine(sqlException.Message.ToString());
> }
> sds.Dispose();
> return al;
> }
>
> The error occur at this line in the code:
> SqlDataSource sds = new SqlDataSource(css.ConnectionString, "SELECT
> UserName from aspnet_Users");
>
> Just in case here is my web.config file:
> <?xml version="1.0"?>
> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <appSettings>
> <add key="aspnet_DB" value="Data Source=.\\SQLEXPRESS;Integrated
> Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
> Instance=true" />
> </appSettings>
> <system.web>
> <roleManager enabled="true"/>
> <authentication mode="Forms"/>
> <compilation debug="true"/>
> <profile enabled="true">
> <properties>
> <add name="Picture" type="System.Byte[]" />
> <add name="PictureType" type="string" />
> </properties>
> </profile>
> </system.web>
> </configuration>
>
> Any ideas what I'm doing wrong here?
>
> Jeff

Hi Jeff,

If looks like css is null. I'm guessing this is because there is no
<connectionStrings> in the web.config.

See http://www.devx.com/dotnet/Article/27562
--
David Hogue

Friday, March 16, 2012

News_view error

Why am I getting this error....Please help anyone

Robert

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 18: Protected Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)Line 19: Dim view As Data.DataRowView = CType(FormView1.DataItem, Data.DataRowView)Line 20: Dim o As Object = view.Item("staticURL")Line 21: If Not o Is Nothing AndAlso Not IsDBNull(o) ThenLine 22: 'We have a static URL, we need to redirect.


Source File:C:\Documents and Settings\Robert Rucker\My Documents\SwingSet Group, Inc\News_View.aspx Line:20

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] ASP.news_view_aspx.FormView1_DataBound(Object sender, EventArgs e) in C:\Documents and Settings\Robert Rucker\My Documents\SwingSet Group, Inc\News_View.aspx:20 System.Web.UI.WebControls.BaseDataBoundControl.OnDataBound(EventArgs e) +56 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +117 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +25 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +140 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68 System.Web.UI.WebControls.FormView.DataBind() +5 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +61 System.Web.UI.WebControls.FormView.EnsureDataBound() +138 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +67 System.Web.UI.Control.EnsureChildControls() +97 System.Web.UI.Control.PreRenderRecursiveInternal() +50 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5684

FormView1.DataItem is Nothing and therefore access of the Item Property on nothing is "Object reference not set to an instance of an object"

Dim o As Object = view.Item("staticURL")


What should I do then...don't understand...should I change it?