post to server using controls or code other than a button

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: post to server using controls or code other than a button

    Don't forget that the client-side script has a Submit() method that can submit
    a form without a button.

    In the following code, I use a literal control to output the Javascript the
    first time. The Javascript inserts the time into the textbox and then submits
    the form. When the page reloads, it displays the time as accepted by the
    textbox and the time of the postback.

    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MyBase.Load
    If Not IsPostBack Then
    Literal1.Text = "<script>document.forms[0].TextBox1.value=" & _
    "'" & Now.TimeOfDay.ToString & "';document.forms[0].submit();</script>"
    Else
    Label2.Text = "I was posted back at: " & Now.TimeOfDay.ToString
    Literal1.Text = ""
    End If
    Label1.Text = TextBox1.Text
    End Sub

    Does this help?

    Ken
    MVP [ASP.NET]


    "Northern" <lifeng26@msn.com> wrote in message
    news:055901c3515d$1ec2ff10$a001280a@phx.gbl...
    If I have a button control that runat=server, then as soon
    as user clicks on the button, server side event handler
    get invoked. I want to have a effect that's similar to
    that, but with other controls. Say, I have a text field.
    What I want is, as soon as my front-end script put a
    string into the text field the form get posted to the
    server and the server side Text changed event get fired.

    Right now, I don't seem to be able to do that. The text
    change on the front-end doesn't trigger a server post. I
    have to wait untill next time some button get pressed then
    the server side detects the changed text and fires my text
    change event handler. This doesn't work for me.

    Can someone show me how to do this?

    Thanks.


    Ken Cox [Microsoft MVP] Guest

  2. Similar Questions and Discussions

    1. Controls that contain code: Code Blocks Not Supported
      How can I develop a custom control that can then be used to display dynamically generated data? I have created a simple custom control which I use...
    2. composite controls... Microsoft Press: Dev ASP.NET Server Controls
      I have the Microsoft Press: Developing Microsoft ASP.NET Server Controls and Components book. It's starting to shine some light on control...
    3. user controls: dynamiclly added child controls dont survive post back ?
      hi, i have some strange behaviour: i've created a web user control that add's some child controls (e.g: textbox, image buttons) to its control...
    4. Disabling a button but calling its server code
      Hi I am trying to create an "Update" button for my form. So far I have got it working fine, posting back and updating the record. Great! ...
    5. Subform Controls (please disregard previous post)
      I have a subform with a variable amount of textboxes. Each textbox should have its own color, depending on the value of the field L3_Status. When...
  3. #2

    Default Re: post to server using controls or code other than a button

    BTW, is Northern your real name? If not, it is polite to sign with one.

    "Northern" <lifeng26@msn.com> wrote in message
    news:055901c3515d$1ec2ff10$a001280a@phx.gbl...
    If I have a button control that runat=server, then as soon
    as user clicks on the button, server side event handler
    get invoked. I want to have a effect that's similar to
    that, but with other controls. Say, I have a text field.
    What I want is, as soon as my front-end script put a
    string into the text field the form get posted to the
    server and the server side Text changed event get fired.

    Right now, I don't seem to be able to do that. The text
    change on the front-end doesn't trigger a server post. I
    have to wait untill next time some button get pressed then
    the server side detects the changed text and fires my text
    change event handler. This doesn't work for me.

    Can someone show me how to do this?

    Thanks.


    Ken Cox [Microsoft MVP] Guest

  4. #3

    Default post to server using controls or code other than a button

    Make sure you set AutoPostBack=true for the control in
    question. That should fix the problem.
    >-----Original Message-----
    >If I have a button control that runat=server, then as
    soon
    >as user clicks on the button, server side event handler
    >get invoked. I want to have a effect that's similar to
    >that, but with other controls. Say, I have a text field.
    >What I want is, as soon as my front-end script put a
    >string into the text field the form get posted to the
    >server and the server side Text changed event get fired.
    >
    >Right now, I don't seem to be able to do that. The text
    >change on the front-end doesn't trigger a server post. I
    >have to wait untill next time some button get pressed
    then
    >the server side detects the changed text and fires my
    text
    >change event handler. This doesn't work for me.
    >
    >Can someone show me how to do this?
    >
    >Thanks.
    >.
    >
    John Kievlan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139