cancel
Showing results for 
Search instead for 
Did you mean: 

Problem while retrieving value from dynamic control

Former Member
0 Kudos

Hi,

I am using EP 6.0 SP 9 and PDK for .Net 1.0 Patch 3.

I have created an interface dynamically based on a BAPI.

Problem is that I am unable to retrieve value from that dynamic control(Input Field) since the control ID is appened with some text(tc8619bec_).

Dim z_selectrow As New StockSamp.BAPIF4B
Dim tempType As New InputField
z_selectrow.Select_Fld = "MTART"
z_selectrow.Sign = "I"
z_selectrow.Option0 = "EQ"
z_selectrow.High = ""
tempType.Value = CType(tblType.FindControl("tc8619bec_txtType2"), InputField).Value.Trim.ToUpper()
z_selectrow.Low = tempType.Value
z_Select.Add(z_selectrow)

I tried this also.

tempType.Value = CType(tblType.FindControl("txtType2"), InputField).Value.Trim.ToUpper()
z_selectrow.Low = tempType.Value

then calling the second BAPI. It is throwing the error as <b>Object reference not set to an instance of an object.</b>

tbltype - Table ID to which the input field is added

txtType2 - Input field (dynamic)

Please help.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rajender,

Im getting the same problem of retreiving the data from dynamically created input field and also i cant trigger action for the button created dynamically..could u tel me how to resolve this issue..

It wil be useful if u send the working code to me..

My mail id: vin_win05@yahoo.co.in

Regards,

Vinoth

reiner_hille-doering
Active Contributor
0 Kudos

Have you assigned an ID to the dynamic InputField during creation? If not, ASP.NET would do so and thus you cannot know how it is called. E.g.

InputField dynamicField = new InputField();

dynamicField.ID = "dynamicField" + number.ToString();

cell.TableCellContens = dynamicField;

cell.Controls.Add(dynamicField);

"number" is a unique number that you calculated from the position in the table.

Former Member
0 Kudos

Hai Reiner,

Thanks for your response. I have assigned ID to the dynamic control.

Actually the problem is that I am unable to retrieve the data from that dynamic control using FindControl method.

// Code to generate the Search Interface dynamically

Private Sub GetDesign(ByVal dvdesc As DataView, ByVal SType As String)
        dvdesc.RowFilter = "ShlpName='" & SType & "'"
        'dvDesc.Sort = "Posi"
        lblHeading.Text = lbHelpList.SelectedItem.Text
        Dim i, j As Integer

        tblType = New WebControls.Table
        tblType.ID = "tblType"

        'CType(tblType, WebControls.Table).ID = "tblType"
        tblType.BorderColor = Color.Black
        tblType.CellSpacing = 0
        tblType.CellPadding = 2

        For i = 0 To dvdesc.Count - 1
            tblTypeRows(i) = New WebControls.TableRow

            tblTypeCell(0) = New WebControls.TableCell
            lblType(i) = New SAP.Web.UI.Controls.Label
            lblType(i).ID = "lblType" & i
            lblType(i).text = dvdesc.Item(i).Item("ScrText_M")
            lblType(i).design = LabelDesign.LIGHT
            'CType(lblType(i), SAP.Web.UI.Controls.Label).ID = "lblType" & i
            'CType(lblType(i), SAP.Web.UI.Controls.Label).Text = dvdesc.Item(i).Item("ScrText_M")
            'CType(lblType(i), SAP.Web.UI.Controls.Label).Design = LabelDesign.LIGHT
            tblTypeCell(0).controls.add(lblType(i))

            tblTypeCell(1) = New WebControls.TableCell
            txtType(i) = New SAP.Web.UI.Controls.InputField
            Dim len As Integer
            len = dvdesc.Item(i).Item("Leng")
            txtType(i).ID = "txtType" & i.ToString
            txtType(i).maxlength = len
            txtType(i).width = CInt(len) * 8
            If len = 1 Then txtType(i).width = 15
            'CType(txtType(i), InputField).ID = "txtType" & i
            'CType(txtType(i), InputField).MaxLength = len
            'CType(txtType(i), InputField).Width = CInt(len) * 8
            'If len = 1 Then CType(txtType(i), InputField).Width = 15
            tblTypeCell(1).controls.add(txtType(i))

            tblTypeRows(i).cells.add(tblTypeCell(0))
            tblTypeRows(i).cells.add(tblTypeCell(1))

            tblType.Rows.Add(tblTypeRows(i))
        Next
        btnSearch.Visible = True
        plHolder.Controls.Add(tblType)
    End Sub

// Code to display the result

Private Sub SearchResult()
        Try
            Response.Write(CType(tblType.FindControl("txtType2"), InputField).Value)
            'Response.Write((CType(tblType.FindControl("txtType2"), InputField).Value))
            lblError.Visible = False
            Click = "Search"
            Dim str As String
            str = lbHelpList.SelectedItem.Value
            z_Explicit = New BAPISHLP
            z_Explicit.Shlpname = str.Trim.ToUpper()
            z_Explicit.Shlptype = "SH"
            z_Explicit.Reptext = ""
            z_Explicit.Title = ""
            Select Case str
                Case Sea_1
                    Dim z_selectrow As New StockSamp.BAPIF4B
                    z_selectrow.Select_Fld = "MTART"
                    z_selectrow.Sign = "I"
                    z_selectrow.Option0 = "EQ"
                    z_selectrow.High = ""
                    z_selectrow.Low = CType(tblType.FindControl("txtType2"), InputField).Value
                    ' Response.Write(z_selectrow)

                    'z_selectrow.Low = (CType(tblType.FindControl("tc8619bec_txtType2"), InputField).Value).ToUpper()
                    z_Select.Add(z_selectrow)
                    Me.SearchResult1.Bapi_Helpvalues_Get("", z_Explicit, "Material", 50000, "GetList", "Material", "Bus1001", "MatnrList", z_Return2, z_Desc2, z_Help, z_Select, z_Values)
                    btnSearch.Visible = False
                    tblResult.Visible = True
                    Call Displayresult(z_Help)
            End Select
        Catch ex As Exception
            lblError.Visible = True
            lblError.Text = ex.Message
        End Try
    End Sub

