Pass Variable to another function

Discussion in 'ASP .Net' started by manmit.walia@gmail.com, Oct 13, 2005.

  1. Guest

    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
     
    , Oct 13, 2005
    #1
    1. Advertising

  2. Guest

    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
     
    , Oct 13, 2005
    #2
    1. Advertising

  3. 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"];

    <> wrote in message
    news:...
    > 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
    >
     
    Dave Hagerich, Oct 13, 2005
    #3
  4. Guest

    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
     
    , Oct 14, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Kial
    Replies:
    1
    Views:
    664
    Eric Enright
    Nov 15, 2004
  2. deanfamily
    Replies:
    4
    Views:
    417
    puzzlecracker
    Oct 24, 2005
  3. grbgooglefan
    Replies:
    9
    Views:
    883
    grbgooglefan
    May 9, 2008
  4. Replies:
    8
    Views:
    122
  5. Replies:
    5
    Views:
    109
Loading...

Share This Page