dynamically added linkbutton control, click event firing but cannot get page to open in iframe

I have a dynamically added linkbutton control (sorry for code layout, i get a noxmlhttp error when trying to use the source code box for posting) added like so:

Private Sub AddSecondLevelLinks(ByVal theTitle As String, ByVal theUrl As String)

Dim lb As New LinkButton

lb.Text = theTitle

lb.ID = lb.Text

lb.CommandArgument = theUrl

lb.Visible = True

lb.CssClass = "secondLevel"

Panel2.Controls.Add(lb)

AddHandler lb.Click, AddressOf SecondLevelButtonClick

End Sub

When i click the button my eventhandler definitely fires (drops in here in debug) but does not work as expected:

Sub SecondLevelButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)

Dim myLinkButton = DirectCast(sender, LinkButton)

Dim strurl As String = appendScopeToURL(myLinkButton.CommandArgument.ToString())

Dim framedisplay As HtmlContainerControl = form1.NamingContainer.FindControl("DisplayFrame")

framedisplay.Attributes("src") = strurl

End Sub

(NB: the strurl returned from appendscopetourl  works fine so please ignore call to this function, I dont believe that is the source of the problem! )

nothing happens after the click event handler is executed, i would expect the iframe to show the page according to strurl. 

I have a dynamically added commandbutton on my page and using the htmlcontainercontrol method of sending page to iframe (as coded above)works fine, which is weird because i would have thought a link button would be pretty much the same?

 Am i missing something fundamental to get the linkbutton to work, do i need to use the onclientclick event and register some javascript to get this going? If so could someone help me out a little more with syntax please as my javascript sucks!! (i am more used to windows development!)

Or could it be because when the button is clicked a postback is done and as the control is dynamically added, it is essentially removed and re-added in the load routine of the page?

Hope someone can shed some light on this for me!

0
cookster1976
3/12/2009 12:04:34 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
935 Views

Similar Articles

[PageSpeed] 26
Get it on Google Play
Get it on Apple App Store

This might help

http://www.aspsnippets.com/post/2009/03/01/Dynamic-Controls-Made-Easy-ASPNet.aspx


MAKMark as Answer if this reply helps you
MVP ASP/ASP.Net
MVP ASP/ASP.Net
ASP.Net Hosting : Host DepotMy Site : ASPSnippets
0
mudassarkhan
3/12/2009 12:25:40 PM
Reply:

Similar Artilces:

Button click event not getting fired for a custom webpart where controls are added dynamically.
 We are migrating from ASP.NET1.1/Sharepoint 2003 to ASP.NET 2.0/Moss 2007. We have a webpart on which controls are getting added dynamically. We have a button which is also dynamically added and a click event handler is also attached to it. However when we click on this button the page gets posted but the event is not fired. We analysed and found that the code to add the button in the webparts controls collection is executed but the code to add the button to it's container (that is a table) is not getting executed. Hence the event is not getting handled. If we forcefully add the bu...

Web User Control - Button Click
I have a web user control which is has one Button control on it. It has a event for handling the click... if I put this user control ( button ) at the top  of the page, the click event does not get fired just page is refreshed...but where as if I move to the bottom of the page, ButtonClick is fired ???? I am completely clueless why is this change of behavior with respect to the position of the control?? Thanks. could you show us the code that you have problem with ...   Here is the code ( i have taken out the unwanted part of the page ) Please note that the bSave does ...

Click Event Not Firing For Dynamically-Added LinkButtons
I'm a total newbie at this dynamic controls business.  Would really appreciate some help.  I can get some LinkButtons onto a page dynamically, but the event handler isn't getting called when I click on them.  Here's the code.The page looks like like this: Like I said, when you click on one of the LinkButtons (ie. "happy", "sad", whatever), a postback occurs but the lb_Click method isn't firing.  What am I doing wrong? MarvinIf, by some rare and amazing chance, I suggested a solution that actually worked for you, please mark the pos...

getting postback events to fire for dynamically added custom controls
I recently posted regarding these 2 controls, but this is a completely different issue, so I thought it best to start a new thread. I have two composite controls (neither renders content, rather they add controls to the control tree). Control X is declared on the page and is passed a custom collection. X iterates through this collection and creates a tab and a 'pane' for each item in the collection. To each pane it adds an instance of control Y, which contains a couple of textboxes and a hidden inputbox. My problem is: if I have a std button on the page which posts back, I need t...

Master Page, Dynamically creating web user control and Event not firing
I am sure all of you have seen this article by Scott Allen. Great Article http://odetocode.com/Blogs/scott/archive/2006/04/12/3271.aspx In here I saw a comment Thursday, May 04, 2006 11:50 AM by Priya # re: The MasterPage Article I Thought I’d Never Finish Good one. I have a custom control with a button. The button click event fires if the page is without master. But, after the master is added, the event does not fire. Can you please help with this? Thanks a lot. Do any of you know what the answer to this problem is. I have a similar issue. Let me explain issue in detail. I have a mast...

