control value after submit

P

psb

QUESTION IS AT BOTTOM...

------------- ASPX -----------------------------------------
<form id="form1" runat="server">
<asp:placeholder id="plhA" runat="server"/>
<input type="submit" id="btnS" runat="server"/>
</form>

-------------------
myControl.ascx ---------------------------------------------
<input type="text" id="txb1" runat="server"/>

-------------- code
behind --------------------------------------------------
function page_load()
if not page.ispostback then
plhA.controls.add(LoadControl("c:\webs\myControl.ascx"))
end if
end function
------------------------------------------
function btnS_Serverclick()
Page.FindControl("txb1") 'IS NOTHING WHY??
plhA.FindControl("txb1") 'IS NOTHING WHY??
request.form("_ctl45_txb1") IS CORRECT!!!
end function

HOW DO I GET THE VALUE OF THE TEXT BOX WITHOUT USING REQUEST.FORM() INSIDE
btnS_Serverclick() FUNCTION???

thanks,
~psb
 
A

Alessandro Zifiglio

I havent tested but this should be working for you.

Dim textbox1 As TextBox
dim myTextboxValue as string
Dim c1 As Control
c1 = LoadControl("myControl.ascx")
textbox1 = c1.FindControl("txb1")
mytextboxvalue = textbox1.text
 
P

psb

first, thanks for replying.

unfortunately, while in the btnS_serverclick(), if I load the control again,
it seems like it initializes it again. like it is loading the control for
the first time. so, the txb1 is not NOTHING, but it is empty. I believe
what I am trying to do is read a dynamically loaded control from the
viewstate. any control dynamically loaded like this is not in the view
state.

again, thanks,
-Paul
 
A

Alessandro Zifiglio

hi paul, it is not retraing the value coz you are loading the control only
the first time. Controls loaded dynamically need to be rebuilt even after
postback. Use the page_load sub, which will fire always, even after
postback. The best places to create dynamic controls and add them to the
controls collection is in the pageInit method or page_load .
Now this should work. When i posted last, I had given your code a quick look
as usual and missed your Page_load method, thought you already knew this. ;)

You have an ispostback check in your page, i guess you are thinking it will
loose its initial values if you reloaded it even after postback, but this is
wrong. It wont loose its value, it will actually maintain its state and work
correctly.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plhA.controls.add(LoadControl("c:\webs\myControl.ascx"))
end sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top