Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Saturday, March 31, 2012

Set a session variable to pre defined value

I just want to set a sesison variable to a defined value when a page loads, I've tried the following but it doesn't seem to work. Any ideas where I'm going wrong?

<%# Session("var1") = "abc" %
Thanks

Julian ParkinsonYou've used adata binding expression, so it will only be called when DataBind() is called on the Page.

I think you want to use aninline code expression instead:

<% Session("var1") = "abc" %>

Hi,

You need to put the Session variable in the Page_Load like this:


if(!Page.IsPostBack)
{

Session["Name"] = "NewValue";
Response.Redirect("Mynewpage.aspx");

}

And then in the Mynewpage.aspx you can recieve the session using this code in the Page_Load with not postback.

if(Session["Name"] == null )
Response.Redirect("LoginPage.aspx");

else
Label1.Text = Session["Name"].ToString();


Dan,

Cheers for that. I just needed the remove the hash!! Duhh!

I'm moving from asp vb to asp.net vb and i'm finding it strange, some stuff is the same, some isn't sometimes I can't see the wood for the trees.

Thanks again.

Thursday, March 22, 2012

set image url programmatically for image control

I have a print page that uses an image control to display an image that is saved in a directory that is dynamically created upon a session start. I have the path readily available for the image control...but I am failing to get the image to display in the image control...

what is the syntax to properly set the url for an image control programmatically in the code behind?

the control is named printImage

thanks in advance

Eric

printImage.src=


printImage.ImageUrl = "your URL";

simple as that.


I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?


ekeefauver:

I am not getting the .src in intellisense for the control - is there a namespace/directive that I am missing?

Nope, it's just, that property is called "ImageUrl" and not "src".


doesn't seem to work for me...do I somehow need to refresh the control after setting the URL to the image?

the path to the image is: C:\Documents and Settings\dekeefau\My Documents\Visual Studio 2005\WebSites\CMAT_FINAL\sessions\sd_ewwewtjwy23b5vnrmxm1mffz\print\theimage.bmp

which is stored in a string variable


No, there is no need to refresh the control. Perhaps the path you are using is not valid? Try using Server.MapPath() function with the relative path to the image in question.

Example:

Image is in the /Images subfolder of the application and its name is MyImage.gif

Then the code to display this image would be:

printImage.ImageUrl = Server.MapPath("~/Images/MyImage.gif");

Tuesday, March 13, 2012

Set Postback or Session Timeout

Hi All.
I have a page that users enter information in text boxes...and
sometimes it's a lot of information. There are times that these folks
either take their time entering the info or do other things before they
submit the page. Unfortunately, if they do take their time, there are
times where the session times out and they can no longer submit their
information, resulting in an error and pretty peeved users.
What I'm asking for help on is...can, possibly through a timer or
something either reset the session or do a postback? This would be to
cover in case the user would take too much time to submit the
information....it would happen automatically. I do have a popup box
that warns them they are about to time out, but it might not be seen.
So far, I have tried a timer to redirect the page to itself, try to go
through the page_load and try to set the session.timeout, but none of
it looks to work. I did see some __doPostBack and Page.GetPostBackEvent
articles, but didn't see how to put them to use. They get mentioned,
but I don't see how to make them function on my page. I need some way
to try to keep the session alive and not timeout. Sorry if it's
something that's easy that I don't see. I'm still a bit (ok, well very)
new at this I have searched Google high and low and found nothing that
looks to work.
Thanks for any help you can be!!
kurtYou can:
1. Extend the length of the session timeout.
2. Store your information in ViewState instead.
"kurt" <kbaker@.granitemicrosystems.com> wrote in message
news:1115834747.970410.207850@.o13g2000cwo.googlegroups.com...
> Hi All.
> I have a page that users enter information in text boxes...and
> sometimes it's a lot of information. There are times that these folks
> either take their time entering the info or do other things before they
> submit the page. Unfortunately, if they do take their time, there are
> times where the session times out and they can no longer submit their
> information, resulting in an error and pretty peeved users.
> What I'm asking for help on is...can, possibly through a timer or
> something either reset the session or do a postback? This would be to
> cover in case the user would take too much time to submit the
> information....it would happen automatically. I do have a popup box
> that warns them they are about to time out, but it might not be seen.
> So far, I have tried a timer to redirect the page to itself, try to go
> through the page_load and try to set the session.timeout, but none of
> it looks to work. I did see some __doPostBack and Page.GetPostBackEvent
> articles, but didn't see how to put them to use. They get mentioned,
> but I don't see how to make them function on my page. I need some way
> to try to keep the session alive and not timeout. Sorry if it's
> something that's easy that I don't see. I'm still a bit (ok, well very)
> new at this I have searched Google high and low and found nothing that
> looks to work.
> Thanks for any help you can be!!
> kurt
>
kurt wrote:
> Hi All.
> I have a page that users enter information in text boxes...and
> sometimes it's a lot of information. There are times that these folks
> either take their time entering the info or do other things before
> they submit the page. Unfortunately, if they do take their time,
> there are times where the session times out and they can no longer
> submit their information, resulting in an error and pretty peeved
> users.
> What I'm asking for help on is...can, possibly through a timer or
> something either reset the session or do a postback? This would be to
> cover in case the user would take too much time to submit the
> information....it would happen automatically. I do have a popup box
> that warns them they are about to time out, but it might not be seen.
>
Maybe you can use a (small) iframe that refreshes itself every few minutes,
to keep the session alive but without submitting the entire page
(and losing scroll-position and focus).
Hans Kesting
Sorry I didn't get back sooner, but I was out for a while. I'm not
sure extending the timeout would work. If I set it to 30 minutes,
they'll probably go 31...and so on. I also wasn't sure that the
viewstate would be usable and last either. But, I did try the iframe
and so far it looks to do exactly as I needed. I also have been trying
it out and I don't look to lose focus from the control I'm currently
using when the iframe refreshes. Thanks for all the input!!
Kurt