Button click event not fired for a custom webpart where controls are added dynamically.
We are migrating a Sharepoint 2003 site to MOSS 2007 and ASP.NET 2.0. We have also migrated the webparts but they are still inheriting from Sharepoint.WebPart. We have a webpart where controls are added dynamically at runtime. On this webpart a button is added dynamically and a click event handler is also attached. The button on the webpart is displayed only when there is some data. The button deletes the selected row of data when clicked. But when we click on the button, the page gets posted but the event handler is not called. We analysed and found that the code where we add the button to one of the table cells does not get executed. That means that the button is added to the webparts control collection but not to any other container's control collection and hence not added on the webpart. The button does not get displayed and event is also not handled. When we add the button forcefully to one of the container table, the event gets executed. Where are we going wrong? Or Is it an ASP.NET 2.0 limitation. Please note that this same code works extermely fine in ASP.NET 1.1 and Sharepoint 2003. Any help will be highly appreciated. Thanks.   I didn't see the code so can't say what exactly the problem it is. But develop customization webpart under Sharepoint 2003 and ASP.NET is NOT same as developement under Sharepoint 2007. Under 2007 the webpart are inheriting the namespace System.Web.UI.WebControls.WebParts. So pleas...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

Button Event Inside User Control Not Firing when Dynamically Created and added to Page.
Hello, I am dynamically Loading multiple instances of a UserControl and adding them to the Page.Controls collection. When I run the page the dynamically created Usercontrols are displayed with the proper data. However, when I click a LinkButton I have included in the UserControl to hide certain elements within the User Control the Page Posts back but the LinkButton.Click event does not fire inside the User Control. Further, if I just hard code the user control into the aspx file (giving me just the one instance) and I click the LinkButton the Click event does fire ins...

Dynamically adding linkbutton to panel, the click event doesn't fire
Hi All,I added linkbutton to a panel dynamically as follow. The linkbutton can show on the screen, but when I click the linkbutton, the whole panel disappears... I don't why...:( Thanks. private void AddButtonToPanel()    {        Label myLabel = new Label();        LinkButton myLinkButton;        Panel_CriteriaDrawing.Controls.Add(new LiteralControl("<div style=\"vertical-align:middle;width:400px;float:left;height:100%;text-align:center;\" >&q...

Adding events to controls, e.g. adding a click event to a label control
 Hi, Is it possible to add a click event to a label control so that one can make something happen when a user clicks the label? How can it be done? One could of course use a linkbutton control, which has an in-built click event. Unfortunately a linkbutton insists on doing a postback every time it is clicked.Thank you!Regards.   Label is span control in html call javascript onclick event <span id="fkdsjfl" onclick=" ">here</span> if you want to call postback event then chk ithttp://forums.devx.com/showthread.php?t=142257 If this post...

Event not firing with Dynamic Controls in a Custom Web Control
I'm creating some LinkButtons on the fly (on Load) and they show up just fine.  The problem is that the AddHandler event I created is not firing.  I'm at a loss...have read a ton of articles today, but just can't figure this one out.  Please help a newb! :-)Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) EnsureChildControls() If Me.Page.IsPostBack Then Me.Units = Me.rblUnits.SelectedValue 'If there is text in the txtSearch TextBox, then search for the new loc...

how to catch the id of dynamic linkbutton controls that has been Clicked on click event
this is how im creating Dynamic LinkButtons: void linkcheck(){LinkButton[] dy = new LinkButton[ds.Tables ["Employee"].Rows.Count-1]; dy[i] = new LinkButton (); dy[i].Click += new EventHandler(dynamiclinkbutton_Click); plh5.Controls.Add(dy[i]); necessary operation ;} now calling that click event on linkbuttonclick: private void dynamiclinkbutton_Click(object o,EventArgs e) {for (int k=0;k < ds.Tables["Employee"].Rows.Count-1;k++) {DataGrid1.EditItemIndex = Convert.ToInt32(ds.Tables["Employee"].Rows[k].ItemArray[0]);}binddata();} but im unable to catch the id of the linkbutton her...

web page opened as dialog does not fire page load event
All,I use the following code to open a web page  as a dialog formMe.btnAddInstruction.Attributes.Add("onclick", "var strReturn; strReturn = window.showModalDialog('AddInstruction.aspx',null,'toolbar:no;menubar:no;status:no;dialogWidth:350px;dialogHeight:350px;dialogHide:true;help:no;scroll:no');")The web page which is being opened has a page load event which populates combo boxes on the web page. However this page load event doesn't fire when the page is opened as a dialog but instead when the page is closed. Now I have a feeling its because the javascript used to open the web pa...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

using master page controls in content page and adding click event
Hi  I've currently got a control on my master page and i'm trying to write an even on the content page that fires when the button is clicked, I don't think it is working though. Can someone help? The code is below:  masterpage <asp:ImageButton id="imgButton" runat="server"/> code behind Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load, Me.Load Public ReadOnly Property lnkbFromMasterPage() As ImageButtonGetReturn imgButtonEnd GetEnd Property  content page code behind: Public Sub Page_Load(ByVa...

