Button event is not firing in ascx control when loaded on aspx page

 Hi,

I used code like this for Dynamically  loading usercontrol in aspx page.

            Control uc1 = LoadControl("Users/userdetails.ascx");
            PlaceHolder1.Controls.Add(uc1);

But in userdetails.ascx page i have "Submit" button when i Click on button it was not firing.

please any one help me why it was happening,suggest me how to solve this problem.

 Thanks in Advance
0
arifslife
7/15/2008 1:34:18 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

9 Replies
2448 Views

Similar Articles

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

Hi,

in which event do you add your usercontrol? Because you can run into problems like yourone if you add the UC on every new pageload.


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
0
ArminStockner
7/15/2008 2:21:09 PM

In Parent.aspx page I placed PlaceHolder,and in that there is “Personal” button in that button event iam dynamically loading usercontrol.

Below is the code I wrote:

protected void btnPersonalInfo_Click(object sender, EventArgs e)

{

Control uc1 = this.LoadControl("userdetails.ascx");

Controls.Add(uc1); cntrlPanel.Controls.Add(uc1);

}

In “userdetails.ascx” control I have “Submit” button,but it was not firing.When i clicked to Submit button it redirecting to Parent.aspx page.

Please give me suggestions how solve this issue.

Thanks in advance.

0
arifslife
7/15/2008 2:42:36 PM

 First thing I can recognize:

Controls.Add(uc1);

cntrlPanel.Controls.Add(uc1);

Let out the first line. What do you try with the Controls.Add?

And can you post your submit method code.


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
0
ArminStockner
7/15/2008 2:52:20 PM

 hi

sorry the 1st line Controls.Add(uc1) was not there.

In userdetails.ascx  control i took one submit button like this:

<asp:Button ID="btnSubmit" OnClientClick="ValidateAll()" OnClick="btnSubmit_Click" runat="server" Text="Submit" BackColor="#2B82B8" BorderColor="#E0E0E0" BorderWidth="1px" ForeColor="White" Font-Bold="True" />

 userdetails.ascx.cs page

  protected void btnSubmit_Click(object sender, EventArgs e)
        {

            if (cmbBirthDay.SelectedValue == "00" && cmbBirthMonth.SelectedValue == "00" && cmbYear.Text == "00")
            {
                lblBirthDate.Text = "Birth Date";
                return;
            }
            else if (cmbBirthDay.SelectedValue == "00")
            {
                lblBirthDate.Text = "Day";
                return;
            }
            else if (cmbBirthMonth.SelectedValue == "00")
            {
                lblBirthDate.Text = "Month";
                return;
            }
            else if (cmbYear.SelectedValue == "00")
            {
                lblBirthDate.Text = "Year";
                return;
            }

            if (rdGender.SelectedIndex == 0)
            {
                sex = "Male";
            }
            else
            {
                sex = "Female";
            }

            string birthdate = cmbBirthDay.SelectedValue + "/" + cmbBirthMonth.SelectedValue + "/" + cmbYear.SelectedValue;
            objUserBLL.UpdateUserSettings(txtFirstName.Text, txtLastName.Text, sex, txtMessebgerEmail.Text, txtPassword.Text, txtContactMail.Text, txtMobile.Text, birthdate, txtHomeTown.Text);
           

        }

But after clicking the page this submit button event was not firing.It just reloading parent page.

plz give me solution its very urgent for me.

 Thanks in Advance.


 

0
arifslife
7/15/2008 3:24:49 PM

 Maybe the error comes with your onClientClick Event. Try to put it out shortly.


Please: Don't forget to click "Mark as Answer" on the post that helped you. That way future readers will know which post solved your issue.
0
ArminStockner
7/15/2008 3:44:07 PM

hi, i remove that onclient click but button event was not firing.. how to solve this issue,can u plz give me any code or any idea to acheive this.

 

thanks in advance 

0
arifslife
7/16/2008 1:13:10 PM

Never mind...

How do you delete a post?

0
brucevde
7/16/2008 2:03:22 PM

Hi arifslife,

I think you can put the following code into function Page_load.

If you put it into button click, it will disappear after postback.

protected void btnPersonalInfo_Click(object sender, EventArgs e)

