DropDownList SelectedIndex value not updating on AutoPostback
Solution 1
Set a break point on the line that reads: NewFaqDropDownCategory.DataBind() and one in your event handler (NewFaqDropDownCategory_SelectedIndexChanged). I suspect the databind is being called right before your NewFaqDropDownCategory_SelectedIndexChanged event fires causing your selected value to change.
If so, you need either to make sure you only databind if you aren't in the middle of your autopostback or instead of using NewFaqDropDownCategory.SelectedIndex on the first line of your event handler you can cast the sender parameter to a DropDownList and use its selected value.
Solution 2
I had the same problem. Found I forgot to look if I was posting back to the page or not and I was binding my DropDownList control in the Page_Load
event of the page.
I had forgot to use:
if (!IsPostBack)
{
.... do databind ....
}
Related videos on Youtube
Shri
Updated on May 03, 2020Comments
-
Shri about 4 years
I'm an absolute beginner in GraphQL. So apologies if the question is amateur. I'm writing this graphQL end point where it will filter person by name. Works good, but I want to be able to
filter by multiple parameters like name, age, phone number
or
use a combination of the parameters to search..
My current program:
var express = require("express"); var express_graphql = require("express-graphql"); var { buildSchema } = require("graphql"); var Sequelize = require("sequelize") var db = new Sequelize( "users", "root", "pass", { host: "localhost", dialect: "mysql" } ); var calls = db.define( "calls", { person_id: { type: Sequelize.INTEGER, allowNull: false, primaryKey: true }, name: { type: Sequelize.STRING, allowNull: false }, age: { type: Sequelize.INTEGER, allowNull: false }, address: { type: Sequelize.STRING, allowNull: false }, company: { type: Sequelize.String, allowNull: false }, email: { type: Sequelize.STRING, allowNull: false } }, { tableName: "person" } ); // Construct a schema, using GraphQL schema language var schema = buildSchema(` type Query { Person(person_id: Integer!): [Person] } type Person { person_id: Integer name: String age: Integer address: String company: String email: String } `); var getperson = function(args) { if (args.person_id) { var p_name = args.person_id; return calls.findAll({ where: { name: p_name } }); } }; // The root provides a resolver function for each API endpoint var root = { person: getperson }; var app = express(); app.use( "/graphql", express_graphql({ schema: schema, rootValue: root, graphiql: true }) ); app.listen(4000); console.log("Running a GraphQL API server at http://localhost:4000/graphql");
Tried doing this:
type Query { Person(person_id: Integer!): [Person] Person(name: String!): [Person] }
But it says Person can be defined only once.
-
Daniel Rearden about 4 yearsAs an aside, you probably shouldn't be using buildSchema.
-
-
Anders about 15 yearsah hah! you were absolutely right. I put the break in there, found out it was indeed being called right before the event fired. I wrapped the DataBind in an if not page.ispostback conditional, and that fixed it up! thanks!
-
grenade about 15 yearsYay, my SO virginity is lost with my first accepted answer :)
-
Tim over 3 yearsStill helpful a decade later! I had nested dynamic controls with DataBind being called twice (once on the PlaceHolder filled with user controls, and once each for the PlaceHolder inside the user controls). I was baffled because the postback event would fire for everything EXCEPT the initial value, and even in the HTML rendering, the correct selected value was shown after I commented out the first, higher level databind, and wrapped the lower level one in a check for IsPostBack.