473,856 Members | 1,571 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 2915
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
9392
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
1769
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
4276
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 cause this? Just a tad frustrating because i can't move forward on this page without
3
5542
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 wondering if there is an advantage to use <input> as
3
3500
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 aspx page, I could then manipulate it in the code behind like so: testdiv.visible = true...
0
992
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
1615
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 Skin, same results.
1
2442
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 <asp:Buttonhere because when it switches to the URL I need to check that the user is in the correct role -...
19
11259
by: Scott M. | last post by:
Why do we need runat="server" on our <headtags?
0
9921
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11065
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10700
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10795
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10390
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7934
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7098
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5763
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4177
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.