User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 401,716 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,099 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4879 | Replies: 2
Reply
Join Date: Jan 2006
Posts: 3
Reputation: hint1979 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hint1979 hint1979 is offline Offline
Newbie Poster

Button event lost..

  #1  
Jan 25th, 2006
Hello ,

I read artical listed on link
http://www.tgreer.com/aspnet_html_04.html

What I am doing is.

on aspx page
1)There are two dropdown list on my .aspx page
2) One ddl ( drop down list) is populated on change of another one
3) One place holder to accomodate dynamic controls

On change of runtime populated ddl i am setting one session value to load which dynamic set of controls. This set of controls i read from XML and match with XSLT and display it.

dynamic set of user control's load mechenism reside in ascx ( User control) file.

There is one button i am adding runtime on the page load of ascx ( User control)

Every thing work fine first time and i get all the post back values on button click as well. when i change option in ddl . It load dynamic set of diffrenet controls fine as well.but button click lost. Intresting to know is if i click second time on button it works fine.

Code:

Code on .aspx page
==============
protected override void LoadViewState(object savedState)
{
base.LoadViewState(savedState);
if ( ViewState["mediaType"] != null)
{
if( ViewState["mediaType"].ToString() != "")
{
plControls.Controls.Clear();
plControls.Controls.Add(LoadControl("ucMediaXMLPar se.ascx"));

}
}
}

// On this index change i am loading another set of controls using XML
#region "Media Type Index Change"
private void cmbmedia_SelectedIndexChanged(object sender, EventArgs e)
{
if(cmbmedia.SelectedValue != null && cmbmedia.SelectedValue !="")
{
Session.Add ("mediaType",cmbmedia.SelectedValue.ToString()) ;
ViewState["mediaType"] = int.Parse(cmbmedia.SelectedValue);
plControls.Controls.Clear();
plControls.Controls.Add(LoadControl("ucMediaXMLPar se.ascx"));
plControls.Visible = true;
}
}
#endregion



On ascx ( user control)
===================
comments:
CreateControlsUsingXSLT method will match template with xml file and make controls
====================

#region "Page Load"
private void Page_Load(object sender, System.EventArgs e)
{
if ( Session["mediaType"] != null)
{
if( Session["mediaType"].ToString() != "")
{
Controls.Clear();
CreateControlsUsingXSLT(int.Parse(Session
["mediaType"].ToString()));

// this button click event has been lost
Button submitButton = new Button();
submitButton.Text= "Submit Me";
submitButton.ID= "btnSubmit";
submitButton.Click +=new EventHandler
(submitButton_Click);
Controls.Add(submitButton);
}
}
}
#endregion

private void CreateControlsUsingXSLT(int mediatype)
{
// mach with template and parse
// parse the controls and add it to the page
System.Web.UI.Control ctrlParsedControls = ParseControl(result);
Controls.Add(ctrlParsedControls);
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: Button event lost..

  #2  
Jan 25th, 2006
It is because everytime you reload all the controls everytime - every postback.
Remember the pageload etc is fired everytime you do something and is fired before the button click event, or selected change etc. so be very careful where you want things to run (ie choose your events - page load, init, loadviewstate etc - wisely) and also decide whether you want it to run every time or just on postback or not (use the Request.IsPostBack to check for this). You can always move parts or all of your function out of the event (i would not code in events either, just call them from events - thats good programming practice for web and windows apps) so you have full control.
I am not 100% sure what you want to do when so cant redo your code for you, but can give you pointers. Use the IsPostback and check the events you are using and whether it is the right one. 90% of unexpected results in apps are usually because the wrong event is chosen. Events are so similar so you have to understand them all to choose the right one (a simple example is the mousedown, mouseup and mouseclick - putting the same code in different events can have different results).
Reply With Quote  
Join Date: Jan 2006
Posts: 3
Reputation: hint1979 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hint1979 hint1979 is offline Offline
Newbie Poster

Re: Button event lost..

  #3  
Feb 3rd, 2006
Thanks F1 fan,

My problem was solved when i have transfer all the things to only one user controls. I mean i have transfered my both combos to usercontrol.

Steps i have taken care
1) put one place holder on aspx page to handle user control
2) transered both combos to usercontrol ascx
3) put one place holder on ascx (user control ) to hold the dynamically generated controls through xml and xslt
4) put on submit buttion on ascx and hide and display as per need.
5) transfer loadviewstate overridden function to ascx as well so on my aspx page there is only one place holder and on page load event of aspx i am loading user control.

any way thanks for your help.

Hint
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 8:57 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC