开发者

Why is my asp:Button posting back every other time?

I have a user control that has only a text box and a button. When I click the button the page posts back but the button does not appear in the AllKeys attribute of Request.Form. Once the page loads, if I click the button again it does appear in the AllKeys attribute.

On the next attempt, the third click will not have the button, but the fourth click will have it.

I don't know what I am missing or how to approach this. Why would my asp:Button only post back one every other click?

Control Code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchControl.ascx.cs" Inherits="controls.SearchControl" %>
<table style="margin: 0 auto">
   <tr>
     <td style="vertical-align:middle">
        <b>Search ID</b>&nbsp;
        <asp:TextBox ID="txtSearchID" AutoPostBack="true" runat="server" Width="100px"></asp:TextBox>&nbsp;
        <asp:Button ID='btnLoadDetails' OnClick="Search" runat="server" Text='Load Details' />&nbsp;
     </td>
   </tr>
</table>

Control Code Behind:

    public event EventHandler onLoad;
    protected virtual void OnLoad(EventArgs e)
    {
        if (onLoad != null)
        {
            onLoad(this, e);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ( !IsPostBack )
        {
            if ( Request["searchID"] != null && Conversion.StringToInt( Request["searchID"].ToString() ) > 0 )
            {
                txtSearchID.Text = Request["searchID"].ToString();
            }
        }
        else
        {   // Used to see if teh button appears in Request.Form
            String test = Request.Form[btnLoadDetails.ClientID];
        }
    }


    protected void Search(object sender, System.EventArgs e)
    {
        if (txtShopperID.Text.Trim().Length > 0)
        {
            OnLoad(new EventArgs());
        }
    }

Page Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SearchPage.aspx.cs" Inherits="SearchPage" %>    
<%@ Register TagPrefix="search" TagName="searchControl" Src="controls/SearchControl.ascx" %>

<search:searchControl id="searchControl" OnLoad="btnSearch_Click" runat="server" />
<br /开发者_如何学编程>
<div id='divResultInformation' runat="server"></div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