Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2010, 09:34 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default How to check if ImageButton is Clicked in ASP?

Hello,
I have a button control whose id is "SearchButton" and a image button control in my design view whose id is "ImageButton1".
-I just want to check in page_load whether searchbutton or imagebutton is clicked.
-i don want to do that in its corresponding event handling function.
-When i click searchbutton the message is displayed and its going to its corresponding event.
-But when i click imagebutton, it goes to its event without displaying the message in page_load. Can anybody tell where i was wrong?

.aspx page
----------

<asp:Button ID="SearchButton" runat="server" Text="SEARCH"
CommandName="SchClick" BackColor="#743A3A" onclick="SearchButton_Click" /><br />


<asp:ImageButton ID="ImageButton1" runat="server" Height="17px"
ImageUrl="~/GoButton.png" onclick="ImageButton1_Click" Width="29px" />


.aspx.cs
---------
public void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();

}
else if (!string.IsNullOrEmpty(Request.Form[SearchButton.UniqueID]))
{

System.Windows.Forms.MessageBox.Show("Search clicked");
}
else if (!string.IsNullOrEmpty(Request.Form[ImageButton1.UniqueID]))//This is not happening when i click the image button.
{
System.Windows.Forms.MessageBox.Show("ImageButton1 clicked");

}
else
{
System.Windows.Forms.MessageBox.Show("Final else ");
}
}
 
Old June 22nd, 2010, 02:17 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Set a break point in the Page_Load method, debug and then put Request.Form.AllKeys in a Watch window. You'll notice additional coordinates for the ImageButton.

BTW: System.Windows.Forms.MessageBox.Show should NOT be used in a web application. It's meant for desktop usage. It might work now when you develop and run on the same machine, but you'll get in big troubles later.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 22nd, 2010, 04:45 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thanks for your tip. So what is the alternate for the MessageBox window to use?

-And regarding 'BreakPoint', sorry am new to ASP, am not sure how to handle this. Can you give me some examples?
I just have two button and thats what i used in my page-load which i referred below in req.form[]. But imagebutton alone is not working.

.aspx.cs
---------
public void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();

}
else if (!string.IsNullOrEmpty(Request.Form[SearchButton.UniqueID]))
{

System.Windows.Forms.MessageBox.Show("Search clicked");
}
else if (!string.IsNullOrEmpty(Request.Form[ImageButton1.UniqueID]))//This is not happening when i click the image button.
{
System.Windows.Forms.MessageBox.Show("ImageButton1 clicked");

}
else
{
System.Windows.Forms.MessageBox.Show("Final else ");
}
}
 
Old June 22nd, 2010, 04:58 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It depends on what you want to do.

If your intention is to output it in the page, add a Label control and do something like this:

Label1.Text = "ImageButton1 clicked";

Otherwise, use debugging. Click the line of code you want to watch, hit F9 to set a breakpoint and hit F5 to run the application. As soon as the line with the breakpoint is about to be executed, Visual Studio halts and enables you to debug the application.

Finally, you can look into Tracing. Search Google for ASP.NET Tracing for more details.

All of this, and *a lot* more is discussed in full detail in my books Beginning ASP.NET 3.5 / 4. Check out the links in the signature of this post for more details.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old June 22nd, 2010, 05:31 PM
Authorized User
 
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
Default

Thank you so much. I le try that.




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check if Button is Clicked in ASP? Gayathri79 ASP.NET 3.5 Basics 5 May 24th, 2010 04:55 PM
Need Help in LoginStatus and Asp:ImageButton [Mini kamii47 ASP.NET 2.0 Basics 0 September 1st, 2007 04:24 PM
post back of an asp.imagebutton produce error gbianchi ASP.NET 2.0 Professional 6 July 11th, 2007 10:00 AM
asp:imagebutton link to New url nawski ASP.NET 1.0 and 1.1 Basics 12 November 5th, 2006 07:50 PM
Refresh imagebutton ianH ASP.NET 2.0 Basics 1 September 13th, 2006 04:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.