如何将查询字符串值从Aspx页面传递到Ascx页面
问题描述:
在aspx页面中,我正在使用转发器,其中我将命令参数绑定到一个按钮,所以在点击按钮时我需要将值传递给ascx页面(用户控制页面)
In aspx page, i am using repeater in which i have binded command argument to a button, so on the click of the butoon i need to pass value to ascx page (user control page)
<asp:Repeater ID="RptMessage" runat="server">
<ItemTemplate>
<tr>
<td width="99%">
<label>
<table cellpadding="4" cellspacing="2">
<tr>
<td><asp:Button ID="BtnMsg" runat="server" Text="Select" CommandArgument='<%# Eval("templateId")%>' OnClick="select"/>
</td>
<td valign="top">
<strong style="font-size: medium">
<%# Eval("templateName")%>
</strong>
<br />
<br />
<%# Eval("templateText")%></strong>
</td>
</tr>
</table>
</label>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
protected void select(object sender, EventArgs e)
{
Button btnM = (Button)sender;
Response.Redirect("message_send.ascx?Tid=" + btnM.CommandArgument);
}
这不起作用请帮助
This is not working please help
答
您不能重定向到UserControl(ascx扩展名)。 Usercontrol应始终呈现为其添加的父WebPage的一部分。因此,将重定向(也添加查询字符串)添加到使用UserControl /添加的WebPage(父页面)并获取QueryString值。
You cannot do a Redirection to an UserControl ( ascx extension ). Usercontrol should be always rendered as part of the Parent WebPage where its added. So Make the Redirection( also add the querystring) to the WebPage ( Parent Page) where the UserControl is used/Added and fetch the QueryString Value .
您无法重定向。它是一个控制。它用作页面的一部分。
You can not redirect. Its a control. It is used as a part of a page.