Showing posts with label heyasp. Show all posts
Showing posts with label heyasp. Show all posts

Thursday, March 29, 2012

newbie: Help, I have problems with this!

hey
asp.net 2.0
visual web developer 2005 express
I have a webpage which contains 1 Repeater control. Into this repeater
control I want to add several rows of data. My problem is that 1 of the data
is an array of bytes (it's a picture saved to the database as bytes) and I
want that picture to be displayed nicely in the repeater list...
Here is two approaches (approach A and approach B) I'm trying:
APPROACH A:
Use the scenario of 2 .aspx files, 1 .aspx (A) convert the bytes of array
into a picture and the other .aspx file (B) has a img tag pointing to the
first .aspx file (A)
But here I get problems with this line "img.Src =
"Thumnail.aspx?ImageID=1";", it looks like it expects a object... Somehow I
need to send over a parameter to this Thumbnail.aspx file about which image
to display... Lets say the resultset has many images, but this row shall
display one particular image
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
System.Web.UI.HtmlControls.HtmlImage img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.HtmlControls.HtmlImage)e.Item.FindControl("Photo");
img.Src = "Thumnail.aspx?ImageID=1";
}
}
<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="inbox.aspx.cs"
Inherits="webForms_Profile_inbox" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<asp:ObjectDataSource ID="odsInbox" runat="server"
SelectMethod="getInbox" TypeName="BusinessLogic.NetworkLogic">
</asp:ObjectDataSource>
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<img ID="Photo" src="http://pics.10026.com/?src=" />
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="sidebar" Runat="Server">
</asp:Content>
****************************************
************************
APPROACH B:
In this approach I tryed to replace the img tag with a Image control in the
repeater.
But the "System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);"
gives this error:
"Parameter is not valid."
Another thing is that I'm not sure this is a good approach because it uses
bmp.Save() and I'm afraid the server will run out of space if images get
saved on the server each time th page is displayed?
protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
//System.Web.UI.HtmlControls.HtmlImage img = null;
System.Web.UI.WebControls.Image img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.WebControls.Image)e.Item.FindControl("Photo");
byte[] data = Profile.Picture;
Int32 offset = 78;
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, offset, data.Length - offset);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath("sample.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();
img.ImageUrl = Server.MapPath("sample.jpeg");
}
//e.Item.DataItem.ToString();
}
Please help me with this one, I'm stucked in this problem...
Best Regards
Jeffhi Jeff
I think I've covered this in a previous thread, but anyways
on this page is an example of dynamically displaying binary image data
on a Web page. this uses a GridView but the logic's the same
http://authors.aspalliance.com/aspx...classbinarywri=
te.aspx
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
Reynald V. Nu=F1ez
http://authors.aspalliance.com/aspxtreme

newbie: Help, I have problems with this!

hey

asp.net 2.0
visual web developer 2005 express

I have a webpage which contains 1 Repeater control. Into this repeater
control I want to add several rows of data. My problem is that 1 of the data
is an array of bytes (it's a picture saved to the database as bytes) and I
want that picture to be displayed nicely in the repeater list...

Here is two approaches (approach A and approach B) I'm trying:

APPROACH A:
Use the scenario of 2 .aspx files, 1 .aspx (A) convert the bytes of array
into a picture and the other .aspx file (B) has a img tag pointing to the
first .aspx file (A)

But here I get problems with this line "img.Src =
"Thumnail.aspx?ImageID=1";", it looks like it expects a object... Somehow I
need to send over a parameter to this Thumbnail.aspx file about which image
to display... Lets say the resultset has many images, but this row shall
display one particular image

protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
System.Web.UI.HtmlControls.HtmlImage img = null;
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.HtmlControls.HtmlImage)e.Item.FindC ontrol("Photo");
img.Src = "Thumnail.aspx?ImageID=1";
}
}

<%@dotnet.itags.org. Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="inbox.aspx.cs"
Inherits="webForms_Profile_inbox" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="content" Runat="Server">
<asp:ObjectDataSource ID="odsInbox" runat="server"
SelectMethod="getInbox" TypeName="BusinessLogic.NetworkLogic">
</asp:ObjectDataSource>
<asp:Repeater ID="rptInbox" runat="server" DataSourceID="odsInbox"
OnItemDataBound="rptInbox_ItemDataBound">
<ItemTemplate>
<tr>
<td bgcolor="#CCFFCC">
<%# Eval("Name") %>
<img ID="Photo" src="http://pics.10026.com/?src=" />
</td>
</tr>
</ItemTemplate>

</asp:Repeater>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="sidebar" Runat="Server">
</asp:Content>

************************************************** **************
APPROACH B:

In this approach I tryed to replace the img tag with a Image control in the
repeater.
But the "System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);"
gives this error:
"Parameter is not valid."

Another thing is that I'm not sure this is a good approach because it uses
bmp.Save() and I'm afraid the server will run out of space if images get
saved on the server each time th page is displayed?

protected void rptInbox_ItemDataBound(object sender, RepeaterItemEventArgs
e)
{
//System.Web.UI.HtmlControls.HtmlImage img = null;
System.Web.UI.WebControls.Image img = null;

if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
ListItemType.AlternatingItem)) {
img =
(System.Web.UI.WebControls.Image)e.Item.FindContro l("Photo");
byte[] data = Profile.Picture;

Int32 offset = 78;
System.IO.MemoryStream mstream = new System.IO.MemoryStream();
mstream.Write(data, offset, data.Length - offset);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);

bmp.Save(Server.MapPath("sample.jpeg"),
System.Drawing.Imaging.ImageFormat.Jpeg);
mstream.Close();
img.ImageUrl = Server.MapPath("sample.jpeg");

}

//e.Item.DataItem.ToString();
}

Please help me with this one, I'm stucked in this problem...

Best Regards

Jeffhi Jeff

I think I've covered this in a previous thread, but anyways

on this page is an example of dynamically displaying binary image data
on a Web page. this uses a GridView but the logic's the same

http://authors.aspalliance.com/aspx...inarywrite.aspx
==============================
Reynald V. Nuez
http://authors.aspalliance.com/aspxtreme

newbie: I wonder if this is possible in asp.net 2.0

Hey

asp.net 2.0

As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.

But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...

Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>

Best RegardsThis article should help, and even fleshes out some of the sample code
provided by one of the MS people for it:

http://www.eggheadcafe.com/articles/20060731.asp
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jeff" wrote:

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.
>
But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...
>
Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>
>
Best Regards
>
>
>

newbie: image problems again

hey

asp.net 2.0

my problem is that on a webpage am I trying to dynamically display the image
a user has uploaded. But the webpage doesn't display the image. The browser
displays the standard image telling that image not found / broken image link
etc...

This is the code which saves the image to hard drive...:
fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" + Profile.UserName +
".jpeg"));

This is my code for displaying the image, it's in Page_Load event of
webpage:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" + Profile.UserName
+ ".jpeg");

The image exist in that folder

Any suggestions to this error?

JeffHi Jeff,

does this variable "Profile.UserName" really exist when you try to load the
image. Did you place an exception-handler around the loading-method?

Bye,

--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
my problem is that on a webpage am I trying to dynamically display the
image a user has uploaded. But the webpage doesn't display the image. The
browser displays the standard image telling that image not found / broken
image link etc...
>
This is the code which saves the image to hard drive...:
fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" + Profile.UserName
+ ".jpeg"));
>
This is my code for displaying the image, it's in Page_Load event of
webpage:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
Profile.UserName + ".jpeg");
>
The image exist in that folder
>
Any suggestions to this error?
>
Jeff
>


Hey

it looks like Profile.UserName is empty...
But this code doesn't work either:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");

I've also tryed this (setting it directly in the source, not the code
behind):
src='<%# Eval("~/Images/Fullsize/test.jpeg") %>'
Without any success...

any suggestions?

Jeff

"Matthias Pieroth" <piermat2001@.yahoo.dewrote in message
news:e8elch$p0k$02$1@.news.t-online.com...

Quote:

Originally Posted by

Hi Jeff,
>
does this variable "Profile.UserName" really exist when you try to load
the image. Did you place an exception-handler around the loading-method?
>
Bye,
>
--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers
>
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>hey
>>
>asp.net 2.0
>>
>my problem is that on a webpage am I trying to dynamically display the
>image a user has uploaded. But the webpage doesn't display the image. The
>browser displays the standard image telling that image not found / broken
>image link etc...
>>
>This is the code which saves the image to hard drive...:
>fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" + Profile.UserName
>+ ".jpeg"));
>>
>This is my code for displaying the image, it's in Page_Load event of
>webpage:
>imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
>Profile.UserName + ".jpeg");
>>
>The image exist in that folder
>>
>Any suggestions to this error?
>>
>Jeff
>>


>
>


Hi Jeff,

I am not sure what your problem is, but try one of these two things:
1. If you are using something like VS.Net, then simply try to locate a
test image using the properties grid of the Image Control. And then try
to run your page and see if it works.

2. try printing the path you are trying to assign to the ImageUrl
property by using a Response.Write() from the code behind.
So basically Response.Write(Server.MapPath("~\....

I have a feeling you are doing a bit too much in trying to assign a
path to the ImageUrl property.

- V

Jeff wrote:

Quote:

Originally Posted by

Hey
>
it looks like Profile.UserName is empty...
But this code doesn't work either:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");
>
I've also tryed this (setting it directly in the source, not the code
behind):
src='<%# Eval("~/Images/Fullsize/test.jpeg") %>'
Without any success...
>
any suggestions?
>
Jeff
>
>
"Matthias Pieroth" <piermat2001@.yahoo.dewrote in message
news:e8elch$p0k$02$1@.news.t-online.com...

Quote:

Originally Posted by

Hi Jeff,

does this variable "Profile.UserName" really exist when you try to load
the image. Did you place an exception-handler around the loading-method?

Bye,

--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
my problem is that on a webpage am I trying to dynamically display the
image a user has uploaded. But the webpage doesn't display the image. The
browser displays the standard image telling that image not found / broken
image link etc...
>
This is the code which saves the image to hard drive...:
fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" + Profile.UserName
+ ".jpeg"));
>
This is my code for displaying the image, it's in Page_Load event of
webpage:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
Profile.UserName + ".jpeg");
>
The image exist in that folder
>
Any suggestions to this error?
>
Jeff
>



The path is
C:\Documents and Settings\Jeff\My Documents\Visual Studio
2005\WebSites\BN\Images\Fullsize\test.jpeg

I've checked and path is correct, but the path contains spaces...

I'm not sure about it but maybe the browser need to know if this is a
picture ("image/thumb")?

Jeff

"V" <vaibhav.gadodia@.gmail.comwrote in message
news:1152051114.522719.324780@.a14g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

Hi Jeff,
>
I am not sure what your problem is, but try one of these two things:
1. If you are using something like VS.Net, then simply try to locate a
test image using the properties grid of the Image Control. And then try
to run your page and see if it works.
>
2. try printing the path you are trying to assign to the ImageUrl
property by using a Response.Write() from the code behind.
So basically Response.Write(Server.MapPath("~\....
>
I have a feeling you are doing a bit too much in trying to assign a
path to the ImageUrl property.
>
- V
>
Jeff wrote:

Quote:

Originally Posted by

>Hey
>>
>it looks like Profile.UserName is empty...
>But this code doesn't work either:
>imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");
>>
>I've also tryed this (setting it directly in the source, not the code
>behind):
>src='<%# Eval("~/Images/Fullsize/test.jpeg") %>'
>Without any success...
>>
>any suggestions?
>>
>Jeff
>>
>>
>"Matthias Pieroth" <piermat2001@.yahoo.dewrote in message
>news:e8elch$p0k$02$1@.news.t-online.com...

Quote:

Originally Posted by

Hi Jeff,
>
does this variable "Profile.UserName" really exist when you try to load
the image. Did you place an exception-handler around the
loading-method?
>
Bye,
>
--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers
>
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...
>hey
>>
>asp.net 2.0
>>
>my problem is that on a webpage am I trying to dynamically display the
>image a user has uploaded. But the webpage doesn't display the image.
>The
>browser displays the standard image telling that image not found /
>broken
>image link etc...
>>
>This is the code which saves the image to hard drive...:
>fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" +
>Profile.UserName
>+ ".jpeg"));
>>
>This is my code for displaying the image, it's in Page_Load event of
>webpage:
>imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
>Profile.UserName + ".jpeg");
>>
>The image exist in that folder
>>
>Any suggestions to this error?
>>
>Jeff
>>
>
>


>


It is possible that you may need to grant permission to the asp.net
process on that image directory. It might be a problem with the
security.

- V
Jeff wrote:

Quote:

Originally Posted by

The path is
C:\Documents and Settings\Jeff\My Documents\Visual Studio
2005\WebSites\BN\Images\Fullsize\test.jpeg
>
I've checked and path is correct, but the path contains spaces...
>
I'm not sure about it but maybe the browser need to know if this is a
picture ("image/thumb")?
>
>
>
>
Jeff
>
>
>
>
>
"V" <vaibhav.gadodia@.gmail.comwrote in message
news:1152051114.522719.324780@.a14g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

Hi Jeff,

I am not sure what your problem is, but try one of these two things:
1. If you are using something like VS.Net, then simply try to locate a
test image using the properties grid of the Image Control. And then try
to run your page and see if it works.

2. try printing the path you are trying to assign to the ImageUrl
property by using a Response.Write() from the code behind.
So basically Response.Write(Server.MapPath("~\....

I have a feeling you are doing a bit too much in trying to assign a
path to the ImageUrl property.

- V

Jeff wrote:

Quote:

Originally Posted by

Hey
>
it looks like Profile.UserName is empty...
But this code doesn't work either:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");
>
I've also tryed this (setting it directly in the source, not the code
behind):
src='<%# Eval("~/Images/Fullsize/test.jpeg") %>'
Without any success...
>
any suggestions?
>
Jeff
>
>
"Matthias Pieroth" <piermat2001@.yahoo.dewrote in message
news:e8elch$p0k$02$1@.news.t-online.com...
Hi Jeff,

does this variable "Profile.UserName" really exist when you try to load
the image. Did you place an exception-handler around the
loading-method?

Bye,

--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...
hey
>
asp.net 2.0
>
my problem is that on a webpage am I trying to dynamically display the
image a user has uploaded. But the webpage doesn't display the image.
The
browser displays the standard image telling that image not found /
broken
image link etc...
>
This is the code which saves the image to hard drive...:
fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" +
Profile.UserName
+ ".jpeg"));
>
This is my code for displaying the image, it's in Page_Load event of
webpage:
imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
Profile.UserName + ".jpeg");
>
The image exist in that folder
>
Any suggestions to this error?
>
Jeff
>



I replaced this line:

imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");

with this line

imgPicture.ImageUrl = "~/Images/Fullsize/test.jpeg";

And now it works

Thank you very much for helping me with this. The best thing with this
problem is that I've learned from it -maybe using Server.MapPath isn't
best all the times...

Best Regards!

Jeff

"V" <vaibhav.gadodia@.gmail.comwrote in message
news:1152057813.849114.308260@.m73g2000cwd.googlegr oups.com...

Quote:

Originally Posted by

It is possible that you may need to grant permission to the asp.net
process on that image directory. It might be a problem with the
security.
>
- V
Jeff wrote:

Quote:

Originally Posted by

>The path is
>C:\Documents and Settings\Jeff\My Documents\Visual Studio
>2005\WebSites\BN\Images\Fullsize\test.jpeg
>>
>I've checked and path is correct, but the path contains spaces...
>>
>I'm not sure about it but maybe the browser need to know if this is a
>picture ("image/thumb")?
>>
>>
>>
>>
>Jeff
>>
>>
>>
>>
>>
>"V" <vaibhav.gadodia@.gmail.comwrote in message
>news:1152051114.522719.324780@.a14g2000cwb.googlegr oups.com...

