Web Forms :: Unable To Retrieve Dynamic Panel Object Controls?
Jul 6, 2010
I have a form in a page and a panel inside the form.The panel gets loaded with dynamic controls like radio button and text boxes.
User is allowed to choose any radio option and enter any value in the textbox beside it and then goes for submit button to move to next stage.
Problem Descritopn:
I load the controls in the panel based on the index of a combo control on the same form.it is done in selectedIndexChanged - This is working fine.
When i go for the submit button and ask for the textbox control, it says "object reference not set to instance of object", denoting that instance is not available. Moreover the panel control list gets empty automatically.
i have to access Textbox and check box values at same time those check box and text box created at run time .i know how i can retrive single controll but problem is that i want both control values at same time to add them in database
i got checkbox in gridview which put inside the itemtemplate. the problem is when i tick on the checkbox, the value for checked property still is a false value. Wat;s wrong?
If GridViewRDR1_Hidden.Rows.Count > 0 Then For Each row As GridViewRow In GridViewRDR1_Hidden.Rows Dim cb As CheckBox = CType(row.FindControl("chkstatus"), CheckBox ) If cb.Checked Then MsgBox("True") End If Next End If
I am trying to update the database with the edited data. However, it did not manage to read the edited data from the textbox. It returned the retrieve data that I have done in the Page_Load instead. Is there any part of the code that I have written wrongly? I did manage not to use <EditItemTemplate> in my past project and manage to update the database with the same logic.
<aspx> <!-- This DataList is created to view Personal Information --> <asp:DataList ID="personal_dl" runat="server"> <ItemTemplate> <table> <tr> <td style="width: 100px; text-align: left;"> <asp:Label ID="first_lbl" runat="server" ForeColor="Black" Font-Size="11px" Text="First:"></asp:Label></td> <td style="width: 350px"> <asp:TextBox ID="first_tb" runat="server" Width="341px" Font-Size="11px" Text='<%# Eval("FIRST") %>'> </asp:TextBox> </td> </tr> <tr> <td style="width: 100px; text-align: left"> <asp:Label ID="name_lbl" runat="server" Font-Size="11px" ForeColor="Black" Text="Name:"></asp:Label> </td> <td style="width: 350px"> <asp:TextBox ID="name_tb" runat="server" Width="341px" Font-Size="11px" Text='<%# Eval("NAME") %>'> </asp:TextBox> </td> </tr> <tr> <td style="width: 100px; text-align: left;"> <asp:Label ID="id_lbl" runat="server" ForeColor="Black" Font-Size="11px" Text="ID:"> </asp:Label> </td> <td style="width: 350px"> <asp:TextBox ID="id_tb" runat="server" Width="341px" Font-Size="11px" Text='<%# Eval("ID") %>'> </asp:TextBox> </td> </tr> <tr> <td style="width: 100px; text-align: left;"> <asp:Label ID="contact_lbl" runat="server" ForeColor="Black" Font-Size="11px" Text="Contact No.:"> </asp:Label> </td> <td style="width: 350px"> <asp:TextBox ID="contact_tb" runat="server" Width="341px" Font-Size="11px" Text='<%# Eval("TELEPHONE_HP") %>'> </asp:TextBox> </td> </tr> <tr> <td style="width: 100px; text-align: left;"> <asp:Label ID="add_lbl" runat="server" ForeColor="Black" Font-Size="11px" Text="Address:"> </asp:Label> </td> <td style="width: 350px"> <asp:TextBox ID="add_tb" runat="server" Width="341px" Font-Size="11px" Text='<%# Eval("ADDRESS") %>'> </asp:TextBox> </td> </tr> </table> </ItemTemplate> </asp:DataList> <br /> <div style="text-align: center; color: Red; width: 460px;"> <asp:Label ID="errorMsg_lbl" runat="server" /> <asp:Button ID="edit_btn" runat="server" Text="Update" /> <asp:Button ID="createBtn" runat="server" Text="Insert" /></div> <aspx.vb> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'display information in datalist Dim login As String = Session("login") Dim id As String = Session("id") bindDataList(personal_dl, getPersonalContent(login, id)) 'display necessary DataList personal_dl.Visible = True 'declare fields Dim i As Integer Dim first_tb, name_tb, id_tb, contact_tb, add_tb As New TextBox For i = 0 To personal_dl.Items.Count - 1 first_tb = personal_dl.Items(i).FindControl("first_tb") name_tb = personal_dl.Items(i).FindControl("name_tb") id_tb = personal_dl.Items(i).FindControl("id_tb") contact_tb = personal_dl.Items(i).FindControl("contact_tb") add_tb = personal_dl.Items(i).FindControl("add_tb") 'set fields as ReadOnly - cannot edit first_tb.ReadOnly = False name_tb.ReadOnly = False id_tb.ReadOnly = False contact_tb.ReadOnly = False add_tb.ReadOnly = False Next End Sub
Protected Sub edit_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles edit_btn.Click 'declare fields Dim i As Integer Dim first_tb, name_tb, id_tb, contact_tb, add_tb As New TextBox Dim id As String = Session("id") For i = 0 To personal_dl.Items.Count - 1 first_tb = personal_dl.Items(i).FindControl("first_tb") name_tb = personal_dl.Items(i).FindControl("name_tb") id_tb = personal_dl.Items(i).FindControl("id_tb") contact_tb = personal_dl.Items(i).FindControl("contact_tb") add_tb = personal_dl.Items(i).FindControl("add_tb") Next Dim myConnection As OleDbConnection = dbConnection() Dim cmd As New OleDbCommand Dim sqlStatement As String Dim condition As String condition = "UPDATE staff " + _ "SET ((FIRST= @FIRST), (NAME = @NAME), (ID= @ID), (TELEPHONE_NO = @CONTACT_NO), (ADDRESS = @ADDRESS)) " + _ "WHERE (ID= @id)" sqlStatement = condition cmd.CommandText = sqlStatement cmd.CommandType = CommandType.Text cmd.Parameters.AddWithValue("@FIRST", first_tb) cmd.Parameters.AddWithValue("@NAME", name_tb) cmd.Parameters.AddWithValue("@ID", id_tb) cmd.Parameters.AddWithValue("@TELEPHONE_NO", contact_tb) cmd.Parameters.AddWithValue("@ADDRESS", add_tb) cmd.Parameters.AddWithValue("@ID", id) cmd.Connection = myConnection Try myConnection.Open() cmd.ExecuteNonQuery() Catch ex As Exception Finally If myConnection.State = ConnectionState.Open Then myConnection.Close() End If End Try 'display information in datalist Dim login As String = Session("login") bindDataList(personal_dl, getPersonalContent(login, id)) End Sub
I have a website written in C# that was running fine on one server. We moved it to another server and have a couple issues. I am mainly a VB.NET coder but can do a few things in C#. This is not a project - it is a website and can open it in VS2008 no problem. This is an admin site for the whole website where the user can add customer comments, etc. When logging in, it works fine. I can go to one of the admin pages after logging in and works. If I go to two other different pages, I get this error:
Object reference not set to an instance of an object.
[Code]....
It turns out this is in the main.master page and it is used by the other pages that load fine. The ApplicationTitle variable is set right in the web.config file and like I said, it shows on the other pages.
My question is why would this code work fine for some pages and not two others? All of these admin pages are under a folder called Admin and the web.config file is in the root folder of the website. Its almost like these two pages cannot see the web.config file in the root folder? Why would that be if thats the case?
im trying to use dynamic object in a databinding tag , it gives me error that the property does not exists even though i can see all the properties there in the vs debug mode
here is what im trying to do:
C#:
my method signature:
public static dynamic MyMethod()
ASPX:
in control itemtemplate:
<%# MyMethod().SomeProperty %>
if also trite the other way:
C#:
public static object MyMethod()
ASPX:
<%# ((dymanic)MyMethod() ).SomeProperty%>
But i dont know why it cant resolve the properties , even though i can see them when the databinder control throws an exception (its working fine outside the databinder tag (ie normal aspx tags <% %>)
i'm using asp.net 3.5 and what im trying to do is create the dropdownlist item dynamically base on value in each datarow, then user select from dropdownlist and click button to postback, when postback system should be able to know what value has been selected by user. the problem with following code is during postback, event of "OnItem_Created" get fired and e.Item.DataItem return null, therefore the dropdownlist will not get populated with the items and that caused the dropdownlist unable to return value selected by user. am i missing anything? is "OnItemCreated" the best place to dynamic create the dropdownlist item?
In the main code, I just have a panel inside a DataList control. I'm attempting to adjust change the visibility to true or false in the code behind, but it's not having any affect on the panel.
I need some help on the row updating for a gridview that i bind manually to a list, not using objectdatasource or sqldatasourcehere is my rowupdating. What i want to do for now is just get the values from the textboxes and I will store them to sting variables then I will call my update function and pass those as parameters. How do I get the data from the textboxes that the user just edited. I have the following but I am getting an error: "unable to cast object of type System.UI.LiteralControl to type System.UI.TextBox
I need to retirve data from two tables...when i click a value in dropdown list, i need to retrieve values from two tables based on that id( which i have selected in dropdown)..so when i have written query ( "Select assign_issue.issue_assigned_to, assign_issue.created_on,assign_issue.last_Date, issue_register.issue_desc,issue_register.issue_Priority from assign_issue INNER JOIN Issue_register ON assign_Issue.Issue_ID = issue_register.Issue_ID where issue_register = '" + ddlissueid.selecteditem.text + "'")..query is executing ..when it comes to dr = cmd.executereader()..Dr is unable to read..it is showing false when i trace..unable to read into while loop.
i am still stumped with this operation: i am trying to retrieve a GridView selected row data..here is my code.. the commented part that gives me the selectedindex works just fine....but the one giving the selected row cell value does't work and there is no error.. The update operation is done successfully...weired. i need to assigned selected row cells values to variables ..do some calculations and then re-assign the result calculation to cell[9]..
I'm an experienced PHP programmer that is new to ASP.net (C#). I'm trying to figure out how to do a manual echo of a specific field from an SQL database and was wondering how you do an if condition in case the field would meet certain criteria ?
What I want the script to do is check in the database if a certain condition is activated, then the html page should echo a windows media player object with the source of the video coming from the database itself ( $line[Video], and if the condition isn't active then either don't echo the player or just echo an old video (in the script I'm just printing a message).
I got this error "object reference not set to an instance of an object" when i want to display the values of dynamic generated drop down lists by pressing a button to show the values in Listitem.
I have a webservice, it has few webmethods. when i create a client proxy and invoke the methods to check its response, i am getting this error. Can someone tell me what things can i check to know the cause of this? The error is not saying much hence blocked on this.
a pure html table will be generated on the client side. (using jQuery to add dynamic new rows to the table when the user clicks a button).
These rows contain textboxes, dropdownlists, checkboxes and other input controls.
When the user clicks a button, a PostBack is triggered in which I need to access this data from the table on the server side, validate it (yes all rows at once) and perform other actions on it.
I'm able to perform the client side and access the table data on server side by adding runat="server" to the table tag. However, I only see the initial table rows (not the ones added through JavaScript) and I have troubles retrieving the different inputs from the rows.
i have a query like this and its running correctly
SELECT CAST(REPLACE(LTRIM(RTRIM(SUBSTRING(P.Telephone, 2, LEN(P.Telephone)))), ' ', '') AS BIGINT) FROM P INNER JOIN PCommunication ON P.ID = PCommunication.ID WHERE P.Telephone IS NOT NULL AND CAST(REPLACE(LTRIM(RTRIM(SUBSTRING(P.Telephone, 2, LEN(P.Telephone)))), ' ', '') AS BIGINT) > 5000000000 AND PCommunication.TypesID = '7667d187-5fe1-4aaf-9e31-79761561da58'
i am trying to use it with dynamic query like this but its not working
I have a page that is mostly dynamically built in the page load of my VB.net code behind page.
The issue is that I made a change to the page and added a button that redirects to a secondary page. When the button is clicked there is a very noticeable lag until the button click event fires because the page is being rebuilt every time.
I had not wrapped the code in the load event in the If not ispostback.... because I have dynamic controls that the user interacts with and I need the page to be rebuilt when the user clicks them.
The dynamic controls are clickable table cells. I did some looking and I found that the RegisterPostBackControl. I thought this would be perfect but, it does not although I maybe using it incorrectly.
What this does is create a javascript spinner control. Now when I click the NEXT button onto this step it generates the spinner control. I click next to go to the next step, then I click PREVIOUS to go back to this step and the spinner control is not generated.
Now I have tested this on an ASPX page and it seems to work, I then copy the code across to an ASCX control and put the page live and it does not work.
The update panel has an animation extender that just displays a div with a processing gif when you click next/previous.
So any reason why it creates the control on the next and not the previous step?