ASP.NET 3.5 BasicsIf 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 .
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.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");
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.
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");
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.