PC Review


Reply
Thread Tools Rate Thread

How can I dynamically set a <form runat="server"...> action parameter?

 
 
Kevin Blount
Guest
Posts: n/a
 
      23rd Aug 2006
bit long winded this one, so stick with me:

I'm trying to create a form that can go to one of 3 places, depending on
various elements. My form control looks like this:

<form runat="server" ID="myForm" method=POST>

so, first thing: how can I dynamically set the "Action" parameter? I
know that with <asp:HiddenField...> for example, I have to do something
like this:

<% fieldID.Value = "stringContent" %>
<asp:HiddenField ID="fieldID"></asp:HiddenField>

so I'm guessing I can do the same kind of thing for the form control,
but "myForm.Action" doesn't appear to work.

I also tried

<% string myString = "here.aspx" %>
<form runat="server" ID="myForm" method=POST action="<%= myString %>">

but that didn't work either.

Here's the second part:
To get the value of the forms Action, I need to connect to a database,
so I setup a DataTable and grab the data. I figure I need to do this
outside of the <form> tag, so that I can put the value into it's Action,
but I also want to be able to use that DataTable inside the form, but
I've found that anything I setup before the <form runat=server> line
isn't accessible within the form (such as the other fields from the
database for populating the form textboxes.

Can I set up a string, int, DataTable, etc outside the form that can
also be used inside it? If so, please please tell me how

Cheers

Kevin
 
Reply With Quote
 
 
 
 
bruce barker \(sqlwork.com\)
Guest
Posts: n/a
 
      24th Aug 2006
if you are using 2.0, you can set the postback url in a button. in version
one, you need to use cient script.

-- brue (sqlwork.com)


