control value after submit

Discussion in 'ASP .Net Building Controls' started by psb, Jan 13, 2004.

  1. psb

    psb Guest

    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
     
    psb, Jan 13, 2004
    #1
    1. Advertising

  2. 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



    "psb" <> wrote in message
    news:...
    > 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
    >
    >
     
    Alessandro Zifiglio, Jan 14, 2004
    #2
    1. Advertising

  3. psb

    psb Guest

    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


    "Alessandro Zifiglio" <> wrote in
    message news:qX6Nb.2835$...
    > 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
    >
    >
    >
    > "psb" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    psb, Jan 14, 2004
    #3
  4. 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


    "psb" <> wrote in message
    news:%...
    > 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
    >
    >
    > "Alessandro Zifiglio" <> wrote in
    > message news:qX6Nb.2835$...
    > > 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
    > >
    > >
    > >
    > > "psb" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    Alessandro Zifiglio, Jan 14, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lau Lei Cheong

    HtmlInputFile.value cleared after submit.

    Lau Lei Cheong, May 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,281
    Lau Lei Cheong
    May 19, 2004
  2. domchik
    Replies:
    1
    Views:
    245
    domchik
    Sep 4, 2003
  3. Joel
    Replies:
    3
    Views:
    232
    Randy Webb
    Nov 24, 2004
  4. Man-wai Chang

    submit after value returned from popup window

    Man-wai Chang, Apr 26, 2007, in forum: Javascript
    Replies:
    2
    Views:
    104
    Tom Cole
    Apr 26, 2007
  5. Replies:
    1
    Views:
    177
Loading...

Share This Page