Showing posts with label postback. Show all posts
Showing posts with label postback. Show all posts

Saturday, March 24, 2012

Pass Variable to another function

Hi,
I have a small question...Is there a way to do a postback to the same
page and pass a value to a function OnClick?

Example:

void GetCityName(string c)
{
string city = c;
}

Now I want to call this function by Doing a PostBack with a
asp:LinkButton.

So, here is the asp:LinkButton code.
<asp:LinkButton ID="mob" runat="server" Text="MOB"
OnClick="GetCityName('MOB')"></asp:LinkButton
Can this be done?

ThanksA Onclick serverside event must conform to the delegate signature of
the CommandEventHandler. You could store the value in a hidden html
input using javascript, then in your server event handler retrieve the
value by using Request.Form.GetValues.

Endo
Or store the value in a session variable.
i.e.
Session["city"] = city;

then have the event handler grab it
i.e.
city = (string)Session["city"];

<bcutting@.gmail.com> wrote in message
news:1129235285.953333.183460@.g44g2000cwa.googlegr oups.com...
> A Onclick serverside event must conform to the delegate signature of
> the CommandEventHandler. You could store the value in a hidden html
> input using javascript, then in your server event handler retrieve the
> value by using Request.Form.GetValues.
> Endo
I am total lost...
Does anyone have an example...

What I have is a map of Alabama. So now if I show Mobile, Montgomery on
the map...
and make each city as a LinkButton.

What I am doing is when the user clicks on (MOB) which is Mobile...I
have a query string that goes to a SQL Server and find data where the
city = 'mob'. I want to create a generic function that does this. So
everytime Ijust click a city all that I have to do is call the function
name and pass the city code.

Thanks

Pass Variable to another function

Hi,
I have a small question...Is there a way to do a postback to the same
page and pass a value to a function OnClick?
Example:
void GetCityName(string c)
{
string city = c;
}
Now I want to call this function by Doing a PostBack with a
asp:LinkButton.
So, here is the asp:LinkButton code.
<asp:LinkButton ID="mob" runat="server" Text="MOB"
OnClick="GetCityName('MOB')"></asp:LinkButton>
Can this be done?
ThanksA Onclick serverside event must conform to the delegate signature of
the CommandEventHandler. You could store the value in a hidden html
input using javascript, then in your server event handler retrieve the
value by using Request.Form.GetValues.
Endo
Or store the value in a session variable.
i.e.
Session["city"] = city;
then have the event handler grab it
i.e.
city = (string)Session["city"];
<bcutting@.gmail.com> wrote in message
news:1129235285.953333.183460@.g44g2000cwa.googlegroups.com...
> A Onclick serverside event must conform to the delegate signature of
> the CommandEventHandler. You could store the value in a hidden html
> input using javascript, then in your server event handler retrieve the
> value by using Request.Form.GetValues.
> Endo
>
I am total lost...
Does anyone have an example...
What I have is a map of Alabama. So now if I show Mobile, Montgomery on
the map...
and make each city as a LinkButton.
What I am doing is when the user clicks on (MOB) which is Mobile...I
have a query string that goes to a SQL Server and find data where the
city = 'mob'. I want to create a generic function that does this. So
everytime Ijust click a city all that I have to do is call the function
name and pass the city code.
Thanks

Passing (and retrieving) an ArrayList from a Session Var.

I am attempting to pass an ArrayList of objects to a Session Variable for retrieval on another page. Unfortunately, whenever I PostBack the page I get the following error:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:

Line 49: objCart.SKU="111"
Line 50: objCart.Quantity=intQuantity
Line 51: aryCart.Add(objCart)
Line 52:
Line 53: Session("Cart")=aryCart

I have the Session("Cart") loading in a 'Not IsPostBack' conditional statement in the PageLoad and it works fine. But as soon as I try loading Session("Cart") into any PostBack situation (either in the PageLoad or any other function) I get the error above. I'm not sure why Session("Cart") only works for 'NotIsPostBack' situations. Is this just a problem related to ArrayLists? Any help would be greatly appreciated.are you creating a NEW objCart and/or a NEW aryCart?
Yes.
To anyone who is reading this thread, I've figured out the solution to this problem. When writing data to a Session variable from an ArrayList or an Array for the first time, the Session must first be initialized, otherwise it returns a Null value and you get the error I was getting. I solved this by using the IsNewSession method witihin a conditional statement to check if the Session was new or not. If it's new you cannot read from the Session variable, you may only write to it. If it's not new you can read from it or write to it.

Wednesday, March 21, 2012

passing a querystring

hey all,
i know i can do response.redirect("my.aspx?id=1")

but what if i'm doing a postback, is there something similar to querystring?

thanks,
rodcharHello,

Request.QueryString allows to read querystring parameters during a postback.
Is this what you are looking for ?

--
Patrice

"rodchar" <rodchar@.discussions.microsoft.coma crit dans le message de
news: 2ACC9430-3838-4BA9-A359-1F352434FF08@.microsoft.com...

Quote:

Originally Posted by

hey all,
i know i can do response.redirect("my.aspx?id=1")
>
but what if i'm doing a postback, is there something similar to
querystring?
>
thanks,
rodchar


Use the viewstate collection or add a HiddenField.