Quote:

Originally Posted by

Hi Jeff,
>
I am not sure what your problem is, but try one of these two things:
1. If you are using something like VS.Net, then simply try to locate a
test image using the properties grid of the Image Control. And then try
to run your page and see if it works.
>
2. try printing the path you are trying to assign to the ImageUrl
property by using a Response.Write() from the code behind.
So basically Response.Write(Server.MapPath("~\....
>
I have a feeling you are doing a bit too much in trying to assign a
path to the ImageUrl property.
>
- V
>
Jeff wrote:
>Hey
>>
>it looks like Profile.UserName is empty...
>But this code doesn't work either:
>imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/test.jpeg");
>>
>I've also tryed this (setting it directly in the source, not the code
>behind):
>src='<%# Eval("~/Images/Fullsize/test.jpeg") %>'
>Without any success...
>>
>any suggestions?
>>
>Jeff
>>
>>
>"Matthias Pieroth" <piermat2001@.yahoo.dewrote in message
>news:e8elch$p0k$02$1@.news.t-online.com...
Hi Jeff,
>
does this variable "Profile.UserName" really exist when you try to
load
the image. Did you place an exception-handler around the
loading-method?
>
Bye,
>
--
Matthias Pieroth
www.codegod.de - The Page for .NET-developers
>
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23qlAzL5nGHA.1808@.TK2MSFTNGP02.phx.gbl...
>hey
>>
>asp.net 2.0
>>
>my problem is that on a webpage am I trying to dynamically display
>the
>image a user has uploaded. But the webpage doesn't display the
>image.
>The
>browser displays the standard image telling that image not found /
>broken
>image link etc...
>>
>This is the code which saves the image to hard drive...:
>fullsizeImage.Save(Server.MapPath("~/Images/Fullsize/" +
>Profile.UserName
>+ ".jpeg"));
>>
>This is my code for displaying the image, it's in Page_Load event
>of
>webpage:
>imgPicture.ImageUrl = Server.MapPath("~/Images/Fullsize/" +
>Profile.UserName + ".jpeg");
>>
>The image exist in that folder
>>
>Any suggestions to this error?
>>
>Jeff
>>
>
>
>


>

newbie: I wonder if this is possible in asp.net 2.0

Hey
asp.net 2.0
As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.
But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...
Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>
Best RegardsThis article should help, and even fleshes out some of the sample code
provided by one of the MS people for it:
http://www.eggheadcafe.com/articles/20060731.asp
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jeff" wrote:

> Hey
> asp.net 2.0
> As far as I know it's possible to search the users registrered at a asp.ne
t
> 2.0 web portal using either username or e-mail.
> But what about the custom profile properties which can be configured in
> web.config? Can they be searched too? I guess it can by using foreach loop
> and test the contents on every user object.. but I thought maybe there was
a
> cleaner and faster way to do it...
> Lets say for example these are custom profile settings in web.config. any
> suggestion on how to search them? Lets say the search should return all
> users containing the phrase "Lets" in lastname? or all users of a specific
> gender?
> <profile enabled="true">
> <properties>
> <add name="FirstName" type="string"/>
> <add name="LastName" type="string"/>
> <add name="Gender" type="string"/>
> <add name="BirthDate" type="DateTime"/>
> </properties>
> </profile>
> Best Regards
>
>

newbie: Instance failure!

Hey

asp.net 2.0

When I run the code below I get the runtime error "Instance Failure"

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:
"IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);"

Just in case, here is a copy of my web.config file:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
</appSettings>
<connectionStrings>
<add name="aspnet_DB" connectionString="Data
Source=.\\SQLEXPRESS;Integrated
Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
Instance=true" />
</connectionStrings>
<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>

My gut feeling tells me it might be caused by the db connectionsting, but
I'm not sure... I'm trying to connect to the express database within the
project!

Any suggestions to what I should do to fix this?

Jeff"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:ueLDl0PnGHA.1444@.TK2MSFTNGP02.phx.gbl...
> Hey
>
> asp.net 2.0
>
> When I run the code below I get the runtime error "Instance Failure"
>
> 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:
> "IEnumerable INames = sds.Select(DataSourceSelectArguments.Empty);"
>
> Just in case, here is a copy of my web.config file:
> <?xml version="1.0"?>
> <configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <appSettings>
> </appSettings>
> <connectionStrings>
> <add name="aspnet_DB" connectionString="Data
> Source=.\\SQLEXPRESS;Integrated
> Security=True;AttachDBFilename=|DataDirectory|aspn etdb.mdf;User
> Instance=true" />
> </connectionStrings>
> <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>
>
> My gut feeling tells me it might be caused by the db connectionsting, but
> I'm not sure... I'm trying to connect to the express database within the
> project!
>
> Any suggestions to what I should do to fix this?
>
> Jeff
>

newbie: ItemDataBound and XPath

hey

asp.net 2.0

I have a DataList which has a XmlDataSource as its data source.

This code crash because I use XPath in the ItemDataBound event:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs
e)
{
Label label = (Label)e.Item.FindControl("lblTitle");
label.Text = XPath("title").ToString();
label = (Label)e.Item.FindControl("lblStory");
label.Text = XPath("description").ToString();
}

Any suggestion how this should be done in a ItemDataBound event?

Jeff"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:eCAL$KttGHA.2160@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
I have a DataList which has a XmlDataSource as its data source.
>
This code crash because I use XPath in the ItemDataBound event:
protected void DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{
Label label = (Label)e.Item.FindControl("lblTitle");
label.Text = XPath("title").ToString();
label = (Label)e.Item.FindControl("lblStory");
label.Text = XPath("description").ToString();
}
>
Any suggestion how this should be done in a ItemDataBound event?
>
Jeff
>


Jeff look at this sample here at:-
http://www.msdner.com/forum/thread467894.html
Patrick

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:eCAL$KttGHA.2160@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
I have a DataList which has a XmlDataSource as its data source.
>
This code crash because I use XPath in the ItemDataBound event:
protected void DataList1_ItemDataBound(object sender,
DataListItemEventArgs e)
{
Label label = (Label)e.Item.FindControl("lblTitle");
label.Text = XPath("title").ToString();
label = (Label)e.Item.FindControl("lblStory");
label.Text = XPath("description").ToString();
}
>
Any suggestion how this should be done in a ItemDataBound event?
>
Jeff
>

newbie: load image from db + Repeater

hey
asp.net 2.0
With the help of a Repeater control on my webpage I want to dynamically
generate a list which contains both images and text field. This data are
stored in the aspnetdb.mdf database.
I know it's possible to have the imag tag to point to a .aspx file (<img
src="getImage.aspx" /> )
This is the Page_Load event I have in my getImage.aspx file
protected void Page_Load(object sender, EventArgs e)
{
if (Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}
}
The getImage.aspx file above is used another place in my project. My PROBLEM
is that I don't know how to adapt (make another version of getImage.aspx
which suit the repeater) this getImage.aspx file into the Repeater control.
More specific: in the Page_Load event of getImage.aspx you see that I'm
setting some properties of the Response object with some values of the
Profile object. But in the new getImage.aspx file (created specially for the
Repeater control) I must for each line in the Repeater control pass over the
correct ID to the Page_Load event so the getImage.aspx file knows what image
to load!
In other words how can I tell the Page_Load event what image to show. I
think about using a paramter. But my problem is that I don't know how to add
such a parameter. Maybe it could be passed in the EventArgs argument.. I'm
not sure...
Instead of sending the picture ID I could send over the bytes representing
the image. But even that, I (As Far As I Know) still have to send a paramter
to the Page_Load event
Any ideas how I should pass over such a parameter?
Jeffhello Jeff
you can track the id's and do something like getImage ( id ) in the
ItemDataBound event.
on this page is a similar example, though uses a GridView instead, but
logically it's the same
http://authors.aspalliance.com/aspx...te.aspx

