?
Solved

Returning a selected value to a page

Posted on 2006-05-04
10
Medium Priority
?
221 Views
Last Modified: 2012-08-13
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
Comment
Question by:russomr
  • 5
  • 5
10 Comments
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16607608
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
 

Author Comment

by:russomr
ID: 16607824
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
 

Author Comment

by:russomr
ID: 16607844
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16607894
you don't have codebehind?
0
 

Author Comment

by:russomr
ID: 16607955
I'm using inline coding.
0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16608021
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
 

Author Comment

by:russomr
ID: 16608182
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
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 2000 total points
ID: 16608295
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
 

Author Comment

by:russomr
ID: 16608645
Yes!  Got it working.  Thank you very much for your time and patience.

0
 
LVL 18

Expert Comment

by:Elvio Lujan
ID: 16609395
;)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question