Tuesday, March 13, 2012

Stuck on debugging problem on ASP.net 2.0 using VS 2005

It really make me crazy, I put a breakpoint on line 1, when the debugging process started, it should be expected to loop through 1 to 4 step by step on pressing F10, however, it is really really weird that the pointer is jump to line 3 after I press F10, and then line 2 and then go back to line 3, line 4 and back to line 2 ... It is different for every time, sometimes it loops through the whole procedure, but then jump back to the top of the procedure and loops one more time, sometimes it is normal to loop through the procedure just one time ONLY. Does anyone get any idea what is actually happening here?

Thanks if there is any kind reply.

protected void XXX (object sender, EventArgs e)

{

1<-- breakpoint

2

3

4

}

F10 steps over, that's why it's skipping parts of your code. You should use F11 to go step by step.
depends on how the loop is constructed , what the values are that control the loop, etc..
- post the actual code - then we could help more
.
If there are any control structures in your loop code, this would happen. If you don't have any control structures in your code, F10should just go line by line. One other possibility is that the executable you are debugging and the code are out of sync. Try doing a rebuild and see if that resolves the issue.

protected void CompanyListGridView_SelectedIndexChanged(object sender, EventArgs e)
{
// Disable error message since the user has selected the company
lblErrorMessage.Visible = false;

// Clear manufacturing order list
Clear_ManufacturingOrderEntryList();
Clear_DestinationList();
Clear_DepartmentList();

if (CompanyListGridView.SelectedDataKey == null)
return;

// Get company ID
long COM_ID = Convert.ToInt64(CompanyListGridView.SelectedDataKey.Value);

Company COMPANY = Company.GetCompaniesByCompanyID(COM_ID);

if (COMPANY == null)
return;

// Show details on textboxes
txtCOM_ID.Text = String.Format("{0:LF0000}", COMPANY.COM_ID);
txtCOM_CHT.Text = COMPANY.COM_FN;
txtMO_POD.Text = DateTime.Now.ToShortDateString();
//txtMO_PO.Text = "Plese Input PO Number";
txtMO_DD.Text = DateTime.Now.AddDays(7).ToShortDateString();

// Enable textboxes for input
txtMO_PROJ.Enabled = txtMO_HD.Enabled = txtMO_PO.Enabled = txtMO_POD.Enabled = txtMO_DD.Enabled = true;
txtMO_REM.Enabled = ddlMO_DEST.Enabled = ddlMO_DEPT.Enabled = true;

// Show create and cancel buttons
btnCreateMO.Visible = btnCancelMO.Visible = true;

// Bind drop down list
Bind_DestinationList(COM_ID);
Bind_DepartmentList();
Bind_ComDeptList(COM_ID);

// Hide Customer List
CustomerListFieldset.Visible = false;
}

This is the procedure I wrote, when I click on one of the row in Company List Gridview, then this function will be triggered. I tested it yesterday, no problem has been found. But I run this today, the problem is appeared again. The cursor jumps around the code without order, and the second time I test it, it loops through twice continuously.

Thanks for all kindly help.


Is this a problem of visual studio 2005 ? or ASP.net 2.0 or my fault ?


It sounds like this method is getting triggered twice. You might check to make sure that this method is not registered with more than one event. Also check for code elsewhere on the page that could cause the method to be manually called.

If you are using Visual Studio, you might take a look at the stack as you are walking through the code and see what caused the method to be called each time you take a step. If the parent method on the stack that caused the method to be called is changing, that is probably what is happening.

To open the call stack window, go to Debug -> Windows -> Callstack


The stack is showing the following message

App_Web_dqqvphy9.dll!Erms_MO01.CompanyListGridView_SelectedIndexChanged(object sender = {System.Web.UI.WebControls.GridView}, System.EventArgs e = {System.EventArgs}) Line 74

Only one message is showing until debugging process for the procedure is finished


Hmm. That is the only thing in the stack? Nothing higher?

Tell you what. Post the XML for your GridView. I'd also like to see your Page_Load method in the code behind.


<td nowrap style="vertical-align:top">
<fieldset id="CustomerListFieldset" runat="server" visible="false">
<legend>Customer List</legend>
<br />
<asp:ObjectDataSource ID="CompanyListDataSource" runat="server" TypeName="Erms.BusinessLogicLayer.Company"
SelectMethod="GetAllCompanies">
</asp:ObjectDataSource>
<asp:GridView ID="CompanyListGridView" runat="server" DataSourceID="CompanyListDataSource" DataKeyNames="COM_ID"
AutoGenerateColumns="False" GridLines="None" ShowHeader="false" ShowFooter="false" OnSelectedIndexChanged="CompanyListGridView_SelectedIndexChanged" >
<Columns>
<asp:CommandField ButtonType="Image" ShowSelectButton="true" SelectImageUrl="images/BtnIconEdit.gif" />
<asp:TemplateField>
<ItemStyle Wrap="false" />
<ItemTemplate>
<%# String.Format("{0:LF0000}", DataBinder.Eval(Container.DataItem, "COM_ID")) %>
<%# DataBinder.Eval(Container.DataItem, "COM_FN") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" wrap="false" />
<EmptyDataTemplate>
<asp:Label ID="Lable1" runat="server">There is no company record in list</asp:Label>
</EmptyDataTemplate>
</asp:GridView>
<br />
</fieldset>

</td>

// My Page_Load code behind is also empty

protected void Page_Load(object sender, EventArgs e) {}

==========================================

Since I used object data source for company list gridview data binding, so there is no method I should have to specify in page load. When the page loads, the gridview will bind to the data

ummm ... there are a lot of different patterns to load the procedure

1. Loops through the whole procedure twice if I click on the company list gridview

2. Normally loops through the whole procedure one time ONLY

3. Load 2 times for each line, that means when I press F10, it goes to first line --> F10 --> First line --> F10 -->

Second line --> F10 --> Second line --> F10 --> Third line --> F10 --> Third line ... until the end of the procedure

4. Randomly jump between lines but actually it does have pattern

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

First, it goes to line 1, line 2, line 3, line 4 and then line 1, line 5, line 2, line 6, line 3, line 7, line 8, line 5 ..... ~_~"

it really really make me crazy and I can't write for the following things ... HELP PLEASE

0 comments:

Post a Comment