Monday, March 26, 2012

newbie: load image from db + Repeater

hey

asp.net 2.0

With the help of a Repeater control on my webpage I want to dynamically
generate a list which contains both images and text field. This data are
stored in the aspnetdb.mdf database.

I know it's possible to have the imag tag to point to a .aspx file (<img
src="getImage.aspx" />)

This is the Page_Load event I have in my getImage.aspx file
protected void Page_Load(object sender, EventArgs e)
{
if (Profile.Picture != null)
{
Response.ContentType = Profile.PictureType;
Response.BinaryWrite(Profile.Picture);
Response.End();
}
}

The getImage.aspx file above is used another place in my project. My PROBLEM
is that I don't know how to adapt (make another version of getImage.aspx
which suit the repeater) this getImage.aspx file into the Repeater control.
More specific: in the Page_Load event of getImage.aspx you see that I'm
setting some properties of the Response object with some values of the
Profile object. But in the new getImage.aspx file (created specially for the
Repeater control) I must for each line in the Repeater control pass over the
correct ID to the Page_Load event so the getImage.aspx file knows what image
to load!

In other words how can I tell the Page_Load event what image to show. I
think about using a paramter. But my problem is that I don't know how to add
such a parameter. Maybe it could be passed in the EventArgs argument.. I'm
not sure...

Instead of sending the picture ID I could send over the bytes representing
the image. But even that, I (As Far As I Know) still have to send a paramter
to the Page_Load event

Any ideas how I should pass over such a parameter?

Jeffhello Jeff

you can track the id's and do something like getImage ( id ) in the
ItemDataBound event.

on this page is a similar example, though uses a GridView instead, but
logically it's the same

http://authors.aspalliance.com/aspx...inaryWrite.aspx

newbie: menu / sitemap problem

Hey

asp.net 2.0

My webportal consist of 2 menus (a header menu which goes horizontally
across the top of the page. And a sidebar menu to the left. The menuitmes
shown in the sidebar menu is dependent on what menuitem is selected in the
main menu.)

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description="" >
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
<siteMapNode url="~/pageB.aspx" title="ItemB" description="" />
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>

When the "Network" menuitem in my main menu is clicked the sidebar menu
displays these menu items "Search", "ItemA", "ItemB". So now if the user
clicks on the "Search" menuitem in the sidebar menu, the sidebar menu
continue to display the same menuitems ("Search", "ItemA", "ItemB").

Problem:
In the "Search.aspx" file there is a button (btnSearch), which when clicked
executes this code:
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("~/Result.aspx?name=" + txtFullname.Text);
}

So when the result.aspx page is displayed. the sidebar menu is empty. I
think this must be related to using "Response.Redirect" to open the
"result.aspx" page. When the "result.aspx" page is opened. I want the
sidebar menu to continue to display the same menuitems ("Search", "ItemA",
"ItemB") as it did in the "search.aspx" page.

Any suggestions?

JeffI don't think that your problem has anything to do with the redirect.

You could try separating the
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
<siteMapNode url="~/pageB.aspx" title="ItemB" description="" />

into a separate sitemap file and creating a new SitemapProvider that the
side menu would bind to (you can specify the sitemap file in the sitempa
definintion)

or
(and I haven't tried this myself)
The sitemap schema allows you to specify a provider or sitemap file on a
sitempa node. So what you might be able to do is:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="~/Result.aspx" title="Result" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>

Note that when the XMLSitemapProvider tries to find a node it search the
node list by url, including the querystring. This could cause you problems,
you may need to strore the name query string parameter in session.

Hope this helps,

Garth

"Jeff" wrote:

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
My webportal consist of 2 menus (a header menu which goes horizontally
across the top of the page. And a sidebar menu to the left. The menuitmes
shown in the sidebar menu is dependent on what menuitem is selected in the
main menu.)
>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description="" >
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
<siteMapNode url="~/pageB.aspx" title="ItemB" description="" />
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>
>
When the "Network" menuitem in my main menu is clicked the sidebar menu
displays these menu items "Search", "ItemA", "ItemB". So now if the user
clicks on the "Search" menuitem in the sidebar menu, the sidebar menu
continue to display the same menuitems ("Search", "ItemA", "ItemB").
>
Problem:
In the "Search.aspx" file there is a button (btnSearch), which when clicked
executes this code:
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("~/Result.aspx?name=" + txtFullname.Text);
}
>
So when the result.aspx page is displayed. the sidebar menu is empty. I
think this must be related to using "Response.Redirect" to open the
"result.aspx" page. When the "result.aspx" page is opened. I want the
sidebar menu to continue to display the same menuitems ("Search", "ItemA",
"ItemB") as it did in the "search.aspx" page.
>
Any suggestions?
>
Jeff
>
>
>


Thanks for replying so soon to my thread!

I don't quite understand (rememeber I'm a newbie) how this could solve my
problem. I mean I don't understand how putting the sidebar menuitems in it's
own sitemap file / provider could fix it... It works today with 1 sitemap
file and 1 provider. The problem is with the result.aspx page which is not
accessible through the menu. (currently not added to the sitemap, but could
add it if that is recommended)

Maybe I should have added that I based the configuration of my menus on
article: http://msdn2.microsoft.com/en-us/library/16yk5dby.aspx which shows
how to combine 2 menus, one menu dependent on the other menu.

When the user clicks on the "Network" menuitem in the main menu, the sidebar
menu displays "Search", "ItemA", "ItemB" menuitems. It continue to display
these menuitems when the user clicks on the "Search" menuitem in the sidebar
menu. It's only when the result.aspx file is displayed that the sidebar menu
shows no menuitems...

Any thoughts?

Jeff

"GarthS" <GarthS@.discussions.microsoft.comwrote in message
news:AF1F5849-1230-4B46-B58F-49547A835A99@.microsoft.com...

Quote:

Originally Posted by

>I don't think that your problem has anything to do with the redirect.
>
You could try separating the
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
<siteMapNode url="~/pageB.aspx" title="ItemB" description="" />
>
into a separate sitemap file and creating a new SitemapProvider that the
side menu would bind to (you can specify the sitemap file in the sitempa
definintion)
>
or
(and I haven't tried this myself)
The sitemap schema allows you to specify a provider or sitemap file on a
sitempa node. So what you might be able to do is:
>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="~/Result.aspx" title="Result" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>
>
Note that when the XMLSitemapProvider tries to find a node it search the
node list by url, including the querystring. This could cause you
problems,
you may need to strore the name query string parameter in session.
>
Hope this helps,
>
Garth
>
"Jeff" wrote:
>

Quote:

Originally Posted by

>Hey
>>
>asp.net 2.0
>>
>My webportal consist of 2 menus (a header menu which goes horizontally
>across the top of the page. And a sidebar menu to the left. The menuitmes
>shown in the sidebar menu is dependent on what menuitem is selected in
>the
>main menu.)
>>
><?xml version="1.0" encoding="utf-8" ?>
><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
> <siteMapNode url="Default.aspx" title="Home" description="">
> <siteMapNode url="~/Network.aspx" title="Network" description=""

Quote:

Originally Posted by

> >


> <siteMapNode url="~/Search.aspx" title="Search" description=""
>/>
> <siteMapNode url="~/pageA.aspx" title="ItemA" description=""
>/>
> <siteMapNode url="~/pageB.aspx" title="ItemB" description=""
>/>
> </siteMapNode>
> <siteMapNode url="" title="Forum" description="" />
> </siteMapNode>
></siteMap>
>>
>When the "Network" menuitem in my main menu is clicked the sidebar menu
>displays these menu items "Search", "ItemA", "ItemB". So now if the user
>clicks on the "Search" menuitem in the sidebar menu, the sidebar menu
>continue to display the same menuitems ("Search", "ItemA", "ItemB").
>>
>Problem:
>In the "Search.aspx" file there is a button (btnSearch), which when
>clicked
>executes this code:
>protected void btnSearch_Click(object sender, EventArgs e)
>{
> Response.Redirect("~/Result.aspx?name=" + txtFullname.Text);
>}
>>
>So when the result.aspx page is displayed. the sidebar menu is empty. I
>think this must be related to using "Response.Redirect" to open the
>"result.aspx" page. When the "result.aspx" page is opened. I want the
>sidebar menu to continue to display the same menuitems ("Search",
>"ItemA",
>"ItemB") as it did in the "search.aspx" page.
>>
>Any suggestions?
>>
>Jeff
>>
>>
>>


"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:OEdOwrEsGHA.5072@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Thanks for replying so soon to my thread!
>
I don't quite understand (rememeber I'm a newbie) how this could solve my
problem. I mean I don't understand how putting the sidebar menuitems in
it's own sitemap file / provider could fix it... It works today with 1
sitemap file and 1 provider. The problem is with the result.aspx page
which is not accessible through the menu. (currently not added to the
sitemap, but could add it if that is recommended)
>
Maybe I should have added that I based the configuration of my menus on
article: http://msdn2.microsoft.com/en-us/library/16yk5dby.aspx which
shows how to combine 2 menus, one menu dependent on the other menu.
>
When the user clicks on the "Network" menuitem in the main menu, the
sidebar menu displays "Search", "ItemA", "ItemB" menuitems. It continue to
display these menuitems when the user clicks on the "Search" menuitem in
the sidebar menu. It's only when the result.aspx file is displayed that
the sidebar menu shows no menuitems...
>
Any thoughts?
>
Jeff
>
>
"GarthS" <GarthS@.discussions.microsoft.comwrote in message
news:AF1F5849-1230-4B46-B58F-49547A835A99@.microsoft.com...

