Click here to Skip to main content
14,828,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I have a dropdownlist in side a gridview, Onselectedindexchanged I want to some action. But it doing postback but I don't want postback.Can any one helpme out in stoping the PostBack.I also used Updatepanel but after that the action what I want its not happening.

Below is my code for .cs

protected void Page_Load(object sender, EventArgs e)
       if (!IsPostBack)

           if (this.UserContext.UserRoles.Length == 0)
           if (!IsUserInRole(Constants.RL_GETSSET))

           adminBO = new UpdateAdminBO(this.UserContext);
           btnRemove.Visible = false;
           listSupportRoles = new DomainByCodeValue(this.UserContext, CategotyCode.SUPPORT_ROLES).DomainCodeValue;
           listClarifyRegions = new DomainByCodeValue(this.UserContext, CategotyCode.CLARIFY_REGION).DomainCodeValue;
           ViewState["listClarifyRegions"] = listClarifyRegions;
           existingUserDetails = adminBO.GetUserDetails();
           // Selected Option.
           // Q4 Requirements
           if (!IsPostBack)
               ddlUserRoleSelect.DataSource = listSupportRoles;
               ddlUserRoleSelect.DataTextField = "CodeValue";
               ddlUserRoleSelect.DataValueField = "CodeID";
               ddlUserRoleSelect.Items.Insert(0, new ListItem("ALL", "1"));

               ddlAddUser.DataSource = listSupportRoles;
               ddlAddUser.DataTextField = "CodeValue";
               ddlAddUser.DataValueField = "CodeID";
               ddlAddUser.Items.Insert(0, new ListItem("Select User Role", "1"));

               rcbRegions.DataSource = ViewState["listClarifyRegions"];
               rcbRegions.DataTextField = "CodeValue";
               rcbRegions.DataValueField = "CodeID";

               ddlUserRole.DataSource = listSupportRoles;
               ddlUserRole.DataTextField = "CodeValue";
               ddlUserRole.DataValueField = "CodeID";
               ddlUserRole.Items.Insert(0, new ListItem("ALL", "1"));

               //V-sisann Removed Code.
               if (Request.QueryString["id"] != null)
                   ScriptManager scriptManager = ScriptManager.GetCurrent(Page);
                   ScriptManager.RegisterClientScriptBlock(BtnUpdate, Page.GetType(), "MsgType_Info", "doShowMsg(\"New User Updated successfully.\", MsgType_Info)", true);

protected void ddlUserRole_SelectedIndexChanged(object sender, EventArgs e)

        //get user role drop down list
        DropDownList ddlRole = (DropDownList)sender;

        //get selected userrole row
        GridViewRow row = (GridViewRow)ddlRole.NamingContainer;

        ////get inner grid
        //GridView gridInner = (GridView)row.NamingContainer;

        ////get user detials grid
        //GridView gridUserDetails = (GridView)gridInner.NamingContainer;

        //System.Web.UI.HtmlControls.HtmlImage img = (HtmlImage)gridUserDetails.NamingContainer.FindControl("imgDetail");

        Telerik.Web.UI.RadComboBox rcbSecondaryUserRole = row.FindControl("rcbSecondaryUserRole") as RadComboBox;

        if (ddlRole.SelectedItem.Text == "GSPO")
            rcbSecondaryUserRole.DataSource = ViewState["listClarifyRegions"];
            rcbSecondaryUserRole.DataTextField = "CodeValue";
            rcbSecondaryUserRole.DataValueField = "CodeID";
            rcbSecondaryUserRole.Visible = true;
            rcbSecondaryUserRole.Visible = false;
Prasad Khandekar 24-Apr-13 10:19am
Set the AutoPostBack property to false.
Sandeep Mewara 24-Apr-13 11:17am
Fayaz7Wonders 25-Apr-13 1:15am
Hey Prasad ,
If I set the AutoPostBack to false then the ddlSelectedIndexChanged event will not fire.
Prasad Khandekar 25-Apr-13 1:25am
Well it works like that. Since it's not very clear on what action you want to happen upon selecting the item, I can suggest you try JQuery AJax to call the server side action.
Fayaz7Wonders 25-Apr-13 1:55am
My Question is when ddlUserRole_SelectedIndexChanged event will fire it should not do the Post back.Because of post back my controls are again getting refreshed.I am not able to stay in the same position.

Do you have any Idea on JQuery for this.Can u plz share
Prasad Khandekar 25-Apr-13 2:35am

Doing it without postback will require you to have a REST webservice. ( Once this service is ready you can use code similar to one shown below to call this web service. I am assuming "ddlUserRole" as the id of the drop down.

$('#ddluseRole').change(function() {
$.ajax('SERVICEURL', {
type: 'POST',
data: 'roleId=' + $(this).val(),
async : false,
cache: false,
dataType: 'json',
success:function(data, textStatus, jqXHR) {
// Code to work with the returned data (JSON)
error: function(jqXHR, status, errorThrown ) {
// Code to handle the error.
Fayaz7Wonders 25-Apr-13 3:22am
Ok I understand, But I am not using Service at all . Any other way
Prasad Khandekar 25-Apr-13 3:33am
What action you want to perform on change in dropdown selection?
TrushnaK 24-Apr-13 10:37am
Keep Update Panel as it is and update it from your ddlUserRole_SelectedIndexChange() at last. like:- UpdPnl.Update()
If still problem let me know
Fayaz7Wonders 25-Apr-13 1:57am
Hi Trushna,
I did that but still its reloading the page means postback happening.Below is the Code

if (ddlRole.SelectedItem.Text == "GSPO")
// This is to update the UpdatePanel
rcbSecondaryUserRole.DataSource = ViewState["listClarifyRegions"];
rcbSecondaryUserRole.DataTextField = "CodeValue";
rcbSecondaryUserRole.DataValueField = "CodeID";
rcbSecondaryUserRole.Visible = true;
TrushnaK 25-Apr-13 4:06am
UpdatePanel2.Update(); write this line at last of your event.

how you use update panel for dropdown or whole page...

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