c# how to execute code and then submit a form

  • Thread starter Thread starter j1dopeman
  • Start date Start date
J

j1dopeman

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


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.
 
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.
 
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.
 
Back
Top