Quote:

Originally Posted by

>>I don't think that your problem has anything to do with the redirect.
>>
>You could try separating the
><siteMapNode url="~/Search.aspx" title="Search" description="" />
><siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
><siteMapNode url="~/pageB.aspx" title="ItemB" description="" />
>>
>into a separate sitemap file and creating a new SitemapProvider that the
>side menu would bind to (you can specify the sitemap file in the sitempa
>definintion)
>>
>or
>(and I haven't tried this myself)
>The sitemap schema allows you to specify a provider or sitemap file on a
>sitempa node. So what you might be able to do is:
>>
><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
> <siteMapNode url="Default.aspx" title="Home" description="">
> <siteMapNode url="~/Network.aspx" title="Network" description=""
>siteMapFile="newFile.sitemap">
> </siteMapNode>
> <siteMapNode url="~/Result.aspx" title="Result" description=""
>siteMapFile="newFile.sitemap">
> </siteMapNode>
> <siteMapNode url="" title="Forum" description="" />
> </siteMapNode>
></siteMap>
>>
>Note that when the XMLSitemapProvider tries to find a node it search the
>node list by url, including the querystring. This could cause you
>problems,
>you may need to strore the name query string parameter in session.
>>
>Hope this helps,
>>
>Garth
>>
>"Jeff" wrote:
>>

Quote:

Originally Posted by

>>Hey
>>>
>>asp.net 2.0
>>>
>>My webportal consist of 2 menus (a header menu which goes horizontally
>>across the top of the page. And a sidebar menu to the left. The
>>menuitmes
>>shown in the sidebar menu is dependent on what menuitem is selected in
>>the
>>main menu.)
>>>
>><?xml version="1.0" encoding="utf-8" ?>
>><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
>> <siteMapNode url="Default.aspx" title="Home" description="">
>> <siteMapNode url="~/Network.aspx" title="Network"
>>description="" >
>> <siteMapNode url="~/Search.aspx" title="Search"
>>description="" />
>> <siteMapNode url="~/pageA.aspx" title="ItemA" description=""
>>/>
>> <siteMapNode url="~/pageB.aspx" title="ItemB" description=""
>>/>
>> </siteMapNode>
>> <siteMapNode url="" title="Forum" description="" />
>> </siteMapNode>
>></siteMap>
>>>
>>When the "Network" menuitem in my main menu is clicked the sidebar menu
>>displays these menu items "Search", "ItemA", "ItemB". So now if the user
>>clicks on the "Search" menuitem in the sidebar menu, the sidebar menu
>>continue to display the same menuitems ("Search", "ItemA", "ItemB").
>>>
>>Problem:
>>In the "Search.aspx" file there is a button (btnSearch), which when
>>clicked
>>executes this code:
>>protected void btnSearch_Click(object sender, EventArgs e)
>>{
>> Response.Redirect("~/Result.aspx?name=" + txtFullname.Text);
>>}
>>>
>>So when the result.aspx page is displayed. the sidebar menu is empty. I
>>think this must be related to using "Response.Redirect" to open the
>>"result.aspx" page. When the "result.aspx" page is opened. I want the
>>sidebar menu to continue to display the same menuitems ("Search",
>>"ItemA",
>>"ItemB") as it did in the "search.aspx" page.
>>>
>>Any suggestions?
>>>
>>Jeff
>>>
>>>
>>>


>
>


Jeff,
Moving the side menu items into another sitemap wont fix your problem
directly but it will allow you to reuse those items as a submenu to the
results page if you add it as a sitemap node (the Network and Results nodes
point to the same file so if you change the sidew menu items its reflected in
both).

Can you post your settings for each of your SiteMapDataSources? (primarily
ShowStartingNode, StartFromCurrentNode, StartingNodeOffset and
StartingNodeUrl).

I'm thinking that adding the results page ot the sitemap will be problematic
due to the query string component added when you redirect. What you may be
able to do is set the side menu sitemap datasource StartingNodeUrl property
(if your using it as per the walkthrough) in the Page_Load of the
results.aspx.

Garth

"Jeff" wrote:

Quote:

Originally Posted by

Thanks for replying so soon to my thread!
>
I don't quite understand (rememeber I'm a newbie) how this could solve my
problem. I mean I don't understand how putting the sidebar menuitems in it's
own sitemap file / provider could fix it... It works today with 1 sitemap
file and 1 provider. The problem is with the result.aspx page which is not
accessible through the menu. (currently not added to the sitemap, but could
add it if that is recommended)
>
Maybe I should have added that I based the configuration of my menus on
article: http://msdn2.microsoft.com/en-us/library/16yk5dby.aspx which shows
how to combine 2 menus, one menu dependent on the other menu.
>
When the user clicks on the "Network" menuitem in the main menu, the sidebar
menu displays "Search", "ItemA", "ItemB" menuitems. It continue to display
these menuitems when the user clicks on the "Search" menuitem in the sidebar
menu. It's only when the result.aspx file is displayed that the sidebar menu
shows no menuitems...
>
Any thoughts?
>
Jeff
>
>
"GarthS" <GarthS@.discussions.microsoft.comwrote in message
news:AF1F5849-1230-4B46-B58F-49547A835A99@.microsoft.com...

Quote:

Originally Posted by

I don't think that your problem has anything to do with the redirect.

You could try separating the
<siteMapNode url="~/Search.aspx" title="Search" description="" />
<siteMapNode url="~/pageA.aspx" title="ItemA" description="" />
<siteMapNode url="~/pageB.aspx" title="ItemB" description="" />

into a separate sitemap file and creating a new SitemapProvider that the
side menu would bind to (you can specify the sitemap file in the sitempa
definintion)