Custom User Controls and dynamically created web controls events not firing
I have a peculiar problem and since I am just starting to use .net I am confident I am doing something wrong, but I can't see it and I've wasted a lot of time so far trying to figure it out. Hopefully one of you can figure it out. I have a custom User Control and I am dynamically creating a RadioButtonList. If I remove the custom user control from the page the RadioButtonList works as expected and correctly. However, once I add the custom control, it does not fire the SelectedIndexChanged event. Below is some code. If all I do is remove: "<UC:TOPMENU id="TopMenu1"...

Web User Control dynamically generated control events won’t fire.
I hope someone can give me a hand on this one.   This is what I am trying to do:   We need to create a report. We are using a Repeater control to generate a custom grid. The columns and data fields won’t be known until run-time.   I’ve created a WebUserControl which contains a repeater control.   At run-time, I dynamically create templates for the header and data items. On the header template I want to use a LinkButton so that data can be sorted when the user clicks on one of the header columns.   In my Header Template class, I have a reference to a list o...

click event not firing for linkbuttons created after page load (AJAX Enabled Page)
i have an Ajax page and initially a link button is created dynamically (Text for this button is First Button) and is attached to a div which acts as placeholder. Its click event is defined dynamically. After clicking the button it will create another one (Text for this one is Second Button) and its click event is defined at the time of creation. It is also attached to the previous div by clearing its contents. So far so good. After clicking this button (Second button), the click event is not firing. It is showing the previous state. i.e. First button is displayed Hierarchy should be like th...

loading controls dynamically in content page and firing the js events and codebehind events
Hi, I have master page and cotent page.Now in the content page I am binding the master page. In the content page I need to load the controls dynamically and fire javascript events for the controls loaded and also codebehnind events. Also how when I try to load the controls dynamically the css settings are changed for the master page.How to prevent from changing the style sheet properties also. How to do this? thanks   thanks   You can add controls dynamically to the content place holder by doing something like this: Label l = new Label(); l.Text = "So...

how to open a web page in form of a popup web page
Hello, I have two web pages, let say. Page A : With a Button on it. PAge B: with some info. Now I need to: When I click on the Button of page A.Page B must open in a pop up window.  I can do this but problem is this when I clicked on the button for first time it does not show me any thing and when I clicked on the button for second time then It shows me Page B .My code is as follow:  1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!this.Page.IsPostBack) 4 { 5 6 } 7 else 8...

How to get HTML Source of web page opened by web browser using vb.net
hello friends,         i have opened an web browser in vb.net using the below code Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim nullObject As System.Object = 0 Dim str As String = "" Dim nullObjStr As System.Object = str Windows.Forms.Cursor.Current = Cursors.WaitCursor Dim i As Int16 For i = 1 To 2 AxWebBrowser1.Navigate("http://www.google.co.in/search?hl=en&q=test&meta=", True) AxWebBrowser1.Document. Next Windows.Forms.Cursor.Current = Cursors.Default End Sub  ...

RowCommand event in getting fired inplace of PageIndexchanging event when I click on pageIndex(Paging) in GridView
Hi,  I have a Gridview with a SELECT Button for every Row.Whenever user Clicks on SELECT Button,it redirects to another page with corresponding details.I have set paging too woth pagecount=10 and AllowPaging="True" for Grid.So I Have RowCommad event for SELECT button and PageIndexChanging Event for Paging.But Whenever I click on page No(1 2 3 4......),RowCommand Event is firing but not the PageIndexChanging event.Can anyone please help me in getting it Fixed.Thank you. post your markup and code behind so I can peek.  It looks like your event handlers got mixed up somew...

Dynamically add controls to user control based on Parent page button click event
Hi, I have a page which contains a button, a dropdownlist and a user control.  The user control is added to the parent page during page_load.    If the user clicks on the button, the value in the dropdownlist is passed to the usercontrol via the usercontrols public properties and is stored in its viewstate. The user control is dynamically populated with fields based on a database id passed to it from the parent page.  I gave the user control a public property which hooked into the ViewState bag of the user control so that I could pass it the database id at r...

To access a control placed in a web user control which is loaded during page load in button click event
How can I access a control in a web user control in a button click event , the user control is loaded in page load.Thanks & Regards,Abhiram Reddy Mekha. Try checking this... http://microsoft.apress.com/asptodayarchive/73869/event-handling-between-custom-user-controls-that-are-loaded-at-run-time http://aspalliance.com/565_Dynamic_Loading_of_ASPNET_User_Controls http://www.beansoftware.com/ASP.NET-Tutorials/Controls-Run-Time.aspx http://stackoverflow.com/questions/92792/user-control-created-dynamically-not-able-to-handle-events-on-postback http://www.codersource.net/asp_net_user_c...

Web resources about - dynamically added linkbutton control, click event firing but cannot get page to open in iframe - asp.net.web-forms

iPhone 5 A6 chip to dynamically up-clock up to 1.3GHz (and downclock too)?
Interesting video from our friends at TLDToday: If this is not just a Geekbench app glitch, it could indicate why that A6 processor is so 2X ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

iPhone 5 Lightning port dynamically reassigns pins
... of Apple's Lightning USB cable shows that the pins on the plug aren't arranged symmetrically, suggesting that the Lightning port can dynamically ...

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 2/15/2016 8:14:59 PM