0

I've got default.aspx/default.aspx.cs and other.cs where i "store" a bunch of functions.

In my default.aspx i've :

 <asp:ImageButton ID="ImageButton1" CssClass="btn_img" ImageUrl="./images/1.png" runat="server" OnClick='<%# "setFunction(" +Eval("aGUID") +")" %>' />

in my default.aspx.cs

protected void setFunction(object sender, ImageClickEventArgs e)
{
    string istr = e.ToString();
    var iguid = new Guid(istr);
    // this are classes/functions stored in other.cs
    ManageFun mfun = new ManageFun();
    mfun.setMM(iguid);
}

I though i was doing all right, but can't figure out what i'm doing wrong! In matter of fact it does nothing!

Apreciate any help!

Thanks!

1
  • Shouldn't it just be OnClick="setFunction" ? Commented Nov 3, 2016 at 13:14

2 Answers 2

2

You can try this

  <h3>ImageButton Sample</h3>

  Click anywhere on the image.<br /><br />

  <asp:ImageButton id="imagebutton1" runat="server"
       AlternateText="ImageButton 1"
       ImageAlign="left"
       ImageUrl="images/pict.jpg"
       OnClick="ImageButton_Click"/>

  <br /><br />

  <asp:label id="Label1" runat="server"/>

and C# code

public void ImageButton_Click(object sender, ImageClickEventArgs e) 
      {
         Label1.Text = "You clicked the ImageButton control at the coordinates: (" + 
                       e.X.ToString() + ", " + e.Y.ToString() + ")";
      }

No need to write these <%#

Here is the reference Click

Sign up to request clarification or add additional context in comments.

1 Comment

my setFunction is wating for a parameter of GUID type, shouldn't i pass it with Eval ? How is my function get to know the parameter ?
0

Basically asp:ImageButton with Onclick which will not call the server side code with Eval.

Edit:

You can directly call like this :

<asp:ImageButton ID="ImageButton1" CssClass="btn_img" ImageUrl="./images/1.png" runat="server" OnClick="setFunction"  />

if you want to pass the parameter to that function you can assign the param to the CommandArguement as below

CommandArguement='<%# Eval("aGUID") %>' 

in your SetFunction you can retrieve like this

string val = e.CommandArguement.ToString()

2 Comments

@esko fixed typo .. and i read my answer it giving some different meaning which i fixed
my setFunction is wating for a parameter of GUID type, shouldn't i pass it with Eval ? How is my function get to know the parameter ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.