aspnetdev
asked on
Passing the dropdown value to another page by javascript
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,
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,
Is this ASP.Net 1.x or ASP.NET 2?
ASKER
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.h ref('Count ry.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('co untry.aspx ?Country={ 0}');</scr ipt>", ddlCountry.SelectedItem.Te xt);
Page.RegisterStartupScript ("Viewscri pt",ViewSc ript);
}
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
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.h
** if i make this html button runat="server " and add following code on the code behind on clickevent
private void btnView_ServerClick(object
{
Session["FromView"] = ddlCountry.SelectedValue;
string ViewScript = "<script language='javascript'>" +
string.Format ("window.location.href('co
Page.RegisterStartupScript
}
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
ASKER
its asp.net 1.x
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("T extBox1"). value="."; //Note there is a . in the textboxes
document.getElementById("T extBox2"). value=".";
return true;
}
</script>
In the page_load do this
if (!IsPostBack)
{
this.btnView.Attributes.Ad d("onclick ", "javascript:IgnoreValidato r();");
}
private void btnView_ServerClick(object sender, System.EventArgs e)
{
Session["FromView"] = ddlCountry.SelectedValue;
Response.Redirect("ountry. aspx?Count ry=" + ddlCountry.SelectedItem.Te xt);
//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
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("T
document.getElementById("T
return true;
}
</script>
In the page_load do this
if (!IsPostBack)
{
this.btnView.Attributes.Ad
}
private void btnView_ServerClick(object
{
Session["FromView"] = ddlCountry.SelectedValue;
Response.Redirect("ountry.
//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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:loadWi ndow();" value="sometext"/>
javascript //
function loadWindow()
{
var vv = window.open('country.aspx? country='+ document.a ll.ddlCoun try.option s[document .all.ddlCo untry.sele ctedIndex] .text,'loc ation=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["count ry"];
hope it helps.
regards,
satish.
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:loadWi
javascript //
function loadWindow()
{
var vv = window.open('country.aspx?
//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["count
hope it helps.
regards,
satish.
ASKER
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
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