Pass Variable to another function

M

manmit.walia

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?

Thanks
 
B

bcutting

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
 
D

Dave Hagerich

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"];
 
M

manmit.walia

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top