The problem remains the same. Please help.

Thanks,

Rajender.

reiner_hille-doering
Active Contributor
0 Kudos

Hi Rajender,

what you plan to do it a really complicated thing, maybe the most complicated this you can do with the NetWeaver controls. The problem comes from how ASP.NET works. Think in th following steps that happen:

- When the page is rendered, yor GetDesign method is called to populate the control tree. You fill in your special content controls.

- The tree goes out as HTML, here the inserted controls get a client ID.

- The user fills out some fields and presses a button.

- As the result the browser create a Post data string with <clientid>=<value> pair.s

- ASP.NET needs to do something with the values. Therfore, it needs to create the control tree again, exactly with the same layout and ids. This only works, if your GetDesign is called again with exactly the same parameters, you datasource is the same and so on and so forth.

- If this all worked, the post-result could be inserted into the controls. In fact all of them need to process there part of the postback data correctly.

- Now you could find the control.

You see that this is complicated. This is one of the reasons that we don't fully support input-enabled controls in a table. Rendering is not the problem, but handling the result is one. BTW MS also does not really support it in thre DataGrid.

The most realistic chance to make it working is by handling the whole postback data by your own. You should have access to it somewhere in the request. This sounds at least more realist than to have the postback handled correctly in the tree.

Former Member
0 Kudos

Hi Reiner,

Thanks for your quick response. As shown in the code below, this is what I was using in the post back. It is not displaying the interface.

Here in my program,

1. First I will click on Help button, which will display the different search helps in a listbox.

2. When I select a specific search from listbox, I am getting the interface(dynamically).

3. Here I am clicking the Search button after enter the search criteria.

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim imgPath As String = MapResourcePath("Web Resources/images/DbRun.gif")
        ImgHelp.ImageUrl = imgPath
        Sea_1 = "MAT1T"
        Sea_2 = "MAT1L"
        If Page.IsPostBack Then
            If Click = "Button" Then
                Dim selstr As String
                selstr = lbHelpList.SelectedItem.Value
                Response.Write(selstr)
                Select Case (selstr.ToUpper())
                    Case Sea_1
                        GetDesign(dvDesc, Sea_1)
                    Case Sea_2
                        GetDesign(dvDesc, Sea_2)
                End Select
                Call SearchResult()
            End If
            If tblResult.Visible = True Then
                HelplistClick()
                Call SearchResult()
            End If
        Else
        tblResult.Visible = False
        End If
    End Sub

Private Sub btnSearch_Action(ByVal sender As System.Object, ByVal e As SAP.Web.UI.Controls.AbstractButton.ActionEventArgs) Handles btnSearch.Action
        ' Call GetDesign(dvDesc, Sea_1)
        'Response.Write(CType(tblType.FindControl("txtType2"), InputField).Value)
        Click = "Button"
End Sub

Thanks in advance,

Rajender.

reiner_hille-doering
Active Contributor
0 Kudos

Sorry, I didn't get the question.

Former Member
0 Kudos

Hi Rajender,

Some comments:

1. The prefix you see in the html is a hash code added since your code actualy runs in a user control and is embedded in a page, so the client ID's need to be unique.

2. You shouldn't use "Response.Write". I know it's only for testing purposes, but it's not a good idea anyway (again because of what I wrote in 1). You should use "Me.Write" instead... it has the same effect, but it will make sure the response goes into the right iView.

3. If you would have used The NetWeaver Image control, the runtime resource mapping is done for you, so you could even set the image in design time (in the property grid)

4. I noticed you use the ASP table and not the NetWeaver Table... right?

5. If I got it right (and I'm not sure that I did), seems like you re-create the new input control for each postback in the page load.. and it's after the post back data is parsed.

My suggestions: Can you check what object exactly is null that throws the exception? You might also consider solving this issue with some Java scripting (keep an extra hidden field that gets the data via client script and that is easily accessed in run time).

Regards,

Ofer

Former Member
0 Kudos

Hi,

What I tried is to simulate the Search Help functionalty as in SAP (Material Search) using PDK for .Net.

Finally I could solve it.

Actually the problem was that the "Click" (as in code) variable which I used to control the Postbacks was not retaining its value. I used Session variable instead of an ordinary variable and this solved the problem.

Thanks for ur sugestions.

Rajender.

Former Member
0 Kudos

Can you please

1. Post the <b>working</b> code, if possible

2. mark this question as solved

Thanks

Ofer

Former Member
0 Kudos

Have you filled the PDK for .NET survey yet? You can win an MP3 player!!!

http://feedback.sap.com/efs/vote?campaign=39c7899ecca40a6709a638bd0388ac8b&org=332