I have a routine that i only want to execute if a variable is set to Y. The
routine is getting some information on the screen then redirecting to a new
page.
How can i passed a variable to the Page.IsPostBack routine on the page_load
event?
this is what I'm trying to do/
sub page_load
if page.ispostback then
dim value as string = CType(Session("quesiton"), string)
if value = "Y" then
'execute my routine
else
'do my datagrid databinding, etc.
end if
end if
thanks 14 1711
> How can i passed a variable to the Page.IsPostBack routine on the
page_load event?
QueryString? Cookie? Session Variable?
-Darrel
Create a label and set its visibility property to false. In the
non-postback code, set the text property of that label to "Y" if your
condition is met. In the postback code, simply check the text property of
the label for "Y".
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com... I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the Page.IsPostBack routine on the page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks
i tried all 3 and its not getting the value of the variable being passed,
thats i posted the question to see if there was another way or a coding error
in my code below.
i need to pass the variable when a button on the page is clicked and only
that time
"darrel" wrote: How can i passed a variable to the Page.IsPostBack routine on the page_load event?
QueryString? Cookie? Session Variable?
-Darrel
You can pass on the querystring, but not to the current executing page
without Response.Redirect. In your case, you are probably looking at setting
the session var in the page and then testing for Y, right? Session vars are
not set until the session cookie goes out to the user and returns on the next
hit.
The same is true for any other method.
I would need to see more of your model to give you a better suggestion. Your
code, if the value was set prior to this hit, is fine.
---
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
***************************
Think Outside the Box!
***************************
"Mike" wrote: I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the Page.IsPostBack routine on the page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks
here is what i'm trying to do.
the user can select items on a datalist via a checkbox. They can hit a
button and get redirected to a information page on the items selected by them.
I can get all the items the user selected fine in the page.ispostback
section, but that breaks some other things my page is doing such as refresh.
I want the routine to get the users selection only when the button is hit.
button code:
Public Sub getCars_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles getCars.Click
getSelectedCars ' this gets the users selections then redirects to info
page
'i tried the label thing, and didnt' work
'i tried redirecting to the page itself and passing a querystring and
didn't work
' i tried creating a session varaible and didn't work/
' i'm out of ideas on this one.
End Sub
onload
in my page_load even
if page.ispostback then
getSelectedCars ' this only works here no where else I need to execute
of the value of Y is true
else
'then all my refresh the screen code
else
'do post backs for selection in drop down.
end if
I only need the getSelecetedCar routine execute only if the button is selected
"Cowboy (Gregory A. Beamer) - MVP" wrote: You can pass on the querystring, but not to the current executing page without Response.Redirect. In your case, you are probably looking at setting the session var in the page and then testing for Y, right? Session vars are not set until the session cookie goes out to the user and returns on the next hit.
The same is true for any other method.
I would need to see more of your model to give you a better suggestion. Your code, if the value was set prior to this hit, is fine.
---
Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA
*************************** Think Outside the Box! ***************************
"Mike" wrote:
I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the Page.IsPostBack routine on the page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks
> i tried all 3 and its not getting the value of the variable being passed, thats i posted the question to see if there was another way or a coding
error in my code below. i need to pass the variable when a button on the page is clicked and only that time
When I need to pass variables like this, I tend to use a redirect:
on button click
execute logic
redirect to 'thispage' + 'query string with variable'
but I'm not sure of the full logic of your page so no idea if that would
really work for you.
-Darrel button code: Public Sub getCars_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles getCars.Click getSelectedCars ' this gets the users selections then redirects to
info page
If you are redirecting, then you need to pass the variables with the
redirect. I'd use a querystring and redirect to the URL with the variables
as the querystring. In what way was that not working for you?
in my page_load even if page.ispostback then getSelectedCars ' this only works here no where else I need to execute of the value of Y is true
But you are redirecting on the button click after a person chooses their
cars. Why are you checking for the selected cars here on the postBack?
-Darrel
i'm doing a post back to get all the items selected from the datalist control.
"darrel" wrote: button code: Public Sub getCars_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles getCars.Click getSelectedCars ' this gets the users selections then redirects to info page
If you are redirecting, then you need to pass the variables with the redirect. I'd use a querystring and redirect to the URL with the variables as the querystring. In what way was that not working for you?
in my page_load even if page.ispostback then getSelectedCars ' this only works here no where else I need to execute of the value of Y is true
But you are redirecting on the button click after a person chooses their cars. Why are you checking for the selected cars here on the postBack?
-Darrel
when you redirect to a new page, when that page is processed, it will not be
a postback. you ned to the check when it is not a postback
-- bruce (sqlwork.com)
"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com... I have a routine that i only want to execute if a variable is set to Y.
The routine is getting some information on the screen then redirecting to a
new page. How can i passed a variable to the Page.IsPostBack routine on the
page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks i'm doing a post back to get all the items selected from the datalist
control.
You are confusing me. According to the sample code you provided, you're
doing a redirect on the button click. As such, there won't be a postback.
Or maybe I'm confusing myself. I think this is what is happening:
- select cars
- push button (triggers postback)
- check for isPostback and check values
- execute button handler and set values
- redirect
I think you're trying to check the values before you set them.
To get around, this is what I've used in the past:
- select cars
- push button
- if isPostback
- set values
- redirect with querystring
- if it isn't a postback
- check values from querystring
-Darrel
this might help here is the code that gets all the checkboxes that are
checked from the user:
this is called when the user clicks the button
Public Sub getSelectedCars()
Dim I As Long
Dim CurrentCheckBox As CheckBox
Dim cbValue As String
Dim gameNum As TextBox
Dim game As String
For I = 0 To dlCars.Items.Count - 1
CurrentCheckBox = dlScores.Items(I).FindControl("chkCars")
carMake = dlScores.Items(I).FindControl("carMake")
cbValue = cbValue & CurrentCheckBox.Checked.ToString()
If CurrentCheckBox.Checked.ToString = True Then
carMake= carMake & carMake.Text & "|"
End If
Next
Response.Redirect("webform2.aspx?cars=" & carMake)
End Sub
this is the page_load event:
page_load
if page.ispostback then
getSelectedCars
end if
if i call getSelectedCars in the is NOT isPostBack then
it returns 0, nothing even if cars are selected
"bruce barker" wrote: when you redirect to a new page, when that page is processed, it will not be a postback. you ned to the check when it is not a postback
-- bruce (sqlwork.com)
"Mike" <Mi**@discussions.microsoft.com> wrote in message news:84**********************************@microsof t.com... I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the Page.IsPostBack routine on the page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks
maybe this will help:
my page load event
if page.ispostback then
getSelectedCars 'if i put this in the if NOT isPostBack then, it will
return nothing even if items are checked
end if
the routine that gets the checked checkboxes checked by the user when they
click the button.
sub getSelectedCars
Dim I As Long
Dim CurrentCheckBox As CheckBox
Dim cbValue As String
Dim carMake As TextBox
Dim carsAs String
For I = 0 To dlCars.Items.Count - 1
CurrentCheckBox = dlCars.Items(I).FindControl("chkCars")
carMake= dlScores.Items(I).FindControl("carMake")
cbValue = cbValue & CurrentCheckBox.Checked.ToString()
If CurrentCheckBox.Checked.ToString = True Then
carMake= carMake & carMake.Text & "|"
End If
Next
'Response.Redirect("webform2.aspx?cars=" & carMake)
"bruce barker" wrote: when you redirect to a new page, when that page is processed, it will not be a postback. you ned to the check when it is not a postback
-- bruce (sqlwork.com)
"Mike" <Mi**@discussions.microsoft.com> wrote in message news:84**********************************@microsof t.com... I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the Page.IsPostBack routine on the page_load event?
this is what I'm trying to do/ sub page_load if page.ispostback then dim value as string = CType(Session("quesiton"), string) if value = "Y" then 'execute my routine else 'do my datagrid databinding, etc. end if end if
thanks
> my page load event if page.ispostback then getSelectedCars 'if i put this in the if NOT isPostBack then, it will return nothing even if items are checked end if
That is correct.
You are confused on the order of things and how postbacks work. Once you
redirect, you're clearing all viewstate information for that page. So, your
page is doing this:
- user selects items
- hits the button
- page postbacks ***
- page redirects
you are trying to grab the variables at the *** stage. You can do that, but
you need to do that in the isPostback section and then redirect from there
WITH the variables appended as a queryString (or some other manner).
So I think your solution is to move the redirect from the button click
handler and instead place it in the isPostBack part of the PageLoad.
So it'd be like this:
- user selects items
- hits the button
- page postbacks, sets values, puts them in a querystring, redirects with
querystring
-Darrel
Ok, would you have a snippet of what the code should look like?
"darrel" <no*****@hotmail.com> wrote in message
news:%2*****************@TK2MSFTNGP12.phx.gbl... my page load event if page.ispostback then getSelectedCars 'if i put this in the if NOT isPostBack then, it will return nothing even if items are checked end if
That is correct.
You are confused on the order of things and how postbacks work. Once you redirect, you're clearing all viewstate information for that page. So, your page is doing this:
- user selects items - hits the button - page postbacks *** - page redirects
you are trying to grab the variables at the *** stage. You can do that, but you need to do that in the isPostback section and then redirect from there WITH the variables appended as a queryString (or some other manner).
So I think your solution is to move the redirect from the button click handler and instead place it in the isPostBack part of the PageLoad.
So it'd be like this:
- user selects items - hits the button - page postbacks, sets values, puts them in a querystring, redirects with querystring
-Darrel
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim |
last post by:
To make !Page.IsPostBack to work, do I need to set any properties at page
level or in the config files(Web, machine) or aspx files. Because code in
under the !IsPostBack is executing twice and...
|
by: Pravin |
last post by:
Hi,
I have a doubt that how does ASP.NET find out whether the page is accessed
for the first time or the page is due to a post back event, and then set
the IsPostBack property ?
Any ideas.
...
|
by: DotNetGruven |
last post by:
I've got a page that does a search... There is an ImageButton on it that
allows the user to reset the search.
The Click Handler for the button clears out the Data and then redirects to
the same...
|
by: MooreSmnith |
last post by:
When I navigate to the next page using
Response.Rediect("MyNextPage.aspx") current page Page_Load event is called.
What I may wrongly understood is that post back will happen whenever there
is any...
|
by: Kamal Jeet Singh |
last post by:
Hi Friends !!
I am facing problem in controlling the dynamically created
controls on web page. The problem Scenario is
Scenario:- My requirement is to load the web user controls on the web...
| |
by: tshad |
last post by:
Is there a way to run a script or function on entry of each page without
having to put a call in each page?
Periodically, I find something I want to do each time a page is entered and
I have to...
|
by: Managed Code |
last post by:
Hi all,
I've got a DropDownList for the connection string in a master page.
Transitioning between content pages causes it to reset to the first
value.
Under what conditions and where should I...
|
by: Jeff |
last post by:
I assume that this is an easy newby question...
How can I conditionally force the code in a "if not page.ispostback sub" to run even if the page is posting back?
More specifically, I have a web...
|
by: ricardo.sobral.santos |
last post by:
Hello,
I am trying to get the value of the radiobuttonlist. The problem is
that I need it to be unselected at every page load. The
radiobuttonlist is set to autopostback (true).
My idea is...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |