Solved

Passing the dropdown value to another page by javascript

Posted on 2006-11-03
12
264 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

759 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

20 Experts available now in Live!

Get 1:1 Help Now