Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an update panel where I have a dropdown set to autopostback true.
Depending on the selection in the dropdown, a variable value is updated which is used in a link to populate a query string value.

But if I use the update panel, the variable value is not being updated, keeping the old value that it gets during load.

How can I achieve this?
Thanks.
Posted
Comments
[no name] 14-Jan-11 19:17pm    
What variable? is it JavaScript or in the code behind?
AspDotNetDev 14-Jan-11 21:02pm    
How is the query string value populated? Any change in the query string should cause a page refresh? You'd either do it using a Response.Redirect (ASP.Net) or a window.location = ... (javascript). Post some code.

Try this

ASP.NET AJAX:dropdownlist inside a update panel is not updating[^]

BTW why don't you include your code in your question for quick response?
Let us know.
 
Share this answer
 
Put a hidden field in UpdatePanel. On dropdown value change, update the hidden field(server control) with the desired value.

Now, use this hidden field value to populate query string. Done!
 
Share this answer
 
Comments
Ekjon 17-Jan-11 14:24pm    
I tried all these before. But I had some other complexities - like the whole page is built dynamically based on some data - so I had to force a reload and use a querystring. Otherwise wasn't working no matter what I did. Thanks to all of you for your time and help.
Hi,
If your declare the variable in class level.
eg.

public partial class _Default : System.Web.UI.Page
{
public int Count = 0;


protected void button1_Click(object sender, EventArgs e)
{
count = 5;
}

protected void button2_Click(object sender, EventArgs e)
{
response.write(count);
}

}

output is : 0


So dclare the variable as static.


public partial class _Default : System.Web.UI.Page
{
public static int Count = 0;


protected void button1_Click(object sender, EventArgs e)
{
count = 5;
}

protected void button2_Click(object sender, EventArgs e)
{
response.write(count);
}

}

output is : 5

i think it solve ur problem.
 
Share this answer
 
After you set the variable,Call Update of updatepanel inorder to refresh

C#
UpdatePanel1.Update();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900