473,668 Members | 2,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically update DropDownList with new value

32 New Member
i am developing a web page in that i have a drop down list for Authors Name...which allows to select the Author available in the data source.and if the user wants a new author to insert into the authors table i had put a add new button beside the drop down list will allows the user to add the details of the new authors...so soon the user will select the add new button the Author page will be get open to enter Author details.....and now my requirement is soon the user click the insert button in Authors page...the Author details page should close and the newly entered Author name in the Author page should be added into drop down list of Books page with out refreshing.. can any one plz solve my problem plz. im developing my web page using asp.in with c#....
and im using following JS in .cs file
this.RegisterCl ientScriptBlock ("newAuthor" , "<script language='JavaS cript'> newAuthors('"+d dlAuthors.DataT extField+"','"+ ddlAuthors.Data ValueField+"',' "+ddlAuthors.Cl ientID+"')</script>");

hope i will get a quick respone

thank u...
Jan 5 '09 #1
8 10652
Frinavale
9,735 Recognized Expert Moderator Expert
You can use JavaScript to add the author to the DropDownList but you may run into problems because the ViewState won't match with what was sent to the browser. For an idea of what's involved to get this to work, check out this thread...I know it deals with ListBoxes but the same concept will apply to your DropDownList.

It would be easier to just make an asynchronous call to the server to refresh just the DropDownList instead of the whole page.
Jan 5 '09 #2
satyabhaskar
32 New Member
hi boos,
Thanks for reply, iam in idea to write the same code for java script in authors page...but the drop down list is in books page ... how can i get the id of the drop down list which is in Books page into the Authors page...
will u plz make me clear in this ...
thanks
Jan 6 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
I'm assuming that you are using popups. The key to this is to use the JavaScript window.opener to retrieve a reference to the Parent window. You have to set the name of the parent window before opening the popup window so that the window.opener will be set.

So, make a JavaScript function that opens the popup window but names the parent window before opening it. Also, create a function that updates the list that accepts a parameter with the value to add to it.

Call the function that opens the child window when you click the Add button...and when you hit "update" in the child window, have the update button refer to the windows.opener to call the JavaScript function that updates the list....passing it the value to add to the list.

Look up how to use window.opener to achieve what you're trying to accomplish.

-Frinny
Jan 6 '09 #4
satyabhaskar
32 New Member
hey thanks boss... ur reply helped me a lot... i solved my problem by following ur reply....nw i got two problems one is linked to the previous problem..
1. soon im updating the Authors details if i press ok button available in that form i will be going back to books details.and nw the problem is im not able to display the authors name in dropdown list as my first choice visible which i added in the authors form. can i get the information or sample example for this problem...
i tried even setting selectedIndex=1 and 0 but its not solved..

2. i have some number of text boxes in my page and even a button... soon i enter text in first text box and press enter it actually fires the button...but i dont to be like that...my need is soon i press enter the text in the text box and press enter i want to focus on the cursor on the next text box so that user can type the info in next text box(similar like tab key)...so actually i want navigation to carriage return..can u plz make me clear even in this doubt..by giving some relevant example.. so that i can take further steps in my project...

thanks
Jan 7 '09 #5
Frinavale
9,735 Recognized Expert Moderator Expert
@satyabhaskar
In JavaScript you cannot set the DropDownList.Se lectedIndex=1.
The reason you can't do this is because a DropDownList is an ASP.NET Object...not a JavaScript Object. ASP.NET transforms DropDownLists into HTML in order to let the browser know how to display them. The HTML generated for a DropDownList is a <select>.

Since you aren't posting back to the server to process this information using .NET, and you are certain that you want to use JavaScript to implement your solution, I have moved your question to the JavaScript Forum where JavaScript experts can help you. (It would be very challenging for any .NET expert to help you with this)


@satyabhaskar
This is a new question.
You should post this question in a new thread in the JavaScript Forum. I would recommend that you research and attempt this before asking your question because there is a lot of information and tutorials on the web about how to do this.
Jan 7 '09 #6
acoder
16,027 Recognized Expert Moderator MVP
@satyabhaskar
Get the client-side generated ID and use document.getEle mentById() to refer to the element and then set it's selectedIndex property.
Jan 9 '09 #7
Frinavale
9,735 Recognized Expert Moderator Expert
@acoder

Since this ID is not dynamically generated (because you're updating the list using JavaScript) you should know what it is .
Jan 9 '09 #8
acoder
16,027 Recognized Expert Moderator MVP
To avoid confusion and see exactly what the problem is, satyabaskhar, post your code.
Jan 10 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5477
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
3
4928
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that is being sent to the database is correct and the changes are eventually being made. If I refresh the page after the update then the new values appear. I noticed that when I put a breakpoint in my update handler everything works fine. When I take...
2
1663
by: Ron | last post by:
Hello, I am trying to create a page that pulls class rosters from an SQLServer database. The roster table definition is: emp_id(pk, fk), sec_id(pk, fk), reg_date and reg_status. Status can be Pending, Cancelled or NoShow. I want the page to display section information (working fine) as well as a datagrid of all the employees and their status'. Status should be displayed in a dropdownlist control and is the only control you can edit. ...
2
3747
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the <asp:EditCommandColumn> I want either a textbox or dropdown to appear when I check what is being edited. I thought I could create the dropdown on the fly and add it to the datagrid as below but It's not appearing. I imagined I could populate the dropdown
4
1675
by: Shiju Poyilil | last post by:
Hello EveryBody, I have a dropdownlist with some values as .net server controls & a button , on clicking a button i need to generate the choosen contorl dynamically. I am giving a small glimpse of my code for your understanding the aspx page has dropdwon list with values as below. <asp:DropDownList id="DropDownList1" runat="server"> <asp:ListItem Value="Label">Label</asp:ListItem> <asp:ListItem...
5
3507
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator; Response.Form.GetEnumerator(), etc. while, identifying specific controls by programmatically assigned unique id (e.g. MyButton_AnswerID_123). However, I am not sure if that is the proper way. What is the common practice?
0
4261
by: Zark3 | last post by:
Hi all, In a web form I use a for loop to dynamically add TextBox'es to a page (one for each item in an input file). I can get the input values and I can display them in Label's and TextBox'es. That part works. However, my problem is that the form lets the user choose from input files; the labels are updated, the textboxes are not. This seems to me like it is a ViewState issue, I just can't figure out how to fix that... Apparently the...
3
3633
by: J055 | last post by:
Hi I have a PlaceHolder control inside a FormView EditItemTemplate: <asp:PlaceHolder ID="phResponseText" runat="server"> <tr> <td> <asp:Label ID="lblResponseText" runat="server"></asp:Label></td> <td> <asp:TextBox ID="tbResponseText" runat="server" Text='<%#
4
1489
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created dropdownlistbox and label dynamically through loop and assign id as dropdownlist + no of iteration. Now my question is how I access these control as when I am accessing one of the control I am getting nullobjectreference error stating “Object reference not set...
2
3316
by: mylog | last post by:
Hi I am having a problem of getting the value from the dynamically generated table and dropdownlist. What I am facing is, I have created a table in the aspx page and now I need to add values to the the cells of the table respectively which I have done easily but the problem is when I add the dynamically generated dropdownlist to the cell I cannot read the value from the dropdownlist. For adding the dropdownlist in the cell I have done the...
0
8462
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8382
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8586
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2792
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1787
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.