create custom button asp.net

C

Colin Graham

Hi there,

I am working on a project at the minute and i have created a button
using the following code.

<asp:button id="Button1" onclick="upload" runat="server" Width="119px"
text="Upload"></asp:button>

this button calls and runs some code ie. sub upload - see below

Public Sub upload(ByVal s As Object, ByVal e As EventArgs)

code here .......

i have created my own button in fireworks and want to insert it in my
code an call this function but it does not work - code below

<INPUT id="btn_EditImage" type="image" src="Buttons/EditImage.gif"
onclick="upload" runat="server"></TD>

Can anyone please tell me what the problem is and how can i get round
this issue. i do not really understand the (ByVal s As Object, ByVal e
As EventArgs) in my sub routine can this be removed ???
 
J

J

These are pretty fundamental issues that you are talking about, the upload
method that you talk about is a webserver method, I.E. it can only run on
the server side, the onclick= you are trying to call with the buttons, both
the asp and the fireworks one, is javascript and as such a client side call,
you cannot call server methods like this. You could use the image to act
like a button on the server side but then you would be posting back to the
server and not using javascript. I'd head over to http://www.asp.net and
have a run through their tutorials section, also the Gunderloy books for
preping for the microsoft exams are pretty good too,

J.
 
R

Roger Helliwell

i have created my own button in fireworks and want to insert it in my
code an call this function but it does not work - code below

The problem is that the <asp:Button> is a server-side control and the
<INPUT> is client-side. If you need to process an event and have some
code run on the server, then you should use a server-side control.

Try this instead:

<ASP:ImageButton id="Button1" onclick="upload" runat="server"
Width="119px" ImageUrl="Buttons/EditImage.gif"></asp:ImageButton>

'ImageUrl' refers to the image you created. Similar to 'src'.

When this button is clicked, a postback occurs and your upload()
method on the server is called. (By using onclick in the <INPUT> tag
the way you had it, the browser is expecting the name of a client-side
(javascript) method.)
Can anyone please tell me what the problem is and how can i get round
this issue. i do not really understand the (ByVal s As Object, ByVal e
As EventArgs) in my sub routine can this be removed ???

You need to keep the two parameters in your upload() method the way
you have them. It won't compile without them. 's' is the object that
caused the event (in this case it will be Button1) and 'e' refers to
the event that occured (an OnClick event in this case.)

Roger
 
C

Colin Graham

Thanks for that roger - im definately going along the right lines now.
my only issue is that i got the following error. any ideas as to why
???

Parser Error Message: The base class includes the field 'button1', but
its type (System.Web.UI.WebControls.Button) is not compatible with the
type of control (System.Web.UI.WebControls.ImageButton).

thanks again.

C
 

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,796
Messages
2,569,645
Members
45,362
Latest member
OrderTrimKetoBoost

Latest Threads

Top