locked
Botton is not working RRS feed

  • Question

  • Here is my code:

            private void Button2_Click(object sender, System.EventArgs e)
            {
               
            //Server.Transfer("orderrecord.aspx");
            this.Response.Redirect("orderrecord.aspx");
            }

    No matter I use server.transfer or this.response.redirect, it just doesn't work and stay at the same page. I try to use a urllink and that way works. I also have another botton on the same page which update the current page datagrid which works well. The bottom info area of the browser seem like showing the browser tries to access to orderrecord.aspx. I double check everything since this is for work but I cannot  find out why. Hope someone knows what could be the problem.
    • Moved by Rudedog2 Thursday, March 4, 2010 2:23 PM : ASP.NET is off-topic (From:Visual C# General)
    Thursday, March 4, 2010 3:53 AM

Answers

  • Please ask ASP.NET questions at www.asp.net/forums to get a better response.

    This problem could be because of the URL is being accessed relative to your curent page. You can use Server.MapPath to determine the current location of the page and if the OrderRecord.aspx 's location is correctly identified.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    • Marked as answer by Rudedog2 Thursday, March 4, 2010 2:21 PM
    Thursday, March 4, 2010 4:07 AM
  • Zeigon's method makes sense. Also you could delete the debug direcctory and rebuild the solution.

    Alos since .NET 1.1 uses IIS, you could try doing an IIS reset on the machine. (Dont ask me why this would solve the problem, but I have found this works for many wierd seemingly unrelated errors in ASP.NET 1.1)

    Last and most importantly post questions to www.asp.net/forums if you havent done it already. The chances of getting a good answer are directly proportional to the number of experts in the area.


    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    • Marked as answer by Rudedog2 Thursday, March 4, 2010 2:22 PM
    Thursday, March 4, 2010 1:37 PM

All replies

  • Please ask ASP.NET questions at www.asp.net/forums to get a better response.

    This problem could be because of the URL is being accessed relative to your curent page. You can use Server.MapPath to determine the current location of the page and if the OrderRecord.aspx 's location is correctly identified.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    • Marked as answer by Rudedog2 Thursday, March 4, 2010 2:21 PM
    Thursday, March 4, 2010 4:07 AM
  • No matter what I put inside that button click block it just wouldn't work. I just try to this.Response.Redirect(http://yahoo.com), it would not work too. I do the same button to redirect to other pages in the same projects, those would work fine, just somehow this second button of this page would never work.
    Thursday, March 4, 2010 4:17 AM
  • Can you check if the button click event is executing by putting a breakpoint and running in debug mode.

    One way I could think of if if some javascript is running on ClientClick and returning false preventing the server side event handler from executing.

    also you could try Response.Redirect("orderrecord.aspx",true) to make current page terminate.

    If these methods dont work, please post it in ASP.NET fourms. The web development guys usually hang out in those forums.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    Thursday, March 4, 2010 4:42 AM
  • Thanks for your answer. I have no idea why even breakpoint and run in dedug mode wouldn't run through that click event. I try breakpoint in other click even and those would go through. I don't know could that be a bug of .net 1.1

    I have javascript but not in the html page, just some javascript alert to show message and not in this click event and not in page load.

    Could that be something related to the postback?
    Thursday, March 4, 2010 6:28 AM
  • I tried anything I can think of again but it doesn't work but work together fine in other pages. I copy the codes to a new page but that page would not work too. There must be something I screw up in the code but I cannot see where.
    Thursday, March 4, 2010 7:14 AM
  • I am surprised no one knows...
    Thursday, March 4, 2010 9:25 AM
  • do one thing
    1. select your button and goto properties window
    2. Goto events tab and check wether click event there or not
    3. if nothing there just add your click event name
    Thursday, March 4, 2010 9:36 AM
  • I guess you must have tried this already but what about deleting and creating the button again?
    Thursday, March 4, 2010 10:22 AM
  • Can you post the HTML code?

    Noam B
    _________________________________________________________

    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    Thursday, March 4, 2010 12:13 PM
  • Zeigon's method makes sense. Also you could delete the debug direcctory and rebuild the solution.

    Alos since .NET 1.1 uses IIS, you could try doing an IIS reset on the machine. (Dont ask me why this would solve the problem, but I have found this works for many wierd seemingly unrelated errors in ASP.NET 1.1)

    Last and most importantly post questions to www.asp.net/forums if you havent done it already. The chances of getting a good answer are directly proportional to the number of experts in the area.


    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    • Marked as answer by Rudedog2 Thursday, March 4, 2010 2:22 PM
    Thursday, March 4, 2010 1:37 PM
  • What's your idea about following:
    private void Button2_Click(object sender, System.EventArgs e)
    {
      MessageBox.Show("Yes, I Exists Really But Can Not Redirect.");
    }
    

    My Blog - MSDN Complement by providing Visual C# Walkthroughs and Sample Codes - Founded In February 24, 2010
    Thursday, March 4, 2010 2:19 PM
  • Hi Yasser, I'm afraid that that code won't work since she's working with asp.net.
    Anyway, the javascript alert approach is another option.
    Thursday, March 4, 2010 2:27 PM
  • Hi Yasser, I'm afraid that that code won't work since she's working with asp.net.
    Anyway, the javascript alert approach is another option.
    Hi dear Zeigon,

    As I see in the initial post, it's a C# code-behind which will run at server not a javascript code, so it can run.
    Thans for the prompt Zeigon :)
    My Blog - MSDN Complement by providing Visual C# Walkthroughs and Sample Codes - Founded In February 24, 2010
    Thursday, March 4, 2010 2:44 PM
  • By adding the windows.Forms reference we can use messagebox in asp.net application also
    i worked out this somewhere in one of my application
    Thursday, March 4, 2010 2:53 PM
  • Well, what I actually meant is that even though it is possible I don't think it's recommended. That would be like sending a request for a client-side control (system.windows.forms) on the server side which requires user interaction (clicking OK) on a remote end (client-side). Meaning that it's like double-clicking on an exe file in your desktop and the application appearing on someone else's pc. Unless I am wrong and the actual call to this MessageBox is translated to a client-side MessageBox. Although I doubt it.

    Besides, why would you want the user to go back to the server to display a messagebox that can easily be created by his/her browser. It would be an expensive call.

    My opinion is that it is not correct.
    Thursday, March 4, 2010 3:29 PM
  • yes you correct Zeigon, comming to performance Messagebox is not recommended
    Thursday, March 4, 2010 3:37 PM
  • By adding the windows.Forms reference we can use messagebox in asp.net application also
    i worked out this somewhere in one of my application
    Are you sure this would work in a Client Server scenario? I mean when we are not working with a local IIS of VS development server. I dont see any transalation to a client side messagebox.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    Thursday, March 4, 2010 6:22 PM
  • Well, what I actually meant is that even though it is possible I don't think it's recommended. That would be like sending a request for a client-side control (system.windows.forms) on the server side which requires user interaction (clicking OK) on a remote end (client-side). Meaning that it's like double-clicking on an exe file in your desktop and the application appearing on someone else's pc. Unless I am wrong and the actual call to this MessageBox is translated to a client-side MessageBox. Although I doubt it.

    Besides, why would you want the user to go back to the server to display a messagebox that can easily be created by his/her browser. It would be an expensive call.

    My opinion is that it is not correct.

    Hi Zeigon again :)
    Yes, I'm agree with you too, you pointed to a good idea, but as you see the OP wants it not me ;)

    My Blog - MSDN Complement by providing Visual C# Walkthroughs and Sample Codes - Founded In February 24, 2010
    Thursday, March 4, 2010 7:35 PM
  • I restart IIS but still the same problem. I find out after I click the button, the page would kind of like refresh and then show the top of the page again, since my  button is at the bottom so I can see that. As I said, I even copy all the codes to another aspx page but the problem would still exist, I think it is something about my code.

    Here is my html code for that page:
    <%@ Page language="c#" Codebehind="order.aspx.cs" AutoEventWireup="false" Inherits="staffsalesystem.order" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    	<HEAD>
    		<title>Staff Sale System Order</title>
    		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
    		<meta content="C#" name="CODE_LANGUAGE">
    		<meta content="JavaScript" name="vs_defaultClientScript">
    		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    	</HEAD>
    	<body MS_POSITIONING="GridLayout">
    		<form id="Form1" method="post" runat="server">
    			<DIV style="align: center" align="center"><FONT face="新細明體">Staff Sale System
    					<br>
    					Order Page
    					<br>
    					<asp:label id="stafflabel" style="Z-INDEX: 101; LEFT: 88px; TOP: 272px" runat="server" Width="136px"
    						Height="24px"></asp:label><br>
    					<asp:hyperlink id="r_lnklogout" runat="server" Width="56px" NavigateUrl="login.aspx" Target="_parent"
    						Font-Names="新細明體">Logout</asp:hyperlink><br>
    					<asp:datagrid id="DataGrid1" runat="server" Width="432px" Height="184px" BorderColor="#CC9966"
    						BorderStyle="Dashed" BorderWidth="1px" BackColor="White" CellPadding="4" AutoGenerateColumns="False">
    						<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
    						<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
    						<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
    						<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
    						<Columns>
    							<asp:TemplateColumn>
    								<HeaderTemplate>
    									Order
    								</HeaderTemplate>
    								<ItemTemplate>
    									<asp:CheckBox id="OrderCheckBox" runat="server"></asp:CheckBox>
    								</ItemTemplate>
    							</asp:TemplateColumn>
    							<asp:TemplateColumn>
    								<HeaderTemplate>
    									Order Quantity
    								</HeaderTemplate>
    								<ItemTemplate>
    									<asp:DropDownList id="OrderQuantity" runat="server">
    										<asp:ListItem Value="1">1</asp:ListItem>
    										<asp:ListItem Value="2">2</asp:ListItem>
    										<asp:ListItem Value="3">3</asp:ListItem>
    										<asp:ListItem Value="4">4</asp:ListItem>
    										<asp:ListItem Value="5">5</asp:ListItem>
    										<asp:ListItem Value="6">6</asp:ListItem>
    										<asp:ListItem Value="7">7</asp:ListItem>
    										<asp:ListItem Value="8">8</asp:ListItem>
    										<asp:ListItem Value="9">9</asp:ListItem>
    										<asp:ListItem Value="10">10</asp:ListItem>
    									</asp:DropDownList>
    								</ItemTemplate>
    							</asp:TemplateColumn>
    							<asp:BoundColumn DataField="Code" HeaderText="Product Code"></asp:BoundColumn>
    							<asp:BoundColumn DataField="name" HeaderText="Product Name"></asp:BoundColumn>
    							<asp:BoundColumn DataField="Description" HeaderText="Description">
    								<ItemStyle Width="50px"></ItemStyle>
    							</asp:BoundColumn>
    							<asp:BoundColumn DataField="Price" HeaderText="Price"></asp:BoundColumn>
    							<asp:BoundColumn DataField="quantity" HeaderText="Quantity"></asp:BoundColumn>
    							<asp:BoundColumn DataField="quantityremain" HeaderText="Open Quantity"></asp:BoundColumn>
    						</Columns>
    						<PagerStyle HorizontalAlign="Center" ForeColor="#330099" BackColor="#FFFFCC"></PagerStyle>
    					</asp:datagrid><asp:button id="OrderButton" style="Z-INDEX: 101; LEFT: 248px; TOP: 272px" runat="server" Width="120px"
    						Height="32px" Text="Order"></asp:button>
    					<asp:Button id="Button1" runat="server" Text="Button"></asp:Button><br>
    					<asp:hyperlink id="Hyperlink2" runat="server" Width="90px" NavigateUrl="orderrecord.aspx" Target="_parent"
    						Font-Names="新細明體">Order Record</asp:hyperlink><br>
    					<br>
    					<DIV><FONT face="新細明體">
    							<DIV><FONT face="新細明體"></FONT></DIV>
    						</FONT>
    					</DIV>
    					<asp:hyperlink id="bid" runat="server" Width="90px" NavigateUrl="bid.aspx" Target="_parent" Font-Names="新細明體">Bid</asp:hyperlink></FONT></DIV>
    		</form>
    		</FONT>
    		<DIV><FONT face="新細明體">
    				<DIV><FONT face="新細明體"></FONT>&nbsp;</DIV>
    			</FONT>
    		</DIV>
    		</FORM>
    	</body>
    </HTML>

    it is  button1 that is not working. No matter I delete this one, recreate another one, rename it or do what, anyway second button of this page would not work.
    Friday, March 5, 2010 1:39 AM
  • I find out why.finally!!!!
    thanks for everyone tried to find out a solution!

    the problem is
    in the
    private void InitializeComponent()
            {
    //I have this:
    this.OrderButton.Click += new System.EventHandler(this.OrderButton_Click);
    }         

    but I don't have this:
      this.Button1.Click += new System.EventHandler(this.Button1_Click);

    but I have no idea what does this syntax does. Any idea?
    Friday, March 5, 2010 1:53 AM
  • it will create the click event to then Button Button1 and the event name is Button1_Click
    Friday, March 5, 2010 3:30 AM
  • That is hooking up the Event Handler to the button's click event. I am surprised it didnt come automatically. Can you check on the Page declaration (top of the .aspx page)  if the AutoEventWireup property is set to true.
    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
    Friday, March 5, 2010 5:56 AM