Hi, I had some problems on setting the value for a variable when user clicks on the image button.

This is wat I have in the aspx file

<asp:ImageButton ID="NewBtn" runat="server" ImageUrl="image/plus.png" Width="24px" onclick = "newUser = 'True'"/>

At first i tried to declare the variable in code behind as follow

Dim newUser As Boolean

but it gave me an error : is not accessible in this context because it is 'Private'.

Then i change to

Protected newUser As Boolean

Another error shown: 'AddressOf' operand must be the name of a method (without parentheses).


S.O.S!~ I have no idea how to solve this..

you can't directly set properties from control event handlers. They have to point to methods.

you can't directly set properties from control event handlers. They have to point to methods.

Thanks for the reply. I had tried to change the onClientClick to 'NewBtn_Click' event. It can work but after the click and some coding execution, the value can't be change. As example, i use the image button to indicate that user want to add in new user id. The value for newUser will be true as i declare it as Boolean. after the insert query, i assign false to the newUser and get to mofidy the existing record which should perform update query. But it performs insert query instead as the newUser value did not change from true to false as assigned.

If NewUser is just a property of the page then it will always be reset each time the page is called because the page is recreated each time. You should probably look into asp.net Sessions to store the value of NewUser, that way the updated value will persist across postbacks.

Thanks for the suggestion. How should i pass the variable using Session?.. Any references?

You could create a page property using Session to maintain its value

public bool NewUser
{
  get
  {
    return Session["NewUser"] == null ? true : (bool)Session["NewUser"];
  }
  set
  {
    Session["NewUser"] = value;
  }
}

This is C# though, not real sure of the syntax in VB. In this instance if the Session is null then it will return true if the Session variable is not null then it casts it as bool and returns the value.

This page contains some information about using Session

Thanks for the suggestion :icon_cheesygrin:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.