Igor

Igor

  • NA
  • 16
  • 0

Why HiddenField in UserControl get the same Id

Mar 31 2009 8:09 PM
In Investor.aspx page, the DataList1 is binded. The DataList1 has UserControl that get parameter "DistId" which is used for futher when I click on hlOpenDoc.
Because I can't set "onclick" attribute to HyperLink, that would be procceeded on server, I created hidden button "
btnSetEvent " that is clicked from javascript.
At this moment "
btnSetEvent" is vissible only for the purpose of understanding my porblm.
The problem:
When I click on hlOpenDoc(that is in UserControl) I noticed that hfDistID has the same DistId regardless on which row I click the button
hlOpenDoc.
But when I click on
"btnSetEvent" the hfDistID control has correct value that depends on which row I clicked.
Why it is happens?
Thank you.

Investor.aspx
<asp:DataList ID="DataList1" runat="server" CellSpacing="4" Width="545px" DataSourceID="SqlHanpakot">
<ItemStyle BackColor="LightGray" BorderColor="Transparent" Height="20px" />
<SeparatorStyle BackColor="Transparent" BorderColor="Transparent" />
<ItemTemplate>
<table style="width: 100%">
<tr>
<td style="width: 55px; height: 38px; background-position: center center; text-align: center;">
<uc:OpenDoc DistID='<%# Eval("DistId") %>' NavigateUrl='<%# Eval("sDocPath")+"#pagemode=thumbs" %>' ID="OpenDoc1" runat="server"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList><

user control(OpenDoc.ascx)
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OpenDoc.ascx.cs" Inherits="OpenDoc" %>
<script type="text/javascript">
function setEvent() {
document.getElementsByName('<%= btnSetEvent.UniqueID %>')[0].click();
}
</script>
<asp:HyperLink ID="hlOpenDoc" runat="server"
Font-Names="Arial"
Font-Size="10pt"
Font-Underline="False"
ForeColor="Green"
Width="93px"
Target="_blank"
onclick="setEvent();">Open document</asp:HyperLink>

<asp:HiddenField ID="hfDistID" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Button ID="btnSetEvent" runat="server"
Text="Button"
onclick="btnSetEvent_Click"/>
</ContentTemplate>
</asp:UpdatePanel>

code behind(OpenDoc.ascx.cs)
public partial class OpenDoc : System.Web.UI.UserControl
{
public string NavigateUrl
{
set
{
hlOpenDoc.NavigateUrl = value;
}
}

public string DistID
{
set
{
hfDistID.Value = value;
}
}

protected void Page_Load(object sender, EventArgs e)
{

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

}
}