c# how to execute code and then submit a form

Discussion in 'ASP .Net' started by j1dopeman@gmail.com, Jun 18, 2008.

  1. Guest

    Hi,

    I'd like to use a button to save and then submit a form. I can set
    the onlick of the button to mahButton_click or submit, but I can't
    figure out how to do both.

    It looks like c# can't call a form's submit. I've found how to post
    programatically, but I need to use the form's target attribute so that
    the response goes into another frame, and I can't figure out how to do
    that programatically.

    I looking into using javascript to call the c# method and then submit,
    but I keep finding that javascript can't call c# methods.

    The timing isn't important, I just need to find a way for the button
    to execute my method and also submit the form. The only way I can
    think of is to use another hidden button that calls my method, and
    have the visible button call a javascript method that will click the
    hidden button and also submit, but this doesn't seem like a very good
    solution. Also, I don't want to write to the page, so using
    response.write in mahButton_click to write out a javascript submit is
    out.

    Any help is very much appreciated.

    Thanks,
    John
     
    , Jun 18, 2008
    #1
    1. Advertising

  2. David Wier Guest

    With one event handler, and using the built in Button control, with ASP.Net,
    you can do any number of things easily.
    Just call the save and then do whatever you need it to do after that.

    Are we talking about an HTML form, or an ASP.Net form?

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    <> wrote in message
    news:...
    > Hi,
    >
    > I'd like to use a button to save and then submit a form. I can set
    > the onlick of the button to mahButton_click or submit, but I can't
    > figure out how to do both.
    >
    > It looks like c# can't call a form's submit. I've found how to post
    > programatically, but I need to use the form's target attribute so that
    > the response goes into another frame, and I can't figure out how to do
    > that programatically.
    >
    > I looking into using javascript to call the c# method and then submit,
    > but I keep finding that javascript can't call c# methods.
    >
    > The timing isn't important, I just need to find a way for the button
    > to execute my method and also submit the form. The only way I can
    > think of is to use another hidden button that calls my method, and
    > have the visible button call a javascript method that will click the
    > hidden button and also submit, but this doesn't seem like a very good
    > solution. Also, I don't want to write to the page, so using
    > response.write in mahButton_click to write out a javascript submit is
    > out.
    >
    > Any help is very much appreciated.
    >
    > Thanks,
    > John
     
    David Wier, Jun 18, 2008
    #2
    1. Advertising

  3. Guest

    I need to submit the form after that, how can I do that? I need to
    submit it through the page so that the target attribute is set, or if
    I do it programmatically I need to make sure the response goes to a
    different frame. I'm using an asp.net form.

    On Jun 18, 12:44 pm, "David Wier" <> wrote:
    > With one event handler, and using the built in Button control, with ASP.Net,
    > you can do any number of things easily.
    > Just call the save and then do whatever you need it to do after that.
    >
    > Are we talking about an HTML form, or an ASP.Net form?
    >
    > David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert .doc/.rtf/.txt to HTML with no
    > bloated markup
    >
    > <> wrote in message
    >
    > news:...
    >
    > > Hi,

    >
    > > I'd like to use a button to save and then submit a form.  I can set
    > > the onlick of the button to mahButton_click or submit, but I can't
    > > figure out how to do both.

    >
    > > It looks like c# can't call a form's submit.  I've found how to post
    > > programatically, but I need to use the form's target attribute so that
    > > the response goes into another frame, and I can't figure out how to do
    > > that programatically.

    >
    > > I looking into using javascript to call the c# method and then submit,
    > > but I keep finding that javascript can't call c# methods.

    >
    > > The timing isn't important, I just need to find a way for the button
    > > to execute my method and also submit the form.  The only way I can
    > > think of is to use another hidden button that calls my method, and
    > > have the visible button call a javascript method that will click the
    > > hidden button and also submit, but this doesn't seem like a very good
    > > solution.  Also, I don't want to write to the page, so using
    > > response.write in mahButton_click to write out a javascript submit is
    > > out.

    >
    > > Any help is very much appreciated.

    >
    > > Thanks,
    > > John
     
    , Jun 18, 2008
    #3
  4. David Wier Guest

    Really, with the ASP.net paradigm, there is no 'submission' of a form, like
    in PHP or Classic ASP days. You should get a 'handle' on the new way ASP.Net
    programming actually works
    This is all Object oriented/Event Driven code.

    Therefore, like I said earlier, with one ASP.Net button (an object), you can
    do however many things you'd like, all in one event (the button click event)
    You can insert/update/delete/search data, and then anything else - like
    maybe redirecting to another page.

    What exactly do you mean by "I need to submit the form after that.."?

    David Wier
    http://aspnet101.com
    http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
    bloated markup


    <> wrote in message
    news:...
    I need to submit the form after that, how can I do that? I need to
    submit it through the page so that the target attribute is set, or if
    I do it programmatically I need to make sure the response goes to a
    different frame. I'm using an asp.net form.

    On Jun 18, 12:44 pm, "David Wier" <> wrote:
    > With one event handler, and using the built in Button control, with
    > ASP.Net,
    > you can do any number of things easily.
    > Just call the save and then do whatever you need it to do after that.
    >
    > Are we talking about an HTML form, or an ASP.Net form?
    >
    > David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert
    > .doc/.rtf/.txt to HTML with no
    > bloated markup
    >
    > <> wrote in message
    >
    > news:...
    >
    > > Hi,

    >
    > > I'd like to use a button to save and then submit a form. I can set
    > > the onlick of the button to mahButton_click or submit, but I can't
    > > figure out how to do both.

    >
    > > It looks like c# can't call a form's submit. I've found how to post
    > > programatically, but I need to use the form's target attribute so that
    > > the response goes into another frame, and I can't figure out how to do
    > > that programatically.

    >
    > > I looking into using javascript to call the c# method and then submit,
    > > but I keep finding that javascript can't call c# methods.

    >
    > > The timing isn't important, I just need to find a way for the button
    > > to execute my method and also submit the form. The only way I can
    > > think of is to use another hidden button that calls my method, and
    > > have the visible button call a javascript method that will click the
    > > hidden button and also submit, but this doesn't seem like a very good
    > > solution. Also, I don't want to write to the page, so using
    > > response.write in mahButton_click to write out a javascript submit is
    > > out.

    >
    > > Any help is very much appreciated.

    >
    > > Thanks,
    > > John
     
    David Wier, Jun 18, 2008
    #4
  5. Guest

    I need to submit to another page - to post to a different page. The
    action is happening at that other page, and the response is going into
    another frame. That's all I need to do. I'm not rewriting anything,
    I have a few inputs on the form, and I need to submit the form.
    Here's my form:

    <form runat="server" name="mahForm" id="mahForm" method="post"
    action="someOtherPlace/someOtherPage.asp" target="someOtherFrame">

    here's my button:

    <asp:button runat="server" id="mahButton" Text="Hit It"
    OnClick="submit"> or
    <asp:button runat="server" id="mahButton" Text="Hit It"
    OnClick="mahButton_click">
    </form>

    I want to change that or into and. Looks like all I need is a
    semicolon, I'm gonna go ahead and try that out.

    On Jun 18, 1:45 pm, "David Wier" <> wrote:
    > Really, with the ASP.net paradigm, there is no 'submission' of a form, like
    > in PHP or Classic ASP days. You should get a 'handle' on the new way ASP.Net
    > programming actually works
    > This is all Object oriented/Event Driven code.
    >
    > Therefore, like I said earlier, with one ASP.Net button (an object), you can
    > do however many things you'd like, all in one event (the button click event)
    > You can insert/update/delete/search data, and then anything else - like
    > maybe redirecting to another page.
    >
    > What exactly do you mean by "I need to submit the form after that.."?
    >
    > David Wierhttp://aspnet101.comhttp://iWritePro.com- One click PDF, convert .doc/.rtf/.txt to HTML with no
    > bloated markup
    >
    > <> wrote in message
    >
    > news:...
    > I need to submit the form after that, how can I do that?  I need to
    > submit it through the page so that the target attribute is set, or if
    > I do it programmatically I need to make sure the response goes to a
    > different frame.  I'm using an asp.net form.
    >
    > On Jun 18, 12:44 pm, "David Wier" <> wrote:
    >
    > > With one event handler, and using the built in Button control, with
    > > ASP.Net,
    > > you can do any number of things easily.
    > > Just call the save and then do whatever you need it to do after that.

    >
    > > Are we talking about an HTML form, or an ASP.Net form?

    >
    > > David Wierhttp://aspnet101.comhttp://iWritePro.com-One click PDF, convert
    > > .doc/.rtf/.txt to HTML with no
    > > bloated markup

    >
    > > <> wrote in message

    >
    > >news:...

    >
    > > > Hi,

    >
    > > > I'd like to use a button to save and then submit a form. I can set
    > > > the onlick of the button to mahButton_click or submit, but I can't
    > > > figure out how to do both.

    >
    > > > It looks like c# can't call a form's submit. I've found how to post
    > > > programatically, but I need to use the form's target attribute so that
    > > > the response goes into another frame, and I can't figure out how to do
    > > > that programatically.

    >
    > > > I looking into using javascript to call the c# method and then submit,
    > > > but I keep finding that javascript can't call c# methods.

    >
    > > > The timing isn't important, I just need to find a way for the button
    > > > to execute my method and also submit the form. The only way I can
    > > > think of is to use another hidden button that calls my method, and
    > > > have the visible button call a javascript method that will click the
    > > > hidden button and also submit, but this doesn't seem like a very good
    > > > solution. Also, I don't want to write to the page, so using
    > > > response.write in mahButton_click to write out a javascript submit is
    > > > out.

    >
    > > > Any help is very much appreciated.

    >
    > > > Thanks,
    > > > John
     
    , Jun 18, 2008
    #5
  6. Guest

    Nope, if I use a semicolon it tells me that mahButton_click is
    undefined. Such a simple task, and what a pain in the ass it is to
    find out how to do it.

    On Jun 18, 2:09 pm, wrote:
    > I need to submit to another page - to post to a different page.  The
    > action is happening at that other page, and the response is going into
    > another frame.  That's all I need to do.  I'm not rewriting anything,
    > I have a few inputs on the form, and I need to submit the form.
    > Here's my form:
    >
    > <form runat="server" name="mahForm" id="mahForm" method="post"
    > action="someOtherPlace/someOtherPage.asp" target="someOtherFrame">
    >
    > here's my button:
    >
    > <asp:button runat="server" id="mahButton" Text="Hit It"
    > OnClick="submit"> or
    > <asp:button runat="server" id="mahButton" Text="Hit It"
    > OnClick="mahButton_click">
    > </form>
    >
    > I want to change that or into and.  Looks like all I need is a
    > semicolon, I'm gonna go ahead and try that out.
    >
    > On Jun 18, 1:45 pm, "David Wier" <> wrote:
    >
    > > Really, with the ASP.net paradigm, there is no 'submission' of a form, like
    > > in PHP or Classic ASP days. You should get a 'handle' on the new way ASP.Net
    > > programming actually works
    > > This is all Object oriented/Event Driven code.

    >
    > > Therefore, like I said earlier, with one ASP.Net button (an object), you can
    > > do however many things you'd like, all in one event (the button click event)
    > > You can insert/update/delete/search data, and then anything else - like
    > > maybe redirecting to another page.

    >
    > > What exactly do you mean by "I need to submit the form after that.."?

    >
    > > David Wierhttp://aspnet101.comhttp://iWritePro.com-One click PDF, convert .doc/.rtf/.txt to HTML with no
    > > bloated markup

    >
    > > <> wrote in message

    >
    > >news:....
    > > I need to submit the form after that, how can I do that?  I need to
    > > submit it through the page so that the target attribute is set, or if
    > > I do it programmatically I need to make sure the response goes to a
    > > different frame.  I'm using an asp.net form.

    >
    > > On Jun 18, 12:44 pm, "David Wier" <> wrote:

    >
    > > > With one event handler, and using the built in Button control, with
    > > > ASP.Net,
    > > > you can do any number of things easily.
    > > > Just call the save and then do whatever you need it to do after that.

    >
    > > > Are we talking about an HTML form, or an ASP.Net form?

    >
    > > > David Wierhttp://aspnet101.comhttp://iWritePro.com-Oneclick PDF, convert
    > > > .doc/.rtf/.txt to HTML with no
    > > > bloated markup

    >
    > > > <> wrote in message

    >
    > > >news:....

    >
    > > > > Hi,

    >
    > > > > I'd like to use a button to save and then submit a form. I can set
    > > > > the onlick of the button to mahButton_click or submit, but I can't
    > > > > figure out how to do both.

    >
    > > > > It looks like c# can't call a form's submit. I've found how to post
    > > > > programatically, but I need to use the form's target attribute so that
    > > > > the response goes into another frame, and I can't figure out how to do
    > > > > that programatically.

    >
    > > > > I looking into using javascript to call the c# method and then submit,
    > > > > but I keep finding that javascript can't call c# methods.

    >
    > > > > The timing isn't important, I just need to find a way for the button
    > > > > to execute my method and also submit the form. The only way I can
    > > > > think of is to use another hidden button that calls my method, and
    > > > > have the visible button call a javascript method that will click the
    > > > > hidden button and also submit, but this doesn't seem like a very good
    > > > > solution. Also, I don't want to write to the page, so using
    > > > > response.write in mahButton_click to write out a javascript submit is
    > > > > out.

    >
    > > > > Any help is very much appreciated.

    >
    > > > > Thanks,
    > > > > John
     
    , Jun 18, 2008
    #6
  7. Guest

    I ended up using this:

    http://forums.asp.net/p/1080161/1596598.aspx

    to register a script that will submit the form after the postback for
    the button.

    On Jun 18, 2:48 pm, wrote:
    > Nope, if I use a semicolon it tells me that mahButton_click is
    > undefined.  Such a simple task, and what a pain in the ass it is to
    > find out how to do it.
    >
    > On Jun 18, 2:09 pm, wrote:
    >
    > > I need to submit to another page - to post to a different page.  The
    > > action is happening at that other page, and the response is going into
    > > another frame.  That's all I need to do.  I'm not rewriting anything,
    > > I have a few inputs on the form, and I need to submit the form.
    > > Here's my form:

    >
    > > <form runat="server" name="mahForm" id="mahForm" method="post"
    > > action="someOtherPlace/someOtherPage.asp" target="someOtherFrame">

    >
    > > here's my button:

    >
    > > <asp:button runat="server" id="mahButton" Text="Hit It"
    > > OnClick="submit"> or
    > > <asp:button runat="server" id="mahButton" Text="Hit It"
    > > OnClick="mahButton_click">
    > > </form>

    >
    > > I want to change that or into and.  Looks like all I need is a
    > > semicolon, I'm gonna go ahead and try that out.

    >
    > > On Jun 18, 1:45 pm, "David Wier" <> wrote:

    >
    > > > Really, with the ASP.net paradigm, there is no 'submission' of a form, like
    > > > in PHP or Classic ASP days. You should get a 'handle' on the new way ASP.Net
    > > > programming actually works
    > > > This is all Object oriented/Event Driven code.

    >
    > > > Therefore, like I said earlier, with one ASP.Net button (an object), you can
    > > > do however many things you'd like, all in one event (the button click event)
    > > > You can insert/update/delete/search data, and then anything else - like
    > > > maybe redirecting to another page.

    >
    > > > What exactly do you mean by "I need to submit the form after that.."?

    >
    > > > David Wierhttp://aspnet101.comhttp://iWritePro.com-Oneclick PDF, convert .doc/.rtf/.txt to HTML with no
    > > > bloated markup

    >
    > > > <> wrote in message

    >
    > > >news:....
    > > > I need to submit the form after that, how can I do that?  I need to
    > > > submit it through the page so that the target attribute is set, or if
    > > > I do it programmatically I need to make sure the response goes to a
    > > > different frame.  I'm using an asp.net form.

    >
    > > > On Jun 18, 12:44 pm, "David Wier" <> wrote:

    >
    > > > > With one event handler, and using the built in Button control, with
    > > > > ASP.Net,
    > > > > you can do any number of things easily.
    > > > > Just call the save and then do whatever you need it to do after that.

    >
    > > > > Are we talking about an HTML form, or an ASP.Net form?

    >
    > > > > David Wierhttp://aspnet101.comhttp://iWritePro.com-OneclickPDF, convert
    > > > > .doc/.rtf/.txt to HTML with no
    > > > > bloated markup

    >
    > > > > <> wrote in message

    >
    > > > >news:....

    >
    > > > > > Hi,

    >
    > > > > > I'd like to use a button to save and then submit a form. I can set
    > > > > > the onlick of the button to mahButton_click or submit, but I can't
    > > > > > figure out how to do both.

    >
    > > > > > It looks like c# can't call a form's submit. I've found how to post
    > > > > > programatically, but I need to use the form's target attribute so that
    > > > > > the response goes into another frame, and I can't figure out how to do
    > > > > > that programatically.

    >
    > > > > > I looking into using javascript to call the c# method and then submit,
    > > > > > but I keep finding that javascript can't call c# methods.

    >
    > > > > > The timing isn't important, I just need to find a way for the button
    > > > > > to execute my method and also submit the form. The only way I can
    > > > > > think of is to use another hidden button that calls my method, and
    > > > > > have the visible button call a javascript method that will click the
    > > > > > hidden button and also submit, but this doesn't seem like a very good
    > > > > > solution. Also, I don't want to write to the page, so using
    > > > > > response.write in mahButton_click to write out a javascript submit is
    > > > > > out.

    >
    > > > > > Any help is very much appreciated.

    >
    > > > > > Thanks,
    > > > > > John
     
    , Jun 19, 2008
    #7
    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. Trevor Braun
    Replies:
    3
    Views:
    5,422
    Trevor Braun
    Apr 17, 2006
  2. Replies:
    0
    Views:
    298
  3. Adam Akhtar
    Replies:
    3
    Views:
    115
    Robert Dober
    Sep 7, 2008
  4. Replies:
    4
    Views:
    546
    cwdjrxyz
    Jan 17, 2006
  5. Replies:
    3
    Views:
    702
Loading...

Share This Page