Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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 ");
}
}
Reply With Quote
  #2 (permalink)  
Old June 22nd, 2010, 02:17 AM
Imar's Avatar
Wrox Author
Points: 66,563, Level: 100
Points: 66,563, Level: 100 Points: 66,563, Level: 100 Points: 66,563, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,121
Thanks: 65
Thanked 1,384 Times in 1,364 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!
Reply With Quote
  #3 (permalink)  
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 ");
}
}
Reply With Quote
  #4 (permalink)  
Old June 22nd, 2010, 04:58 PM
Imar's Avatar
Wrox Author
Points: 66,563, Level: 100
Points: 66,563, Level: 100 Points: 66,563, Level: 100 Points: 66,563, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,121
Thanks: 65
Thanked 1,384 Times in 1,364 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!
Reply With Quote
  #5 (permalink)  
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 06:50 PM
Refresh imagebutton ianH ASP.NET 2.0 Basics 1 September 13th, 2006 04:40 PM



All times are GMT -4. The time now is 04:29 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.