or
(and I haven't tried this myself)
The sitemap schema allows you to specify a provider or sitemap file on a
sitempa node. So what you might be able to do is:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="~/Result.aspx" title="Result" description=""
siteMapFile="newFile.sitemap">
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>

Note that when the XMLSitemapProvider tries to find a node it search the
node list by url, including the querystring. This could cause you
problems,
you may need to strore the name query string parameter in session.

Hope this helps,

Garth

"Jeff" wrote:

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
My webportal consist of 2 menus (a header menu which goes horizontally
across the top of the page. And a sidebar menu to the left. The menuitmes
shown in the sidebar menu is dependent on what menuitem is selected in
the
main menu.)
>
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
<siteMapNode url="Default.aspx" title="Home" description="">
<siteMapNode url="~/Network.aspx" title="Network" description=""
>
<siteMapNode url="~/Search.aspx" title="Search" description=""
/>
<siteMapNode url="~/pageA.aspx" title="ItemA" description=""
/>
<siteMapNode url="~/pageB.aspx" title="ItemB" description=""
/>
</siteMapNode>
<siteMapNode url="" title="Forum" description="" />
</siteMapNode>
</siteMap>
>
When the "Network" menuitem in my main menu is clicked the sidebar menu
displays these menu items "Search", "ItemA", "ItemB". So now if the user
clicks on the "Search" menuitem in the sidebar menu, the sidebar menu
continue to display the same menuitems ("Search", "ItemA", "ItemB").
>
Problem:
In the "Search.aspx" file there is a button (btnSearch), which when
clicked
executes this code:
protected void btnSearch_Click(object sender, EventArgs e)
{
Response.Redirect("~/Result.aspx?name=" + txtFullname.Text);
}
>
So when the result.aspx page is displayed. the sidebar menu is empty. I
think this must be related to using "Response.Redirect" to open the
"result.aspx" page. When the "result.aspx" page is opened. I want the
sidebar menu to continue to display the same menuitems ("Search",
"ItemA",
"ItemB") as it did in the "search.aspx" page.
>
Any suggestions?
>
Jeff
>
>
>


>
>
>

newbie: My code crashes

hey

asp.net 2.0

I'm trying to make a webpage that shows a list of pictures. When the user
clicks on a picture, the user is redirected to another page in my website.
The links are generated at runtime

My code crashes during runtime because of a variable in the ItemDataBound
event is null. Below I show my problem code and maybe some of you could give
me a suggestion to what should do to fix this...

<td rowspan="2"><a id="LinkToProfile" href="http://links.10026.com/?link="><asp:Image ID="MemberPhoto"
runat="server" ImageAlign="Left" /></a></td>

System.Web.UI.HtmlControls.HtmlAnchor link = null;
link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");
link.HRef = "../test.aspx?id=" + subscriber.UserName;

My code crashes because the variable "link" is null after this line "link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");"

Any suggestions that may solve this problem are very welcome :-)

JeffThat is because there is no control with the id "LinkToProfile". You
have to put runat="server" in the tag to make it a server control.

Jeff wrote:

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
I'm trying to make a webpage that shows a list of pictures. When the user
clicks on a picture, the user is redirected to another page in my website.
The links are generated at runtime
>
My code crashes during runtime because of a variable in the ItemDataBound
event is null. Below I show my problem code and maybe some of you could give
me a suggestion to what should do to fix this...
>
>
<td rowspan="2"><a id="LinkToProfile" href="http://links.10026.com/?link="><asp:Image ID="MemberPhoto"
runat="server" ImageAlign="Left" /></a></td>
>
System.Web.UI.HtmlControls.HtmlAnchor link = null;
link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");
link.HRef = "../test.aspx?id=" + subscriber.UserName;
>
My code crashes because the variable "link" is null after this line "link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");"
>
Any suggestions that may solve this problem are very welcome :-)
>
Jeff
>
>


Why not dynamically generated ImageButtons and set the image and postbackUrl
on the control to do what you desire. You can then have complete control
without a lot of code and use a control that is designed to do both of the
tasks you desire.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23Pma5OmoGHA.5104@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
I'm trying to make a webpage that shows a list of pictures. When the user
clicks on a picture, the user is redirected to another page in my website.
The links are generated at runtime
>
My code crashes during runtime because of a variable in the ItemDataBound
event is null. Below I show my problem code and maybe some of you could
give me a suggestion to what should do to fix this...
>
>
<td rowspan="2"><a id="LinkToProfile" href="http://links.10026.com/?link="><asp:Image ID="MemberPhoto"
runat="server" ImageAlign="Left" /></a></td>
>
System.Web.UI.HtmlControls.HtmlAnchor link = null;
link =
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");
link.HRef = "../test.aspx?id=" + subscriber.UserName;
>
My code crashes because the variable "link" is null after this line "link
=
(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");"
>
Any suggestions that may solve this problem are very welcome :-)
>
Jeff
>
>


Thanks for the advice, I will try it.

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamMwrote in
message news:Oax8NlqoGHA.4960@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

Why not dynamically generated ImageButtons and set the image and
postbackUrl on the control to do what you desire. You can then have
complete control without a lot of code and use a control that is designed
to do both of the tasks you desire.
>
--
Gregory A. Beamer
>
*************************************************
Think Outside the Box!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23Pma5OmoGHA.5104@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

>hey
>>
>asp.net 2.0
>>
>I'm trying to make a webpage that shows a list of pictures. When the user
>clicks on a picture, the user is redirected to another page in my
>website. The links are generated at runtime
>>
>My code crashes during runtime because of a variable in the ItemDataBound
>event is null. Below I show my problem code and maybe some of you could
>give me a suggestion to what should do to fix this...
>>
>>
><td rowspan="2"><a id="LinkToProfile" href="http://links.10026.com/?link="><asp:Image ID="MemberPhoto"
>runat="server" ImageAlign="Left" /></a></td>
>>
>System.Web.UI.HtmlControls.HtmlAnchor link = null;
>link =
>(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");
>link.HRef = "../test.aspx?id=" + subscriber.UserName;
>>
>My code crashes because the variable "link" is null after this line "link
>=
>(System.Web.UI.HtmlControls.HtmlAnchor)e.Item.Find Control("LinkToProfile");"
>>
>Any suggestions that may solve this problem are very welcome :-)
>>
>Jeff
>>
>>


>
>

newbie: my code crashe, NULL value

