HtmlInputImage.ServerClick

J

JP

ow do I get a HtmlInputImage to raise the ServerClick event

I have two inputs one is a submit button the other is a
image. The submit button works the input image does not.
Does anyone know why this would happen?

I would like to mention that I have overridden viewstate
and do not use server side forms.

Below is my code maybe I am missing something



<input type="image" src="~/img/btnPurchase.gif" width="90"
height="26" id="Purchase" runat="server">
<input type="submit" id="sbmt" runat="server"
value="submit">

and the code behind is as follows.

protected System.Web.UI.HtmlControls.HtmlInputImage
Purchase;
protected System.Web.UI.HtmlControls.HtmlInputButton sbmt;

private void InitializeComponent()
{
this.sbmt.ServerClick += new System.EventHandler
(this.Sbmt_Click);
this.Purchase.ServerClick += new
System.Web.UI.ImageClickEventHandler(this.Purchase_Click);
this.Load += new System.EventHandler
(this.Page_Load);
}

public void Purchase_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Write("Purchase_Click Fired!!!");
Response.End();
}
private void Sbmt_Click(object sender, System.EventArgs e)
{
Response.Write("Purchase_Click Fired!!!");
Response.End();
}
 
G

Guest

Please find my suggestion inlined with your code....

HTH
-----Original Message-----
ow do I get a HtmlInputImage to raise the ServerClick event

I have two inputs one is a submit button the other is a
image. The submit button works the input image does not.
Does anyone know why this would happen?

I would like to mention that I have overridden viewstate
and do not use server side forms.

Below is my code maybe I am missing something



<input type="image" src="~/img/btnPurchase.gif" width="90"
height="26" id="Purchase" runat="server">
<input type="submit" id="sbmt" runat="server"
value="submit">

and the code behind is as follows.

protected System.Web.UI.HtmlControls.HtmlInputImage
Purchase;
protected System.Web.UI.HtmlControls.HtmlInputButton sbmt;

private void InitializeComponent()
{
this.sbmt.ServerClick += new System.EventHandler
(this.Sbmt_Click);
this.Purchase.ServerClick += new
System.Web.UI.ImageClickEventHandler(this.Purchase_Click);
this.Load += new System.EventHandler
(this.Page_Load);
}

--> Try

this.Purchase.Click += new
 
J

JP

Click is not a defined methed of HTMLInputImage
And the compilier throws and error stating that if i try.
 
J

Jacob Yang [MSFT]

Hi JP,

I am not sure about what you have done in "I would like to mention that I
have overridden viewstate and do not use server side forms." but I believe
that this issue is caused by it.

I have tried a simple test on my side and the HtmlInputImage.ServerClick
works fine. Please try the following testing steps on your side.

1. Create a default Web application.

2. Add the following HTML code directly between the "form" tag in the HTML
View.

<input type="image" src="~/img/btnPurchase.gif" width="90" height="26"
id="Purchase" runat="server" NAME="Purchase">
<input type="submit" id="sbmt" runat="server" value="submit" NAME="sbmt">

3. Switch to the Design View. Double click the buttons to add the event
handler.
...
private void Purchase_ServerClick(object sender,
System.Web.UI.ImageClickEventArgs e)
{
Response.Write("Image Purchase_Click Fired!!!");
}

private void sbmt_ServerClick(object sender, System.EventArgs e)
{
Response.Write("Purchase_Click Fired!!!");
}
...

4. Build and test the application. Everything works fine.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

JP

Yes this works.
I was hoping to find a reason why buttons work with out a
valid viewstate but a htmlinputimage doesn't
 
J

Jacob Yang [MSFT]

Hi JP,

Thank you for your update.

As I have mentioned before, I am not sure about what you have done in "I
would like to mention that I have overridden viewstate and do not use
server side forms."

I am trying to reproduce your problem on my side now. Would you please tell
me how to reproduce the problem on my side with my simple testing sample in
my previous post? It will be helpful to find the root cause for this issue.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top