473,545 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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:HiddenFiel d...for example, I have to do something
like this:

<% fieldID.Value = "stringCont ent" %>
<asp:HiddenFiel d ID="fieldID"></asp:HiddenField >

so I'm guessing I can do the same kind of thing for the form control,
but "myForm.Act ion" 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 <formtag, 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=serverlin e
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
Aug 23 '06 #1
4 2892
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" <ke**********@L OLgmail.comwrot e in message
news:u1******** ******@TK2MSFTN GP04.phx.gbl...
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:HiddenFiel d...for example, I have to do something like
this:

<% fieldID.Value = "stringCont ent" %>
<asp:HiddenFiel d ID="fieldID"></asp:HiddenField >

so I'm guessing I can do the same kind of thing for the form control, but
"myForm.Act ion" 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 <formtag, 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=serverlin e 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

Aug 24 '06 #2
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="Bu tton.PostBackUr lPage2cs.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.postbac kurl = myURL;
}
else
{
Button2.Text = "go to myOtherURL";
Button2.postbac kurl = myOtherURL
}
<asp:button id="Button2" runat="Server">
</asp:button>

and if so, should I use ".PostBackU rl", "PostBackUR L", "postbackur l" 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)
Aug 24 '06 #3
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.
Aug 24 '06 #4
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" <ke**********@L OLgmail.comwrot e in message
news:u1******** ******@TK2MSFTN GP04.phx.gbl...
>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:HiddenFiel d...for example, I have to do something like
this:

<% fieldID.Value = "stringCont ent" %>
<asp:HiddenFie ld 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 <formtag, 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=serverlin e 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.Tex t = "this is the button text";
EventSubmit.Pos tBackUrl = "/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
Aug 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9375
by: Michael | last post by:
There seem to be two ways to include files on the server: 1. <!-- #include file="header.inc" --> 2. <script language="VBScript" runat="server" src="header.inc"></script> What are the differences between the two, and when to use one instead of the other? Thanks.
1
1738
by: Hai Nguyen | last post by:
Hi all I have a several User Controls which require this tag: "<form runat="server">. I tried to have all of these user user controls on the same web page. It kept giving me an error :""A page can have only one server-side Form tag" Is there a way to go around this?
4
4257
by: Tim Mulholland | last post by:
I have one page where i have some <div> tags set to be runat="server" (and i've given them an id) and i can access them from the code-behind file just fine. I have another page where i've done essentially the same thing (even copying the code from the other file) and i cannot access them from the code-behind file. Any clues what would...
3
5512
by: Jaime Stuardo | last post by:
Hi all... Both controls are server side. The former has more properties. Both may have associated events that are ran at server. Which one are recommended to use? is performance an issue? in what case I can (or must) use the second? If I want an input control that has specific font or color, I can use client side <input> so I'm...
3
3482
by: Jim in Arizona | last post by:
Most of the asp.net learning I've done has been from books that were written during the 1.0 framework. I didn't have a copy of visual studio when I started reading them then I got a hold of VS 2005 Beta 1, then Beta 2. I was using the <div runat="server"> statement on my projects. Once I placed a <div id="testdiv" runat="server"> within my...
0
981
by: uto | last post by:
<uc1:uc_pager ID="Uc_pager1" runat="server" CurrentPage="<%=page%>" PageCount="<%=pageCount%>" PageSize="<%=pageSize%>" /> i'd like to input data into usercontrol when page loading but this <%= %> tag does't work how can i change this tage to work it?
0
1586
by: Tom | last post by:
I need to use DynamicHoverStyle. I read that in order to do so, I must add a <head runat="server" /> at the top of my UserCOntrol. When I do this though, my DynamicMenuItemStyle items get changed. If I take the <head runat="server" /> out of my userControl, my DynamicMenuItemStyle are fine. I tried it using a CSS file and class and a...
1
2411
by: mark4asp | last post by:
<form runat="server"automatically adds <divtag to code contained within. Is there a way to stop that? Mixing block-level elements with inline-level elements messes up the HTML becasuse that is invalid for a strict implementation. <spanis in-line-level and <divis block-level. I don't want to mix up <span> and <div> I'm using an...
19
11211
by: Scott M. | last post by:
Why do we need runat="server" on our <headtags?
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7803
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5965
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5322
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1871
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.