Hey
asp.net 2.0
My code below crashes at the "return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;"
line. In the debugging window I see that when this exception occur, the
"return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;" has a NULL value...
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@dotnet.itags.org.receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@dotnet.itags.org.sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@dotnet.itags.org.title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@dotnet.itags.org.body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@dotnet.itags.org.return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;
}
}
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@dotnet.itags.org.sender nvarchar(256),
@dotnet.itags.org.receiver nvarchar(256),
@dotnet.itags.org.title nvarchar(100),
@dotnet.itags.org.body nvarchar(2000),
@dotnet.itags.org.return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@dotnet.itags.org.sender, @dotnet.itags.org.receiver, @dotnet.itags.org.title, @dotnet.itags.org.body);
set @dotnet.itags.org.return = 1;
select 1;
END
Please, what am I doing wrong here?
JeffIf altering the signature of your SP, you may consider the following option
that should work.
SqlParameter returnValue = sqlCommand.Parameters.Add("@.YourSPReturnValue",
SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
return (Int32)returnValue.Value;
Declaring an explicit return value is in my opinion preferrable, as it is
more clear about your intent and somewhat cleans up the SP declaration.
Tor Bdshaug
tor.badshaug(AT)bekk.no
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...
> Hey
> asp.net 2.0
> My code below crashes at the "return
> (int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
> that when this exception occur, the "return
> (int)cmd.Parameters["@.return"].Value;" has a NULL value...
> public override int SendMessage(MessageDetails message)
> {
> using (SqlConnection cn = new SqlConnection(this.ConnectionString))
> {
> SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
> message.Title;
> cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
> message.Body;
> cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
> ParameterDirection.Output;
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> return (int)cmd.Parameters["@.return"].Value;
> }
> }
> This is the stored procdure called in the method:
> ALTER PROCEDURE dbo.AH_network_SendMessages
> @.sender nvarchar(256),
> @.receiver nvarchar(256),
> @.title nvarchar(100),
> @.body nvarchar(2000),
> @.return int OUTPUT
> AS
> BEGIN
> SET NOCOUNT ON;
> INSERT INTO AH_Messages (sender, receiver, title, body)
> VALUES (@.sender, @.receiver, @.title, @.body);
> set @.return = 1;
> select 1;
> END
> Please, what am I doing wrong here?
> Jeff
>
What is the ExecuteNonQuery method you try to call after all?
Normally, you will do a cmd.ExecuteNonQuery, rather than
ExecuteNonQuery(cmd).
Could it be that your ExecuteNonQuery(SqlCommand cmd) method in somewhat
fail to do a cmd.ExecuteNonQuery.
The fact that the output parameter does not have a value may suggest that
may be the case.
Tor Bdshaug
tor.badshaug(AT)bekk.no
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...
> Hey
> asp.net 2.0
> My code below crashes at the "return
> (int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
> that when this exception occur, the "return
> (int)cmd.Parameters["@.return"].Value;" has a NULL value...
> public override int SendMessage(MessageDetails message)
> {
> using (SqlConnection cn = new SqlConnection(this.ConnectionString))
> {
> SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
> message.Title;
> cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
> message.Body;
> cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
> ParameterDirection.Output;
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> return (int)cmd.Parameters["@.return"].Value;
> }
> }
> This is the stored procdure called in the method:
> ALTER PROCEDURE dbo.AH_network_SendMessages
> @.sender nvarchar(256),
> @.receiver nvarchar(256),
> @.title nvarchar(100),
> @.body nvarchar(2000),
> @.return int OUTPUT
> AS
> BEGIN
> SET NOCOUNT ON;
> INSERT INTO AH_Messages (sender, receiver, title, body)
> VALUES (@.sender, @.receiver, @.title, @.body);
> set @.return = 1;
> select 1;
> END
> Please, what am I doing wrong here?
> Jeff
>
I am not sure why you are selecting 1 after setting the @.return. There is no
need unless you are doing something with it. Since you are ExecuteNonQuery,
this is a wasted cycle.
Next, why are you not testing "ret" in your code. If it is -1, the insert
failed for some reason. By testing that you could determine what your issue
is.
Also, why have you not wrapped the open and ExecuteNonQuery() in a try. Here
is a good pattern:
try
{
cn.Open();
int ret = ExecuteNonQuery(cmd);
}
finally
{
cn.Dispose();
}
Not sure what you are returning.
Next suggestion. Do not return until you test the parameter. If it is is
null, the cast to int will blow up (nice technical term ;-> ).
Be careful with calling thisgs return in a stored proc, as SQL Server
already returns a value (even if you do not declare it) called
@.RETURN_VALUE.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/
****************************************
*********
Think Outside the Box!
****************************************
*********
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...
> Hey
> asp.net 2.0
> My code below crashes at the "return
> (int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
> that when this exception occur, the "return
> (int)cmd.Parameters["@.return"].Value;" has a NULL value...
> public override int SendMessage(MessageDetails message)
> {
> using (SqlConnection cn = new SqlConnection(this.ConnectionString))
> {
> SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
> message.Sender;
> cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
> message.Title;
> cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
> message.Body;
> cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
> ParameterDirection.Output;
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> return (int)cmd.Parameters["@.return"].Value;
> }
> }
> This is the stored procdure called in the method:
> ALTER PROCEDURE dbo.AH_network_SendMessages
> @.sender nvarchar(256),
> @.receiver nvarchar(256),
> @.title nvarchar(100),
> @.body nvarchar(2000),
> @.return int OUTPUT
> AS
> BEGIN
> SET NOCOUNT ON;
> INSERT INTO AH_Messages (sender, receiver, title, body)
> VALUES (@.sender, @.receiver, @.title, @.body);
> set @.return = 1;
> select 1;
> END
> Please, what am I doing wrong here?
> Jeff
>
Thanks, the error was in the ExecuteNonQuery method, which is just a wrapper
around SqlCommand.ExecuteNonQuery... It's solved now, thanks to your tip
about checking ExecuteNonQuery
"Tor Bdshaug" <tor.badshaug@.nospam.com> wrote in message
news:%23TqCCAw6GHA.4996@.TK2MSFTNGP04.phx.gbl...
> What is the ExecuteNonQuery method you try to call after all?
> Normally, you will do a cmd.ExecuteNonQuery, rather than
> ExecuteNonQuery(cmd).
> Could it be that your ExecuteNonQuery(SqlCommand cmd) method in somewhat
> fail to do a cmd.ExecuteNonQuery.
> The fact that the output parameter does not have a value may suggest that
> may be the case.
> Tor Bdshaug
> tor.badshaug(AT)bekk.no
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...
>
Hey
Thanks, yes selecting 1 after setting the @.return to 1 is bad programming. I
know it, I will later rewrite this stored procedure and then I will fix
this.. the procedure is also missing a commit/rollback... I guess auto
commit is enabled but I prefer using explicit transaction...
"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamM> wrote in
message news:ON3X9Jw6GHA.2288@.TK2MSFTNGP05.phx.gbl...
>I am not sure why you are selecting 1 after setting the @.return. There is
>no need unless you are doing something with it. Since you are
>ExecuteNonQuery, this is a wasted cycle.
> Next, why are you not testing "ret" in your code. If it is -1, the insert
> failed for some reason. By testing that you could determine what your
> issue is.
> Also, why have you not wrapped the open and ExecuteNonQuery() in a try.
> Here is a good pattern:
> try
> {
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> }
> finally
> {
> cn.Dispose();
> }
> Not sure what you are returning.
> Next suggestion. Do not return until you test the parameter. If it is is
> null, the cast to int will blow up (nice technical term ;-> ).
> Be careful with calling thisgs return in a stored proc, as SQL Server
> already returns a value (even if you do not declare it) called
> @.RETURN_VALUE.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com/
> ****************************************
*********
> Think Outside the Box!
> ****************************************
*********
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...
>

newbie: my code crashe, NULL value

Hey

asp.net 2.0

My code below crashes at the "return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;"
line. In the debugging window I see that when this exception occur, the
"return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;" has a NULL value...

public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@dotnet.itags.org.receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@dotnet.itags.org.sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@dotnet.itags.org.title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@dotnet.itags.org.body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@dotnet.itags.org.return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@dotnet.itags.org.return"].Value;
}
}

This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@dotnet.itags.org.sender nvarchar(256),
@dotnet.itags.org.receiver nvarchar(256),
@dotnet.itags.org.title nvarchar(100),
@dotnet.itags.org.body nvarchar(2000),
@dotnet.itags.org.return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@dotnet.itags.org.sender, @dotnet.itags.org.receiver, @dotnet.itags.org.title, @dotnet.itags.org.body);

set @dotnet.itags.org.return = 1;
select 1;
END

Please, what am I doing wrong here?

JeffIf altering the signature of your SP, you may consider the following option
that should work.

SqlParameter returnValue = sqlCommand.Parameters.Add("@.YourSPReturnValue",
SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
return (Int32)returnValue.Value;

Declaring an explicit return value is in my opinion preferrable, as it is
more clear about your intent and somewhat cleans up the SP declaration.

Tor Bdshaug
tor.badshaug(AT)bekk.no

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
My code below crashes at the "return
(int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
that when this exception occur, the "return
(int)cmd.Parameters["@.return"].Value;" has a NULL value...
>
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@.return"].Value;
}
}
>
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@.sender nvarchar(256),
@.receiver nvarchar(256),
@.title nvarchar(100),
@.body nvarchar(2000),
@.return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@.sender, @.receiver, @.title, @.body);
>
set @.return = 1;
select 1;
END
>
Please, what am I doing wrong here?
>
Jeff
>


What is the ExecuteNonQuery method you try to call after all?
Normally, you will do a cmd.ExecuteNonQuery, rather than
ExecuteNonQuery(cmd).
Could it be that your ExecuteNonQuery(SqlCommand cmd) method in somewhat
fail to do a cmd.ExecuteNonQuery.
The fact that the output parameter does not have a value may suggest that
may be the case.

