views:

24

answers:

1

I have form tag in an ASPX page,

<form id="payForm" method="post" action="<%Response.Write(URL);%>" runat="server">
</form>

On the pageload event,

Literal mylit = new Literal();
mylit.Text = string.Format("<input type=\"hidden\" name=\"{0}\" value=\"{1}\" /> \n", name, value); 
payForm.Controls.Add(mylit);

How do I make my form to submit after adding this control defined in pageload event?

If I write this code

 <script language="javascript" type="text/javascript">
        document.forms["payForm"].submit();
 </script>

then this snipet of code also cannot find the payForm object.

A: 

I don't know if there is a way to submit the form through your server side application, only if it was using the GET method so you could just redirect to the formated url. Think you gonna have to use JS.

document.forms["payForm"].submit() doesn't work because document.forms is not an associative array. You have to use it like this: document.forms[0].submit() where 0 is the index of the form that you want to submit.

And you can also find your form inside the document element with the name attribute of it.

This way: document.nameOfMyForm.submit()

Delta
thnx for your response dear. but problem is when i use runat="server" attribute then document.forms[0].submit() or document.forms["payForm"].submit() does not work at all
SOF User