{

Control uc1 = this.LoadControl("userdetails.ascx");

Controls.Add(uc1);

cntrlPanel.Controls.Add(uc1);

}

protected void Page_Load()

{

Control uc1 = this.LoadControl("userdetails.ascx");

Controls.Add(uc1);

cntrlPanel.Controls.Add(uc1);

}

 

Let me know if I have misunderstood what you mean.
Thanks.
Waiting for your result,
Hua Jun


Sincerely,
Hua Jun Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hua
7/17/2008 10:02:28 AM
Did u set reference for the usercontrol on corresponding page
With Cheers
P.Durai

-------------------****--------------
Please mark as answer if it is useful to you
0
yespeedurai
7/17/2008 10:19:47 AM
Reply:

Similar Artilces:

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 page .aspx is slow when loading. Pages have web user controls on them that are loaded dynamically
I have written a web application using VS 2003. Several of my forms have web user controls on them. The controls are loaded dynamically at runtime. The problem is that the web pages are very slow to load. Does anyone know if there is a way to speed up the pages being loaded into the browser? Here is an example of some code I use to dynamically load the controls:  private void Page_Load(object sender, System.EventArgs e)  {   // Put user code to initialize the page here   // Put user code to initialize the page here    Co...

C# .NET need button to fire without fire page load event
I have a asp.net button on my form. I need to fire click event of button without firing page load event of page. Anybody know what the trick is? Thanks in advance. Hi there! Then you shouldn't use the asp.net's WebControls.Button but instead use normal html button because WebControls.Button always fires the post-back. You must use a javascript function to do something when the button is clicked. <input type="button" value="Click me!" onclick="Clicked();"> .... //Then you must have a function "Clicked()": <script lan...

Urgent!!! Form inside Windows form control (that is embedded to Web page i.e aspx), not displayed on button click
 Hi all I have a Windows Form Control(i.e Windows Control Library), that consists of a Button "button1" and  a panel "panel1". Also I have a form "form1.cs". On form "form1.cs" I have a label whose text value i have set to  "Hi". On click of button "button1" on windows form control i am opening the form "form1.cs"  inside a panel and it displays "Hi". The code of windows form control is as below :  public partial class UserControl1 : UserControl    {    ...

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 ...

User control image button event not firing on first page load
Hello, I have a page (Parent.aspx) with a panel on it. In the panel, I dynamically load user controls (Child.ascx). The first time I click on the image button on Child.ascx, the following events happen: 1. Page_Load for Parent.aspx fires. Here, I reload Child.ascx. 2. Page_Load for Child.ascx fires.   Any subsequent clicks of the image button on Child.ascx triggers the following: 1. Page_Load for Parent.aspx fires. Here, I reload Child.ascx. 2. Page_Load for Child.ascx fires. 3. ImageButton_Click fires.   Obviously, I would like the ImageButton_Click sub to fire the firs...

Pls Help: Inheritance Control declared in aspx: Button Event firing! Inheritance control created programmatically: buttons NOT Firering
Hello all,Facing a problem again hope u can help me out:Control:   [Serializable] public class HeaderField { public string HeaderText { get; set; } public bool NotSortable { get; set; } public string SortExpression { get; set; } public HeaderField(string text, string sortExp) { HeaderText = text; SortExpression = sortExp; } } public class EviSorterCommandEventArgs : CommandEventArgs { public string Message { get; set; } public EviSorterCommandEventArgs(string message, CommandEventArgs origi...

Using a user control 2 times on a page: first one fires all events, second one fires all events but not 4 buttons
Hello!Edit solved:The problem was that depending on the databind i didn't add the buttons to the control tree instead of simple set visible to false. This worked fine for the first user control cause databinding was triggered on Page_Load but for the secon one the databidning took place later on so the condition not to add the buttons to the control tree set in. The simple solution was to always add the buttons to the control  tree and then check on Pre_render if the visaibility had to be set to false.So always keep in ind:1) Add controls to the control tree for the postback ev...

Button Click event is not firing when ajax modal popup control is used in my aspx page
Hi to all ,my problen is without using ajax my application is working fine but my problem is i have to display an error message in ajax modal popup contol when i click on a button aftter using ajax contol my button click event it self is not firing can u please help me in solving my problem its very urgent the sample code is as follows protected void Page_Load(object sender, EventArgs e) { //Button1.Attributes.Add("onclick", "javascript:return onOk(" + TextBox1.Text + ")"); }protected void Button1_Click(object sender, EventArgs e) {  Butt...

Validating web user control(ascx) in parent page (aspx) -- .NET 1.1
Hi,  I have a user control which has some asp.net server controls like drop down list, list box etc. These fields are required. I'm using this control in a parent page which has its own server controls which are also required. The button on the parent page which is supposed to validate the controls is not working after I add the web user control.  Is there a work-around for this scenario  other than manually calling Page.Validate() and checking for Page.IsValid property ? I tried calling a javascript on button click which calls Page_ClientValidate() whic...

Button CLick Event + Page Load Event ( Why does Page load clear all my variables )
super asp noob here ---and i hve to get this done asap --- thxn everyone for reading and responding heres my program in psuedo code page load () { make_table() }   public make_ table () { make a table - read data from a database- set  data -- store lots of data in arrays and variables }   button1_click () { get_data }   public get_data() { get all  the data from the variables-- read from the  table--+ all the variables store the data }  --------------------------------------  basically the user can enter in data&nb...

Determine the Control Events fired in Page Load Event
Suppose If i have a button control on my form and i click on button to post back, in this case Click Event of the button will called after Page Load Event.I need to know how can i determine which Event of which control is fired in Page Load Event before the itself control's event called.Do let me know If you don't get my point please."Hope its your Solution so Mark it as Answer"Ahmad SheikhMicrosoft Valuable Geekhttp://sharpcontents.blogspot.com If I understand your question, I believe that you are asking for which control events fire during the Page_Load event.  If ...

Dynamically loaded Web User Control .ascx button click event handler not called on second time click
I have an ascx control (that performs actions for an entity) being added dynamically to accordion panes, and then the panes are added to an ajax accordion control, so that the accordion can contain multiple panes with each pane containing one ascx control. The ascx control contains a delete button which removes the entity from the database. Once the entity is removed, I need to reflect this deletion in the parent page by removing the accordion pane from the accordion. To do this I created a delegate function and which is called from the parent page to rebind the accordion and hence not d...

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...

Web resources about - Button event is not firing in ascx control when loaded on aspx page - asp.net.web-forms

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Is Hillary Clinton sorry she reacted to the San Bernardino massacre with a call for more gun control ...
... "Gun safety" has traditionally meant handling your guns safely, but now it's supposed to mean what has more commonly been called "gun control." ...

more pics from Ground Control Touring 15th anniversary: Woods, Kurt Vile, Parquet Courts, Beach Fossils ...
... Parquet Courts / Woods & Kurt Vile / Beach Fossils @ Webster Hall 12/2/2015 We already posted a review and set of pictures from Ground Control ...

Chris Christie: NYT gun control op-ed "liberal claptrap"
N.J. governor and GOP presidential candidate tells "Face the Nation" stricter gun laws won't "stop terrorists from attacking us"

Liberals Soft On Bomb Control? Are You Sure You Want To Go There, Marco?
... reports: Appearing on Fox & Friends , 2016 GOP presidential contender Marco Rubio hammered at Democrats for proposing additional gun control ...

Christie: Democratic Gun Control Proposals Are ‘Just Like Eating Cotton Candy, It Does Nothing Good’
Christie: Democratic Gun Control Proposals Are ‘Just Like Eating Cotton Candy, It Does Nothing Good’

Open thread for night owls: First U.S. birth control clinic lasted just 10 days before being raided
... Parenthood Only Lasted for 10 Days but Started a Revolution . An excerpt: During her time in Europe, Sanger had seen Norwegian birth control ...

Facebook Gives Users More Control Over Viral Content In News Feed
Facebook is updating its algorithm to give users more control over how high viral content appears in their News Feed.

BUSINESS IS BOOMING Firearm buys likely to spike amid gun control push
BUSINESS IS BOOMING Firearm buys likely to spike amid gun control push

Watch: 'The View' Co-Hosts Discuss Gun Control
People on the terror watch list can still legally buy guns in America.

Resources last updated: 12/6/2015 5:07:10 AM