"Kevin Blount" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> bit long winded this one, so stick with me:
>
> I'm trying to create a form that can go to one of 3 places, depending on
> various elements. My form control looks like this:
>
> <form runat="server" ID="myForm" method=POST>
>
> so, first thing: how can I dynamically set the "Action" parameter? I know
> that with <asp:HiddenField...> for example, I have to do something like
> this:
>
> <% fieldID.Value = "stringContent" %>
> <asp:HiddenField ID="fieldID"></asp:HiddenField>
>
> so I'm guessing I can do the same kind of thing for the form control, but
> "myForm.Action" doesn't appear to work.
>
> I also tried
>
> <% string myString = "here.aspx" %>
> <form runat="server" ID="myForm" method=POST action="<%= myString %>">
>
> but that didn't work either.
>
> Here's the second part:
> To get the value of the forms Action, I need to connect to a database, so
> I setup a DataTable and grab the data. I figure I need to do this outside
> of the <form> tag, so that I can put the value into it's Action, but I
> also want to be able to use that DataTable inside the form, but I've found
> that anything I setup before the <form runat=server> line isn't accessible
> within the form (such as the other fields from the database for populating
> the form textboxes.
>
> Can I set up a string, int, DataTable, etc outside the form that can also
> be used inside it? If so, please please tell me how
>
> Cheers
>
> Kevin



 
Reply With Quote
 
Kevin Blount
Guest
Posts: n/a
 
      24th Aug 2006
Bruce: Thanks for the reply. I'm not familiar this the postback url, but
I've done some quick research and found the following example:

<asp:button id="Button2"
text="Post value to another page"
postbackurl="Button.PostBackUrlPage2cs.aspx"
runat="Server">
</asp:button>

Quick question about this code:

Should I be adding a different button for each URL, or can I set this
dynamically in the same way as my asp:HiddenField example, e.g.

<%
if (blah)
{
Button2.Text = "go to myURL";
Button2.postbackurl = myURL;
}
else
{
Button2.Text = "go to myOtherURL";
Button2.postbackurl = myOtherURL
}
<asp:button id="Button2" runat="Server">
</asp:button>

and if so, should I use ".PostBackUrl", "PostBackURL", "postbackurl" or
doesn't it matter (which I doubt)?

Cheers

Kevin


bruce barker (sqlwork.com) wrote:
> if you are using 2.0, you can set the postback url in a button. in version
> one, you need to use cient script.
>
> -- brue (sqlwork.com)

 
Reply With Quote
 
Erik Funkenbusch
Guest
Posts: n/a
 
      24th Aug 2006
On Wed, 23 Aug 2006 15:42:36 -0500, Kevin Blount wrote:

> bit long winded this one, so stick with me:
>
> I'm trying to create a form that can go to one of 3 places, depending on
> various elements. My form control looks like this:


Short answer is, you can't do it.

ASP.NET pages post back to themselves, otherwise there's no way for them to
handle control events.

The longer answer is that ASP.NET 2.0 introduced a way to do postback's to
another page with the button control, but that may not be what you're
looking for.
 
Reply With Quote
 
Kevin Blount
Guest
Posts: n/a
 
      24th Aug 2006
bruce barker (sqlwork.com) wrote:
> if you are using 2.0, you can set the postback url in a button. in version
> one, you need to use cient script.
>
> -- brue (sqlwork.com)
>
>
> "Kevin Blount" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> bit long winded this one, so stick with me:
>>
>> I'm trying to create a form that can go to one of 3 places, depending on
>> various elements. My form control looks like this:
>>
>> <form runat="server" ID="myForm" method=POST>
>>
>> so, first thing: how can I dynamically set the "Action" parameter? I know
>> that with <asp:HiddenField...> for example, I have to do something like
>> this:
>>
>> <% fieldID.Value = "stringContent" %>
>> <asp:HiddenField ID="fieldID"></asp:HiddenField>
>>
>> so I'm guessing I can do the same kind of thing for the form control, but
>> "myForm.Action" doesn't appear to work.
>>
>> I also tried
>>
>> <% string myString = "here.aspx" %>
>> <form runat="server" ID="myForm" method=POST action="<%= myString %>">
>>
>> but that didn't work either.
>>
>> Here's the second part:
>> To get the value of the forms Action, I need to connect to a database, so
>> I setup a DataTable and grab the data. I figure I need to do this outside
>> of the <form> tag, so that I can put the value into it's Action, but I
>> also want to be able to use that DataTable inside the form, but I've found
>> that anything I setup before the <form runat=server> line isn't accessible
>> within the form (such as the other fields from the database for populating
>> the form textboxes.
>>
>> Can I set up a string, int, DataTable, etc outside the form that can also
>> be used inside it? If so, please please tell me how
>>
>> Cheers
>>
>> Kevin

>
>

Bruce,

Thanks again for pointing me in the right direction. Now that I'm back
in the office I've been playing around with PostBackUrl, and I found
that I can dynamically set this, using the following:

<%
EventSubmit.Text = "this is the button text";
EventSubmit.PostBackUrl = "/us/seminars/index.aspx";
%>
<asp:Button ID="EventSubmit" runat="server"></asp:Button>

This will let me set the text based on the translated text from the
database, and also set the resulting URL based on the contents of the
form/page.

Many thanks for the help; I sincerely doubt I would have found this
option if let to my own devices (I'm having to use Dreamweaver for my
aspx pages, which has very limited .NET intelisense)

Kevin
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"...must be placed inside a form tag with runat=server" error Goldenrate Microsoft Dot NET 2 17th Dec 2008 12:24 AM
<form runat="server"> automatically adds <div> tag to code contained within. Is there a way to stop that? mark4asp Microsoft ASP .NET 1 3rd Apr 2007 08:53 AM
Total newbie - form redirect using runat="server" - please help Quinniee Microsoft ASP .NET 10 2nd Mar 2006 10:17 AM
How do I get a form to post to another page when runat="server" is true? COHENMARVIN Microsoft ASP .NET 4 28th Jul 2005 08:52 PM
<input id="iPhoto" type="file" size="20" runat="server"> Mark Sandfox Microsoft ASP .NET 1 11th May 2004 02:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:04 PM.