Tor Bdshaug
tor.badshaug(AT)bekk.no

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
My code below crashes at the "return
(int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
that when this exception occur, the "return
(int)cmd.Parameters["@.return"].Value;" has a NULL value...
>
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@.return"].Value;
}
}
>
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@.sender nvarchar(256),
@.receiver nvarchar(256),
@.title nvarchar(100),
@.body nvarchar(2000),
@.return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@.sender, @.receiver, @.title, @.body);
>
set @.return = 1;
select 1;
END
>
Please, what am I doing wrong here?
>
Jeff
>


Thanks, the error was in the ExecuteNonQuery method, which is just a wrapper
around SqlCommand.ExecuteNonQuery... It's solved now, thanks to your tip
about checking ExecuteNonQuery

"Tor Bdshaug" <tor.badshaug@.nospam.comwrote in message
news:%23TqCCAw6GHA.4996@.TK2MSFTNGP04.phx.gbl...

Quote:

Originally Posted by

What is the ExecuteNonQuery method you try to call after all?
Normally, you will do a cmd.ExecuteNonQuery, rather than
ExecuteNonQuery(cmd).
Could it be that your ExecuteNonQuery(SqlCommand cmd) method in somewhat
fail to do a cmd.ExecuteNonQuery.
The fact that the output parameter does not have a value may suggest that
may be the case.
>
Tor Bdshaug
tor.badshaug(AT)bekk.no
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Hey
>>
>asp.net 2.0
>>
>My code below crashes at the "return
>(int)cmd.Parameters["@.return"].Value;" line. In the debugging window I
>see that when this exception occur, the "return
>(int)cmd.Parameters["@.return"].Value;" has a NULL value...
>>
>public override int SendMessage(MessageDetails message)
>{
> using (SqlConnection cn = new SqlConnection(this.ConnectionString))
> {
> SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
>message.Sender;
> cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
>message.Sender;
> cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
>message.Title;
> cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
>message.Body;
> cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
>ParameterDirection.Output;
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> return (int)cmd.Parameters["@.return"].Value;
> }
>}
>>
>This is the stored procdure called in the method:
>ALTER PROCEDURE dbo.AH_network_SendMessages
>@.sender nvarchar(256),
>@.receiver nvarchar(256),
>@.title nvarchar(100),
>@.body nvarchar(2000),
>@.return int OUTPUT
>AS
>BEGIN
>SET NOCOUNT ON;
>INSERT INTO AH_Messages (sender, receiver, title, body)
> VALUES (@.sender, @.receiver, @.title, @.body);
>>
>set @.return = 1;
>select 1;
>END
>>
>Please, what am I doing wrong here?
>>
>Jeff
>>


>
>


I am not sure why you are selecting 1 after setting the @.return. There is no
need unless you are doing something with it. Since you are ExecuteNonQuery,
this is a wasted cycle.

Next, why are you not testing "ret" in your code. If it is -1, the insert
failed for some reason. By testing that you could determine what your issue
is.

Also, why have you not wrapped the open and ExecuteNonQuery() in a try. Here
is a good pattern:

try
{
cn.Open();
int ret = ExecuteNonQuery(cmd);
}
finally
{
cn.Dispose();
}

Not sure what you are returning.

Next suggestion. Do not return until you test the parameter. If it is is
null, the cast to int will blow up (nice technical term ;->).

Be careful with calling thisgs return in a stored proc, as SQL Server
already returns a value (even if you do not declare it) called
@.RETURN_VALUE.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/
*************************************************
Think Outside the Box!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
My code below crashes at the "return
(int)cmd.Parameters["@.return"].Value;" line. In the debugging window I see
that when this exception occur, the "return
(int)cmd.Parameters["@.return"].Value;" has a NULL value...
>
public override int SendMessage(MessageDetails message)
{
using (SqlConnection cn = new SqlConnection(this.ConnectionString))
{
SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
message.Sender;
cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
message.Title;
cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
message.Body;
cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
ParameterDirection.Output;
cn.Open();
int ret = ExecuteNonQuery(cmd);
return (int)cmd.Parameters["@.return"].Value;
}
}
>
This is the stored procdure called in the method:
ALTER PROCEDURE dbo.AH_network_SendMessages
@.sender nvarchar(256),
@.receiver nvarchar(256),
@.title nvarchar(100),
@.body nvarchar(2000),
@.return int OUTPUT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO AH_Messages (sender, receiver, title, body)
VALUES (@.sender, @.receiver, @.title, @.body);
>
set @.return = 1;
select 1;
END
>
Please, what am I doing wrong here?
>
Jeff
>


Hey

Thanks, yes selecting 1 after setting the @.return to 1 is bad programming. I
know it, I will later rewrite this stored procedure and then I will fix
this.. the procedure is also missing a commit/rollback... I guess auto
commit is enabled but I prefer using explicit transaction...

"Cowboy (Gregory A. Beamer)" <NoSpamMgbworld@.comcast.netNoSpamMwrote in
message news:ON3X9Jw6GHA.2288@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>I am not sure why you are selecting 1 after setting the @.return. There is
>no need unless you are doing something with it. Since you are
>ExecuteNonQuery, this is a wasted cycle.
>
Next, why are you not testing "ret" in your code. If it is -1, the insert
failed for some reason. By testing that you could determine what your
issue is.
>
Also, why have you not wrapped the open and ExecuteNonQuery() in a try.
Here is a good pattern:
>
try
{
cn.Open();
int ret = ExecuteNonQuery(cmd);
}
finally
{
cn.Dispose();
}
>
Not sure what you are returning.
>
Next suggestion. Do not return until you test the parameter. If it is is
null, the cast to int will blow up (nice technical term ;->).
>
Be careful with calling thisgs return in a stored proc, as SQL Server
already returns a value (even if you do not declare it) called
@.RETURN_VALUE.
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/
>
*************************************************
Think Outside the Box!
*************************************************
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:unl2osv6GHA.4580@.TK2MSFTNGP03.phx.gbl...

Quote:

Originally Posted by

>Hey
>>
>asp.net 2.0
>>
>My code below crashes at the "return
>(int)cmd.Parameters["@.return"].Value;" line. In the debugging window I
>see that when this exception occur, the "return
>(int)cmd.Parameters["@.return"].Value;" has a NULL value...
>>
>public override int SendMessage(MessageDetails message)
>{
> using (SqlConnection cn = new SqlConnection(this.ConnectionString))
> {
> SqlCommand cmd = new SqlCommand("AH_network_SendMessages", cn);
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@.receiver", SqlDbType.NVarChar).Value =
>message.Sender;
> cmd.Parameters.Add("@.sender", SqlDbType.NVarChar).Value =
>message.Sender;
> cmd.Parameters.Add("@.title", SqlDbType.NVarChar).Value =
>message.Title;
> cmd.Parameters.Add("@.body", SqlDbType.NVarChar).Value =
>message.Body;
> cmd.Parameters.Add("@.return", SqlDbType.Int).Direction =
>ParameterDirection.Output;
> cn.Open();
> int ret = ExecuteNonQuery(cmd);
> return (int)cmd.Parameters["@.return"].Value;
> }
>}
>>
>This is the stored procdure called in the method:
>ALTER PROCEDURE dbo.AH_network_SendMessages
>@.sender nvarchar(256),
>@.receiver nvarchar(256),
>@.title nvarchar(100),
>@.body nvarchar(2000),
>@.return int OUTPUT
>AS
>BEGIN
>SET NOCOUNT ON;
>INSERT INTO AH_Messages (sender, receiver, title, body)
> VALUES (@.sender, @.receiver, @.title, @.body);
>>
>set @.return = 1;
>select 1;
>END
>>
>Please, what am I doing wrong here?
>>
>Jeff
>>


>
>