Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If I DYNAMICALLY add user control how can I read back from it? 1

Status
Not open for further replies.

mb22

Programmer
Sep 4, 2002
258
US
If I add a user control (UC) at design time ... I have no problem reading from the controls in it ...say (text boxes) bcos I create a public property for each text box.

say in my UC i have a TextBox txtfname ...and a property p1_txtfname to read and write to it

Public Property p1_txtfname() As String
Get
Return txtfname.Text
End Get
Set(ByVal Value As String)
txtfname.Text = Value
End Set
End Property


Then in my HOST page suppose my UC id = Namebox... I can grab whatever is entered in the textbox by ....

myfNameInHostPage.Text = Namebox.p1_txtfname

..but this is bcos the UC id=Namebox is available at design time.

But suppose I add the UC dynamically at run-time like ...

Dim control As Control
control = Page.LoadControl("UserControls/Namebox.ascx")
Me.pageContentsCell.Controls.Add(control)

where pageContentsCell is say a table cell .... the page downloads OK ......

how do I read back the same
myfNameInHostPage.Text = Namebox.p1_txtfname

is it like
myfNameInHostPage.Text=control.ID("p1_txtfname") ?

since I don't know what ID will be assigned to the UC?
please help!
 
DazzleD ... the hyperlink is not working ... It looks like I'm getting a javascript error .. it is not posting back at all! What is wrong with my hyperlink javascript? I have it like you suggested!

<asp:datalist id="MenuList" CellPadding="0" runat="server">
<HeaderTemplate>
<IMG alt="" src="Images/DeptHeader.gif">
</HeaderTemplate>
<SelectedItemTemplate>
<asp:HyperLink id=HyperLink2 runat="server" CssClass="MenuSelected" Text='<%# DataBinder.Eval(Container.DataItem, "MenuName") %>' NavigateUrl='<%# "../default.aspx?MenuID=" &amp; DataBinder.Eval(Container.DataItem, "MenuID") &amp; "&amp;MenuIndex=" &amp; Container.ItemIndex %>'>
</asp:HyperLink>
</SelectedItemTemplate>
<FooterTemplate>
<IMG alt="" src="Images/DeptFooter.gif">
</FooterTemplate>
<ItemStyle BackColor="#FFFF80"></ItemStyle>
<ItemTemplate>
<asp:HyperLink id=HyperLink1 runat="server" CssClass="MenuUnselected" Text='<%# DataBinder.Eval(Container.DataItem, "MenuName") %>' NavigateUrl='javascript:document.getElementById("txtHidden").value="<%# "../default.aspx?MenuID=" &amp; DataBinder.Eval(Container.DataItem, "MenuID") &amp; "&amp;MenuIndex=" &amp; Container.ItemIndex %>";document.forms[0].submit()'>
</asp:HyperLink>
</ItemTemplate>
<HeaderStyle BackColor="#FFFF80"></HeaderStyle>
</asp:datalist><INPUT id="txtHidden" style="WIDTH: 93px; HEIGHT: 22px" type="hidden" size="10" runat="server">
 
:D

i'm pretty sure it's because characters get replaced when posted into the forum. lemme try it again:

Code:
NavigateUrl='javascript:document.getElementById("txtHidden").value="../default.aspx?MenuID=<%# DataBinder.Eval(Container.DataItem, "MenuID")%>&MenuIndex=<%# Container.ItemIndex %>";document.forms[0].submit()'

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
thanks DaZZleD .... I needed to have the hidden field on the main hosting page ... not in the User Control ... that is why the JavaScript was failing.

Thanks soo much for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top