 |
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
|
|
|

June 21st, 2010, 09:34 PM
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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 ");
}
}
|

June 22nd, 2010, 02:17 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

June 22nd, 2010, 04:45 PM
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
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 ");
}
}
|

June 22nd, 2010, 04:58 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

June 22nd, 2010, 05:31 PM
|
Authorized User
|
|
Join Date: Mar 2010
Posts: 65
Thanks: 6
Thanked 0 Times in 0 Posts
|
|
Thank you so much. I le try that.
|
|
 |