I am dynamically creating radbuttons on a webpage, but cannot get them to post back to the server.
Any ideas would be greatly appreciated!
Here is the code, this is within a loop creating the items:
Any ideas would be greatly appreciated!
Here is the code, this is within a loop creating the items:
aComboBox(aTextBoxCount) = New TextBox
aComboBox(aTextBoxCount).TextMode = TextBoxMode.MultiLine
aComboBox(aTextBoxCount).ReadOnly = True
aEditButton(aTextBoxCount) = New RadButton
aEditButton(aTextBoxCount).Text = "Edit"
aEditButton(aTextBoxCount).ID = aTextBoxCount
aEditButton(aTextBoxCount).AutoPostBack = True
AddHandler aEditButton(aTextBoxCount).Click, AddressOf EditText
aComboBox(aTextBoxCount).ID = "aComboBox" & aTextBoxCount
aComboBox(aTextBoxCount).Width = TextBoxWidth
aComboBox(aTextBoxCount).DataBind()
aComboBox(aTextBoxCount).Text = ""
RadMultiPage1.PageViews(cCheckBoxTab).Controls.Add(New LiteralControl("<
table
><
tr
><
td
style
=
""
width: 45px""></
td
><
td
>"))
RadMultiPage1.PageViews(cCheckBoxTab).Controls.Add(aComboBox(aTextBoxCount))
RadMultiPage1.PageViews(cCheckBoxTab).Controls.Add(New LiteralControl("</
td
><
td
>"))
RadMultiPage1.PageViews(cCheckBoxTab).Controls.Add(aEditButton(aTextBoxCount))
RadMultiPage1.PageViews(cCheckBoxTab).Controls.Add(New LiteralControl("</
td
></
tr
></
table
>"))
4 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 15 Nov 2013, 04:38 AM
Hi ChuckRock,
Please have a look into the following code snippet to create a RadButton dynamically and post back the RadButton to the server side.
ASPX:
VB:
Thanks,
Shinu
Please have a look into the following code snippet to create a RadButton dynamically and post back the RadButton to the server side.
ASPX:
<
telerik:RadTabStrip
ID
=
"RadTabStrip1"
runat
=
"server"
MultiPageID
=
"RadMultiPage1"
>
<
Tabs
>
<
telerik:RadTab
Text
=
"Tab1"
runat
=
"server"
PageViewID
=
"RadPageView1"
>
</
telerik:RadTab
>
</
Tabs
>
</
telerik:RadTabStrip
>
<
telerik:RadMultiPage
ID
=
"RadMultiPage1"
runat
=
"server"
>
<
telerik:RadPageView
ID
=
"RadPageView1"
runat
=
"server"
>
</
telerik:RadPageView
>
</
telerik:RadMultiPage
>
VB:
Protected
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
'creating a radbutton
Dim
Button
As
New
RadButton()
Button.ID =
"RadButton1"
Button.Text =
"Click"
AddHandler
Button.Click,
AddressOf
Me
.Button_Click
RadMultiPage1.FindPageViewByID(
"RadPageView1"
).Controls.Add(Button)
End
Sub
Private
Sub
Button_Click(sender
As
Object
, e
As
EventArgs)
'click event of the dynamically created radbutton
Throw
New
NotImplementedException()
End
Sub
Thanks,
Shinu
0
ChuckRock
Top achievements
Rank 1
answered on 15 Nov 2013, 04:38 PM
Shinu,
Thanks for the example. I was able to get that to work by itself; but was not able to get it to work on the page I need it. Apparently something else was interfering with it.
After troubleshooting a bit longer, I found that it was the RadAjaxManager that was the culprit.
Thanks again for your help, it lead me in the right direction.
-Chuck Bryan
Thanks for the example. I was able to get that to work by itself; but was not able to get it to work on the page I need it. Apparently something else was interfering with it.
After troubleshooting a bit longer, I found that it was the RadAjaxManager that was the culprit.
Thanks again for your help, it lead me in the right direction.
-Chuck Bryan
0
ChuckRock
Top achievements
Rank 1
answered on 15 Nov 2013, 06:46 PM
Sinhu,
Unfortunately, I have not completely gotten this problem fixed. I have stripped down the page in question as much as I can. Below you will see the aspx and aspx.vb portions.
The sticking point seems to be that I have two RadCombo Boxes on the page. If I remove them, then the dynamically created buttons behave as they should. If the combo boxes are left on the page; then the created button does not post back!
Any help you can provide would be greatly appreciated!
EditTest.aspx
EditTest.aspx.vb
Unfortunately, I have not completely gotten this problem fixed. I have stripped down the page in question as much as I can. Below you will see the aspx and aspx.vb portions.
The sticking point seems to be that I have two RadCombo Boxes on the page. If I remove them, then the dynamically created buttons behave as they should. If the combo boxes are left on the page; then the created button does not post back!
Any help you can provide would be greatly appreciated!
EditTest.aspx
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPMSI.master" AutoEventWireup="false" CodeFile="!EditTest.aspx.vb" Inherits="Main" ValidateRequest="false" %>
<%@ MasterType VirtualPath="~/MasterPMSI.master" %>
<
asp:Content
ID
=
"Content1"
ContentPlaceHolderID
=
"head"
runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content2"
ContentPlaceHolderID
=
"ContentPlaceHolder1"
runat
=
"Server"
>
</
asp:Content
>
<
asp:Content
ID
=
"Content3"
ContentPlaceHolderID
=
"ContentPlaceHolder2"
runat
=
"Server"
>
<
table
id
=
"footerTable"
>
<
tr
>
<
td
class
=
"cc"
>
<
center
>
<
span
class
=
"style2"
>Edit</
span
>
<
br
/>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"cReassessIn"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadMultiPage1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"Timer1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"lRefresh"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
asp:Label
ID
=
"TopHeader"
runat
=
"server"
Font-Italic
=
"True"
Width
=
"100%"
></
asp:Label
>
<
br
/>
<
asp:Panel
ID
=
"Panel1"
runat
=
"server"
BorderStyle
=
"Ridge"
BorderWidth
=
"3px"
Width
=
"95%"
HorizontalAlign
=
"Left"
DefaultButton
=
"bReturn"
>
<
table
width
=
"100%"
>
<
tr
>
<
td
style
=
"text-align: left"
>
<
telerik:RadButton
ID
=
"bReturn"
runat
=
"server"
Text
=
"Return"
Width
=
"180px"
Font-Size
=
"16px"
></
telerik:RadButton
>
</
td
>
</
tr
>
<
tr
>
<
td
style
=
"text-align: center"
>
<
asp:Label
ID
=
"lStatus"
runat
=
"server"
Width
=
"100%"
Font-Bold
=
"True"
></
asp:Label
>
</
td
>
</
tr
>
</
table
>
<
telerik:radtabstrip
id
=
"RadTabStrip1"
runat
=
"server"
width
=
"100%"
Skin
=
"Outlook"
AutoPostBack
=
"True"
>
<
Tabs
>
<
telerik:RadTab
ID
=
"Tab1"
runat
=
"server"
Text
=
"1"
Visible
=
"False"
></
telerik:RadTab
>
<
telerik:RadTab
ID
=
"Tab2"
runat
=
"server"
Text
=
"2"
Visible
=
"False"
></
telerik:RadTab
>
</
Tabs
>
</
telerik:radtabstrip
>
<
hr
/>
<
telerik:RadMultiPage
ID
=
"RadMultiPage1"
runat
=
"server"
Width
=
"100%"
SelectedIndex
=
"0"
>
<
telerik:RadPageView
ID
=
"PageView1"
runat
=
"server"
></
telerik:RadPageView
>
<
telerik:RadPageView
ID
=
"PageView2"
runat
=
"server"
Width
=
"100%"
></
telerik:RadPageView
>
</
telerik:RadMultiPage
>
<
br
/>
<
table
width
=
"100%"
>
<
tr
>
<
td
valign
=
"top"
>
This
<
telerik:RadComboBox
ID
=
"cAssessmentFinal"
runat
=
"server"
Width
=
"410px"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Exceeds"
Value
=
"0"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Meets"
Value
=
"1"
/>
</
Items
>
</
telerik:RadComboBox
>
</
td
>
<
td
>
Date
<
telerik:RadComboBox
ID
=
"cReassessIn"
runat
=
"server"
Width
=
"225px"
AutoPostBack
=
"True"
>
<
Items
>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"Not Needed"
Value
=
"1"
/>
<
telerik:RadComboBoxItem
runat
=
"server"
Text
=
"in 2-4 weeks"
Value
=
"2"
/>
</
Items
>
</
telerik:RadComboBox
>
</
td
>
</
tr
>
</
table
>
</
asp:Panel
>
<
asp:Panel
ID
=
"Panel2"
runat
=
"server"
>
<
asp:Timer
ID
=
"Timer1"
runat
=
"server"
Interval
=
"120000"
OnTick
=
"Timer1_Tick"
/>
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
>
</
telerik:RadWindowManager
>
</
asp:Panel
>
</
center
>
</
td
>
</
tr
>
</
table
>
</
asp:Content
>
EditTest.aspx.vb
Imports
Microsoft.VisualBasic
Imports
System
Imports
System.Web
Imports
System.Web.UI
Imports
System.Text
Imports
System.Web.Configuration
Imports
Telerik.Web.UI
Imports
MySql.Data.MySqlClient
Partial
Class
Main
Inherits
System.Web.UI.Page
Protected
Sub
Page_Load(sender
As
Object
, e
As
System.EventArgs)
Handles
Me
.Load
PutButtons()
End
Sub
Private
Sub
PutButtons()
Dim
button
As
New
RadButton
button.Text =
"Test Edit"
button.ID =
"EButtonTest"
AddHandler
button.Click,
AddressOf
Me
.EditText
RadMultiPage1.PageViews(0).Controls.Add(button)
End
Sub
Private
Sub
EditText(
ByVal
sender
As
Object
,
ByVal
e
As
System.EventArgs)
Dim
buttonId
As
String
buttonId =
DirectCast
(sender, RadButton).ID
lStatus.Text +=
" BC= "
+ buttonId
End
Sub
Protected
Sub
Timer1_Tick(sender
As
Object
, e
As
System.EventArgs)
Handles
Timer1.Tick
Dim
fu
As
Boolean
' Do timer stuff here
End
Sub
End
Class
0
Shinu
Top achievements
Rank 2
answered on 21 Nov 2013, 10:07 AM
Hi ChuckRock,
The dynamically created RadButton postback is not happening because the RadButton is added inside the "RadMultiPage1", which is ajaxified. If you want to ajaxify the controls inside the "RadMultiPage1" then Please try to specify each controls inside the "RadMultiPage1" separately. Otherwise all the controls inside the "RadMultiPage1" will be ajaxified.
Thanks,
Shinu.
The dynamically created RadButton postback is not happening because the RadButton is added inside the "RadMultiPage1", which is ajaxified. If you want to ajaxify the controls inside the "RadMultiPage1" then Please try to specify each controls inside the "RadMultiPage1" separately. Otherwise all the controls inside the "RadMultiPage1" will be ajaxified.
Thanks,
Shinu.