• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Returning a selected value to a page

I have an ASP.Net 1.1 C# web page that has the following code:

<a href="#" onClick="window.open('FindAgencyPopup.aspx', 'myWin', 'width=600,height=500,scrollbars=1,top=50,left=50,resizable=1,status=1');return false;">Find...</a>
<asp:TextBox id="txtCode" runat="server" CssClass="InputBox" MaxLength="50" />

When someone clicks on 'Find...', a new page pops up (FindAgencyPopup.aspx) that allows a user to search for an agency.  Once the user submits the search, the search results come back in a datagrid.  Datagrid looks like this:

<asp:datagrid id="dgResults" Runat="server" AutoGenerateColumns="False" width="100%" >
      <Columns>
            <asp:TemplateColumn HeaderText="Code">
                  <ItemTemplate>
                        <%# ConvertState(DataBinder.Eval(Container.DataItem, "agy_st").ToString()) %><%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>
                  </ItemTemplate>
            </asp:TemplateColumn>
            <asp:BoundColumn HeaderText="Agency Name" DataField="AgencyName"></asp:BoundColumn>
            <asp:ButtonColumn HeaderText="Select" Text="[Select]" ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>
      </Columns>
</asp:datagrid>

I need the user to be able to click on a 'select' link in that datagrid which will then close the popup page then populate the txtCode textbox.

Does this make sense?  I have a feeling javascript is involved, I'm just not sure on how to go about it.
0
russomr
Asked:
russomr
  • 5
  • 5
1 Solution
 
Elvio Lujan.Net Senior DeveloperCommented:
window.opener.document.getElementById(ctlId).value=id;


<ItemTemplate onclick="window.opener.document.getElementById(txtId).value='yourvalue'; window.close();">
                    <%# ConvertState(DataBinder.Eval(Container.DataItem, "agy_st").ToString()) %><%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>
               </ItemTemplate>

where txtId is the id of the textBox in the parent page, and yourvalue is the new value for it.

Elvio
0
 
russomrAuthor Commented:
I'm a little confused.  Where does the following go:

window.opener.document.getElementById(ctlId).value=id;

Is that somehow used for the Find... link?  You started the post out with this line but didn't say where it goes.

My dg now looks like (txtCode is the name of the textbox):

<asp:datagrid id="dgResults" Runat="server" AutoGenerateColumns="False" width="100%" >
      <Columns>
            <asp:TemplateColumn HeaderText="Code">
                  <ItemTemplate onclick="window.opener.document.getElementById('txtCode').value='<%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>'; window.close();">
                        <%# ConvertState(DataBinder.Eval(Container.DataItem, "agy_st").ToString()) %><%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>
                  </ItemTemplate>
            </asp:TemplateColumn>
            <asp:BoundColumn HeaderText="Agency Name" DataField="AgencyName"></asp:BoundColumn>
            <asp:ButtonColumn HeaderText="Select" Text="[Select]" ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>
      </Columns>
</asp:datagrid>

But I'm getting an error:

Parser Error Message: Content ('<ItemTemplate onclick="window.opener.document.getElementById('txtCode').value='') does not match any properties within a 'System.Web.UI.WebControls.TemplateColumn', make sure it is well-formed.

Also, should it be:

window.opener.document.getElementById('txtCode').value

with apostrophes?  The posted sample did not have them.  I tried with and without but no luck.
0
 
russomrAuthor Commented:
I replaced:

<ItemTemplate onclick="window.opener.document.getElementById('txtCode').value='<%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>'; window.close();">

with

<ItemTemplate onclick="window.opener.document.getElementById('txtCode').value='4'; window.close();">

And now get:

Parser Error Message: Property 'ItemTemplate' does not have a property named 'onclick'.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Elvio Lujan.Net Senior DeveloperCommented:
you don't have codebehind?
0
 
russomrAuthor Commented:
I'm using inline coding.
0
 
Elvio Lujan.Net Senior DeveloperCommented:
ummm...

<ItemTemplate>
                    <span onclick="window.opener.document.getElementById('txtCode').value='<%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>'; window.close();"><%# ConvertState(DataBinder.Eval(Container.DataItem, "agy_st").ToString()) %><%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %></span>
               </ItemTemplate>
0
 
russomrAuthor Commented:
I'm still getting errors on the following:

<asp:datagrid id="dgResults" Runat="server" AutoGenerateColumns="False" width="100%" >
      <Columns>
            <ItemTemplate>
            <span onclick="window.opener.document.getElementById('txtCode').value='4'; window.close();">343434</span>
        </ItemTemplate>
            <asp:BoundColumn HeaderText="Agency Name" DataField="AgencyName"></asp:BoundColumn>
            <asp:ButtonColumn HeaderText="Select" Text="[Select]" ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>
      </Columns>
</asp:datagrid>

Error is:
Parser Error Message: System.Web.UI.WebControls.DataGridColumnCollection must have items of type 'System.Web.UI.WebControls.DataGridColumn'. 'ItemTemplate' is of type 'System.Web.UI.HtmlControls.HtmlGenericControl'.
0
 
Elvio Lujan.Net Senior DeveloperCommented:
this is the way you have to put it
<asp:datagrid id="dgResults" Runat="server" AutoGenerateColumns="False" width="100%" >
     <Columns>
          <asp:TemplateColumn HeaderText="Code">
               <ItemTemplate>
                    <span onclick="window.opener.document.getElementById('txtCode').value='<%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %>'; window.close();"><%# ConvertState(DataBinder.Eval(Container.DataItem, "agy_st").ToString()) %><%# ConvertNumber(DataBinder.Eval(Container.DataItem, "agy_numb").ToString()) %></span>
               </ItemTemplate>
          </asp:TemplateColumn>
          <asp:BoundColumn HeaderText="Agency Name" DataField="AgencyName"></asp:BoundColumn>
          <asp:ButtonColumn HeaderText="Select" Text="[Select]" ButtonType="LinkButton" CommandName="Select"></asp:ButtonColumn>
     </Columns>
</asp:datagrid>
0
 
russomrAuthor Commented:
Yes!  Got it working.  Thank you very much for your time and patience.

0
 
Elvio Lujan.Net Senior DeveloperCommented:
;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now