Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.Net Javascript vs. ServerControl

Status
Not open for further replies.

mkohl

Programmer
Feb 22, 2005
82
US
Hi,

I am have a task to convert an asp page to an asp.net page. The problem that I am encountering is a html drop down control. Which is running javascript when the user clicks on a button.

The problem is the javascript is not working. My assumption is because the <form runat=server> will not let it execute. So, I am planning to use a server control ("dropdown combobox") and then redirect the users to different pages.

Anyhow, I Have 4 controls on the web page that are server controls (4 combo boxes) with autopostback = "true"

I have my code working but if the user is redirected to a web page, and the presses the i.e back button my accessories drop down control is not reset. So if the user chooses a different vehicle (different drop down box) then during postback the user is redirected to a unwanted webpage. It appears that even if a user does not click on the "accessories" drop down combo box, it will still execute the code behind even if the user did not click on that control.

Any suggestons?

<mike>
 
Thomas,

I agree with you about using asp.net server controls. 3 Drop downs on my page had to be server controls since each of them are accessing the database. As far as the javascript goes I am not to familiar with javascript and why my code would not execute. I simpily tested the code on a new asp.net page, which had a a form tag with out the attribute runat = "server". and the java script ran fine. But once I put the code on the actual page that I needed it to be.. then the code did not work. My assumption is because the form tag has runat = "server".

I got it working as a server control, but I agree with you that it should be a html control. Here is the Sample code that I have for the drop down: Sample A: Works, this is a test on a new asp.net page: Sample B: Does not work and this is where I need it to be.

Sample A: (works)
<FORM name="Sample" >
<SELECT name="SampleLink">
<OPTION value=" selected>
Accessories
<OPTION value="</SELECT>
&nbsp;&nbsp; <INPUT type="button" name="go" value="Go!" onClick="window.location=document.Sample.SampleLink.options[document.Sample.SampleLink.selectedIndex].value">
</FORM>

Sample B: (does not work)

<SELECT name="SampleLink" method="post" runat="server">
<OPTION value=" selected>
Accessories
<OPTION value="</SELECT>
&nbsp;&nbsp; <INPUT type="button" name="go" value="Go!" onClick="window.location=document.Sample.SampleLink.options[document.Sample.SampleLink.selectedIndex].value">
</FORM>

The only difference between Sample A: and Sample B: is the attributes for form. I tested my page without the runat server attribute, but error I get basically states that I need it because my other controls are running on the server.

Any advice would be greatly appreciated. I have been trying to figure this out for the last fews days. I did get it working using code behind, but I do agree with you that it should not be set up that way.

<mike>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top