Set Postback or Session Timeout

Hi All.
I have a page that users enter information in text boxes...and
sometimes it's a lot of information. There are times that these folks
either take their time entering the info or do other things before they
submit the page. Unfortunately, if they do take their time, there are
times where the session times out and they can no longer submit their
information, resulting in an error and pretty peeved users.

What I'm asking for help on is...can, possibly through a timer or
something either reset the session or do a postback? This would be to
cover in case the user would take too much time to submit the
information....it would happen automatically. I do have a popup box
that warns them they are about to time out, but it might not be seen.

So far, I have tried a timer to redirect the page to itself, try to go
through the page_load and try to set the session.timeout, but none of
it looks to work. I did see some __doPostBack and Page.GetPostBackEvent
articles, but didn't see how to put them to use. They get mentioned,
but I don't see how to make them function on my page. I need some way
to try to keep the session alive and not timeout. Sorry if it's
something that's easy that I don't see. I'm still a bit (ok, well very)
new at this I have searched Google high and low and found nothing that
looks to work.

Thanks for any help you can be!!

kurtYou can:
1. Extend the length of the session timeout.
2. Store your information in ViewState instead.

"kurt" <kbaker@.granitemicrosystems.com> wrote in message
news:1115834747.970410.207850@.o13g2000cwo.googlegr oups.com...
> Hi All.
> I have a page that users enter information in text boxes...and
> sometimes it's a lot of information. There are times that these folks
> either take their time entering the info or do other things before they
> submit the page. Unfortunately, if they do take their time, there are
> times where the session times out and they can no longer submit their
> information, resulting in an error and pretty peeved users.
> What I'm asking for help on is...can, possibly through a timer or
> something either reset the session or do a postback? This would be to
> cover in case the user would take too much time to submit the
> information....it would happen automatically. I do have a popup box
> that warns them they are about to time out, but it might not be seen.
> So far, I have tried a timer to redirect the page to itself, try to go
> through the page_load and try to set the session.timeout, but none of
> it looks to work. I did see some __doPostBack and Page.GetPostBackEvent
> articles, but didn't see how to put them to use. They get mentioned,
> but I don't see how to make them function on my page. I need some way
> to try to keep the session alive and not timeout. Sorry if it's
> something that's easy that I don't see. I'm still a bit (ok, well very)
> new at this I have searched Google high and low and found nothing that
> looks to work.
> Thanks for any help you can be!!
> kurt
kurt wrote:
> Hi All.
> I have a page that users enter information in text boxes...and
> sometimes it's a lot of information. There are times that these folks
> either take their time entering the info or do other things before
> they submit the page. Unfortunately, if they do take their time,
> there are times where the session times out and they can no longer
> submit their information, resulting in an error and pretty peeved
> users.
> What I'm asking for help on is...can, possibly through a timer or
> something either reset the session or do a postback? This would be to
> cover in case the user would take too much time to submit the
> information....it would happen automatically. I do have a popup box
> that warns them they are about to time out, but it might not be seen.

Maybe you can use a (small) iframe that refreshes itself every few minutes,
to keep the session alive but without submitting the entire page
(and losing scroll-position and focus).

Hans Kesting
Sorry I didn't get back sooner, but I was out for a while. I'm not
sure extending the timeout would work. If I set it to 30 minutes,
they'll probably go 31...and so on. I also wasn't sure that the
viewstate would be usable and last either. But, I did try the iframe
and so far it looks to do exactly as I needed. I also have been trying
it out and I don't look to lose focus from the control I'm currently
using when the iframe refreshes. Thanks for all the input!!

Kurt