title: Need a postback handle from a clicked dynamic hyperlink control in ajax
body: <p>The scenario...I have a list of dynamic hyperlink controls on an ajax panel that link directly to a WORD doc located on a share. Clicking any link opens WORD client side (I set the file association to do that so the IE browser doesn't try to open it instead). </p>
  
  <p>LinkButtons won't work because it doesn't do a direct link to the doc from the browser and I don't want server automation or activex, since I want each client to open the doc using their own box as if they had simply clicked on the document itself.</p>
  
  <p>But I need to change an image in an image control once they've clicked on the hyperlink. In other words, I need the link to sit on top of a control that does cause a postback so I can get at the posting controls ID and do my thing. I'm also trying to avoid client side scripting though I'm sure there may be a convoluted way to do that.</p>
  
  <p>Here is the code in the loop that creates the dynamic link. I started with just the hyperlink control, then this code is messing with adding a hyperlink to a label, that's why it's showing as it is:</p>
  
  <pre><code>Label lblWordLink = new Label();
  HyperLink hrefLetter = new HyperLink();
  hrefLetter.Text = items.letterName;                
  hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;
  hrefLetter.ID = "standardLettersHref_" + items.letterName;
  lblWordLink.Text = "&lt;a href='" + hrefLetter.NavigateUrl.ToString() + "'&gt;" + items.letterName + "&lt;/a&gt;" ;                
  tRow.Cells[1].Controls.Add(lblWordLink);
  </code></pre>
  
  <p>I'm looking for a way to let the link open the doc and at the same time postback. Is there a way to layer the link control on top of another control such that the link just links and the control beneath causes a postback?</p>
  
  <p>32U</p>
  
  <p>Fixed: the answer gave the clue. On the server, during dynamic control creation I did:</p>
  
  <pre><code>HyperLink hrefLetter = new HyperLink();
  hrefLetter.ID = "standardLettersHref_" + items.letterName;
  hrefLetter.Text = items.letterName;                
  hrefLetter.NavigateUrl = folderForPackageLetters + items.letterName + wordDocExtension;                               
  hrefLetter.Attributes.Add("OnClick", "letterHrefClick('" + items.letterName + wordDocExtension + "')");
  tRow.Cells[1].Controls.Add(hrefLetter);
  </code></pre>
  
  <p>then client side I pushed a value into a hidden control inside the ajax panel when the hyperlink control was clicked and forced submit:</p>
  
  <pre><code>function letterHrefClick(link) {
    //alert(link);
    form1.hdnLetterClick.value = link;
    form1.submit();
  }
  </code></pre>
  
  <p>After the submit, back on server side, I got the value in the Page_Load event:</p>
  
  <pre><code> string x = hdnLetterClick.Value;
  </code></pre>
  
  <p>nice!</p>
  
  <p>update...
  An even better way to do this... in the javascript postback use:</p>
  
  <pre><code>__doPostBack("hdnLetterClick", "somevalue");
  </code></pre>
  
  <p>then in the codebehind in the Page_Init you can do (not for button or imgbutton):</p>
  
  <pre><code>string postbackControlID = Request.Params.Get("__EVENTTARGET");
  string postbackArgument = Request.Params.Get"__EVENTARGUMENT");
  </code></pre>
  
  <p>to get at what you need. This is better if dealing with dynamic controls so you can control state during control recreation.</p>