我有一个 aspx 页面,它会在按钮单击时动态更新。正在将带有按钮的表格添加到占位符中。每个按钮都应该重定向到另一个页面,在查询字符串中发送它的 id。
我遇到的问题是,当单击每个按钮时,会发生回发并且按钮不会再次添加到页面中(因为该方法是通过单击按钮运行的),因此事件触发的函数没有运行
我试图将除占位符之外的所有内容都放在更新面板中,但是首先没有添加表格。如何从页面加载中再次调用 btn_click 函数?我应该在它的参数中传递什么?或者我可以添加不会导致回发的按钮?
这是aspx:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h1 style="text-align:center;">חיפוש חברים</h1>
<br />
<table>
<tr><td>אזור עבודה מועדף</td>
<td>סיווג משני</td>
<td>סיווג ראשי</td>
<td>שם משפחה</td>
<td>שם</td>
<td>תז</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="working_area" CssClass="wid" runat="server">
<%--some items--%>
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="d_d_second" CssClass="wid" runat="server">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="d_d_main" CssClass="wid" runat="server">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
<td><asp:TextBox ID="m_l_name" CssClass="wid" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="m_name" CssClass="wid" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="m_id" CssClass="wid" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="text-align:left"><asp:Button ID="search" CssClass="btn btn-primary"
runat="server" Text="חפש" onclick="search_Click" /></td>
</tr>
</table>
<asp:PlaceHolder ID="search_tbl_ph" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
这是后面的代码:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void search_Click(object sender, EventArgs e)
{
search_category s1 = new search_category();
s1.id = m_id.Text;
s1.name = m_name.Text;
s1.l_name = m_l_name.Text;
s1.main_cat = d_d_main.SelectedValue;
s1.second_cat = d_d_second.SelectedValue;
s1.working_area = working_area.SelectedValue;
List<member> m_list = db.return_search_member(s1);
Table m_tbl = new Table();
TableRow r2 = new TableRow();
TableCell c7 = new TableCell();
TableCell c8 = new TableCell();
TableCell c9 = new TableCell();
TableCell c10 = new TableCell();
TableCell c11 = new TableCell();
TableCell c12 = new TableCell();
c7.Text = "תז";
c8.Text="שם פרטי";
c9.Text="שם משפחה";
c10.Text="סיווג ראשי";
c11.Text="סיווג משני";
r2.Controls.Add(c12);
r2.Controls.Add(c11);
r2.Controls.Add(c10);
r2.Controls.Add(c9);
r2.Controls.Add(c8);
r2.Controls.Add(c7);
r2.CssClass = " head_line";
m_tbl.Controls.Add(r2);
foreach (member m1 in m_list)
{
TableRow r1 = new TableRow();
TableCell c1 = new TableCell();
TableCell c2 = new TableCell();
TableCell c3 = new TableCell();
TableCell c4 = new TableCell();
TableCell c5 = new TableCell();
TableCell c6 = new TableCell();
Button btn1 = new Button { Text = "עבור לכרטיס חבר", CommandArgument = "argument", ID = m1.id };
btn1.Click += new EventHandler(btn_click);
btn1.CssClass = "btn btn-primary";
c1.Controls.Add(btn1);
c2.Text = m1.prof.secondary;
c3.Text = m1.prof.primary;
c4.Text = m1.l_name;
c5.Text = m1.f_name;
c6.Text = m1.id;
r1.Controls.Add(c1);
r1.Controls.Add(c2);
r1.Controls.Add(c3);
r1.Controls.Add(c4);
r1.Controls.Add(c5);
r1.Controls.Add(c6);
m_tbl.Controls.Add(r1);
}
search_tbl_ph.Controls.Add(m_tbl);
}
protected void btn_click(object sender, EventArgs e)
{
Button btn = (Button)sender;
String member_id = btn.ID;
string qstring = "?id=" + member_id;
Response.Redirect("member_page.aspx" + qstring);
//Session["id"] = qstring;
}