Solved

Passing the dropdown value to another page by javascript

Posted on 2006-11-03
12
266 Views
Last Modified: 2007-02-03
Hi,
I have asp.net page with a dropdown list and two textboxes.These text boxes have a Required field validator and cannot be left empty.Plus this page has got a button called view.Now the problem i am facing is that after i select a value from  a drop down and press view button i should be able to pass the value to the dropdown to the other page dropdown which im able to do using the session.But if the textboxes are left empty and the button view is clicked  then the reqd field validators does not the redirection...even on click event of the button im using the javascript still the reqd fld validators are enabled.I dont know how to get the solution for this problem and if some one can help me ..tht wud be appreciated.
Thanks,
0
Comment
Question by:aspnetdev
12 Comments
 
LVL 27

Expert Comment

by:Sammy
ID: 17872414
Your question is not clear,
You have a dropdown list and 2 textboxes with required validators on the textboxes?
if you dont want the validation to take place you can set its CausesValidation to false. if thats not what you want can you explain the reason behind the validators on the textboxes ?

Sammy

0
 
LVL 7

Expert Comment

by:mjmarlow
ID: 17872817
Is this ASP.Net 1.x or ASP.NET 2?
0
 

Author Comment

by:aspnetdev
ID: 17873265
well, i knew my question is not clear...anyways heres the detailed descp.
In Page1 i have a dropdown list to select country,a textbox to type in code and another textbox to type in description and then i have 2 buttons Save and ViewCountry.btnSave from begning was a server control which when clicked saves the typed in information and show javascript alert saying that save was successful.
Now ddl and the two text boxes all have reqd fld validators since they cannot be left empty.
The ViewCountry when clicked redirects to new page called country.aspx and again the new page (ie) country.aspx has a ddl which on load has selected value same as the value from the ddl from page1.aspx.
Now my problem:
1)I cannot remove Reqd fld vldtrs from page1.aspx as it has to be there.
2)I want to go to Country.aspx page from page1.aspx even if the textboxes on page1.aspx are empty and set the value of ddl on country.aspx same as the page1.aspx.
  ** if i make the viewcountry button a html button and onclick="window.location.href('Country.aspx)" i cannot pass the selected value of the dropdown of page1.aspx to country.aspx as a session....
** if i make this html button runat="server " and add following code on the code behind on clickevent

private void btnView_ServerClick(object sender, System.EventArgs e)
{
   Session["FromView"] = ddlCountry.SelectedValue;
   string ViewScript = "<script language='javascript'>" +
   string.Format ("window.location.href('country.aspx?Country={0}');</script>", ddlCountry.SelectedItem.Text);
   Page.RegisterStartupScript("Viewscript",ViewScript);
 }

then the required fld validators get enabled....and i cannot go to country.aspx with empty txtboxes...
then what i tried is i kept the btnView as html control and on html code of this button added  onclick=history.go(-1)
it wokrs good but once uset does a save and javascript window for successful save is prompted and when user tries to click btnview it keeps on same page ,but if u click the btn twice we go to the country.aspx page if i make onclick="history.go(-2)" and if user does not do a save and click btn view then it takes back sowhere else even though after save it does whts it expected to do....phew!i knw it really confusing but this is a wierd pbm ....and yes if ppbm were not to be weird i wudnt have been on EE askin help for Experts :)
thanks

0
 

Author Comment

by:aspnetdev
ID: 17873740
its asp.net 1.x
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:Sammy
ID: 17876202
Okays, this was a very interesting question :)
good news is it can be done easy with a little bit of clientscript

put this in the head of the aspx page
<script type="text/javascript">
    function IgnoreValidator()
    {
    document.getElementById("TextBox1").value="."; //Note there is a .  in the textboxes
    document.getElementById("TextBox2").value=".";
    return true;
    }
    </script>

In the page_load do this
if (!IsPostBack)
        {
            this.btnView.Attributes.Add("onclick", "javascript:IgnoreValidator();");
        }

private void btnView_ServerClick(object sender, System.EventArgs e)
{
   Session["FromView"] = ddlCountry.SelectedValue;
  Response.Redirect("ountry.aspx?Country=" + ddlCountry.SelectedItem.Text);
//You still can use your script if you want to
 }

Now to explain this process
when the user clicks on the view button the client script will use . for each textbox to stop the requiredvalidator from stopping the process then proceed to button on click event so you can write your session and move to the other page. user will not even see the . the textboxes since the redirect will take effect instantly.

Good luck

Sammy

0
 

Author Comment

by:aspnetdev
ID: 17876740
Thanks Sammy for the prompt reply and the solution,but i forgot to add one more intresting
dimension to the problem and that is ,
I have a button called "Edit" on the Country.aspx page and when btnEdit is clicked it redirects to Page1.aspx along with session called Session["Edit"] which holds the value of ddlCountry and two other(of Country.aspx).When on Page1.aspx i retrieve the values of Session["Edit"] and set the value of ddclcoutnry and two other text boxes on page1.aspx.Now
if we are presetting the values to "." as ur solution suggest using the javascript it overwrites the Edit values.Actually this page1.aspx can be accessed independantly (in which ur
solution works perfect since the ddl and text boxes are unselected and empty ) and aslo thru a button called "Edit" from coutnry.aspx which passes the selected values to be edited and sets them accordingly on page1.aspx....so another scene added ...plz help me outta this cunfusion...which wud be appreciated ...
Thanks,
aspnetdev

"Its not about points its about the CHALLENGE" :) --Cheers
0
 
LVL 27

Accepted Solution

by:
Sammy earned 500 total points
ID: 17877839
then have the client check if there is a value in the textboxes, if Yes leave them alone and if not value assign the .
<script type="text/javascript">
    function IgnoreValidator()
    {
  if((document.getElementById("TextBox1").value.length==0) || (document.getElementById("TextBox1").value==null))
  {
     document.getElementById("TextBox1").value=".";
   }
    if((document.getElementById("TextBox2").value.length==0) || (document.getElementById("TextBox2").value==null))
  {
  document.getElementById("TextBox2").value=".";
   }
    return true;
    }
    </script>

This way nothing will be overriden
0
 
LVL 4

Expert Comment

by:satish_nagdev
ID: 17878527
hi,
first of all quick question is that the case that you want selected value of country dropdown in country.asxp? if yes you could use a simple html button no need or runat=server. i m not sure why are storing value of ddlcountry in session.

you could change you btnview to htm in .aspx file i.e. html source

<input type=button onClick="javascript:loadWindow();" value="sometext"/>

javascript //
function loadWindow()
{
     var vv = window.open('country.aspx?country='+document.all.ddlCountry.options[document.all.ddlCountry.selectedIndex].text,'location=0|1');
     //location specifies to open in new or current window.
}

now if you want to store value of selected country in session you can do it in country.aspx page load this way

Session["FromView"] = Request.QueryString["country"];

hope it helps.

regards,
satish.
0
 

Author Comment

by:aspnetdev
ID: 17891372
Thanks Guys for your prompt help...someother issue came up before this so was not able to test and any change in the code is screwing up whole application  ...as soon as im done will update with points ...thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Please explain: Aspect Oriented Programming 2 84
Registering DLL 5 43
Runtime Error 2 28
How to have a gridview column with multiple items in a column row. 2 12
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now