Click here to Skip to main content
15,891,567 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: TabContainer in AjaxControlToolkit Pin
Illegal Operation21-Aug-07 20:38
Illegal Operation21-Aug-07 20:38 
Questionpdf file Pin
yesu prakash21-Aug-07 20:04
yesu prakash21-Aug-07 20:04 
AnswerRe: pdf file Pin
Christian Graus21-Aug-07 20:08
protectorChristian Graus21-Aug-07 20:08 
GeneralRe: pdf file Pin
yesu prakash21-Aug-07 20:11
yesu prakash21-Aug-07 20:11 
GeneralRe: pdf file Pin
N a v a n e e t h21-Aug-07 20:17
N a v a n e e t h21-Aug-07 20:17 
GeneralRe: pdf file Pin
Christian Graus21-Aug-07 20:22
protectorChristian Graus21-Aug-07 20:22 
AnswerRe: pdf file Pin
Vasudevan Deepak Kumar21-Aug-07 21:06
Vasudevan Deepak Kumar21-Aug-07 21:06 
QuestionCalling a method outside of Page_Load is not working [modified] Pin
shivamray21-Aug-07 19:59
shivamray21-Aug-07 19:59 
Hello,

This is starting to really bug me. If I make a call to a function from the Page_Load it does what it supposed to do, but if I make the same call from a control on the page it does not work properly.

I am trying to create a function that dynamically creates drop down lists, bound to a db, and then sets the "onchange" property so that when the user changes the selected item it posts back and executes code on the server side. Here's my code behind:


<br />
using System;<br />
    using System.Data;<br />
    using System.Configuration;<br />
    using System.Collections;<br />
    using System.Web;<br />
    using System.Web.Security;<br />
    using System.Web.UI;<br />
    using System.Web.UI.WebControls;<br />
    using System.Web.UI.WebControls.WebParts;<br />
    using System.Web.UI.HtmlControls;<br />
   <br />
   public partial class testcode : System.Web.UI.Page<br />
   {<br />
       protected void Page_Load(object sender, EventArgs e)<br />
       {<br />
           DropDownList ddl1 = new DropDownList();<br />
           ddl1.Items.Add("Item1");<br />
           ddl1.Items.Add("Item2");<br />
           ddl1.AutoPostBack = true;<br />
           form1.Controls.Add(ddl1);<br />
           ddl1.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);        <br />
       }<br />
       protected void x(object sender, EventArgs e)<br />
       {<br />
           DropDownList ddl2 = new DropDownList();<br />
           ddl2.Items.Add("1");<br />
           ddl2.Items.Add("2");<br />
           ddl2.AutoPostBack = true;<br />
           form1.Controls.Add(ddl2);<br />
           ddl2.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);<br />
       }<br />
       void ddl_SelectedIndexChanged(object sender, EventArgs e)<br />
       {<br />
           <br />
           <br />
           Response.Write("works");<br />
       }<br />
   }<br />



And my .aspx:
<br />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testcode.aspx.cs" Inherits="testcode" EnableViewState="true" %><br />
    <br />
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
    <br />
    <html xmlns="http://www.w3.org/1999/xhtml" ><br />
    <head runat="server"><br />
        <title>Untitled Page</title><br />
    </head><br />
    <body><br />
       <form id="form1" runat="server"><br />
      <asp:Button runat="server" Text="Push Me" OnClick="x" />   <br />
       </form><br />
   </body><br />
   </html><br />



The dropdownlist that is created on page load works fine, and upon changing the selected item from this dropdownlist it is able successfully call the correct function. However, the dropdownlist created by the button is not able to call the function properly, it just causes a page reload, and the second dropdownlist created by the button dissapeasrs. Any help would be greatly appreciated!

Thanks,

Shivam.


-- modified at 2:37 Wednesday 22nd August, 2007
AnswerRe: Calling a method outside of Page_Load is not working Pin
Christian Graus21-Aug-07 20:06
protectorChristian Graus21-Aug-07 20:06 
GeneralRe: Calling a method outside of Page_Load is not working Pin
shivamray21-Aug-07 20:12
shivamray21-Aug-07 20:12 
GeneralRe: Calling a method outside of Page_Load is not working Pin
N a v a n e e t h21-Aug-07 20:19
N a v a n e e t h21-Aug-07 20:19 
GeneralRe: Calling a method outside of Page_Load is not working Pin
shivamray22-Aug-07 22:30
shivamray22-Aug-07 22:30 
GeneralRe: Calling a method outside of Page_Load is not working Pin
Christian Graus21-Aug-07 20:20
protectorChristian Graus21-Aug-07 20:20 
QuestionCompilation in VWD 2008 Pin
sacheesach21-Aug-07 19:48
sacheesach21-Aug-07 19:48 
AnswerRe: Compilation in VWD 2008 Pin
Illegal Operation21-Aug-07 20:40
Illegal Operation21-Aug-07 20:40 
GeneralRe: Compilation in VWD 2008 Pin
sacheesach21-Aug-07 20:45
sacheesach21-Aug-07 20:45 
GeneralRe: Compilation in VWD 2008 Pin
Illegal Operation21-Aug-07 20:55
Illegal Operation21-Aug-07 20:55 
QuestionSession Not Ending even after Logging Out!! Pin
SrividhyaS21-Aug-07 19:45
SrividhyaS21-Aug-07 19:45 
AnswerRe: Session Not Ending even after Logging Out!! Pin
N a v a n e e t h21-Aug-07 20:34
N a v a n e e t h21-Aug-07 20:34 
AnswerRe: Session Not Ending even after Logging Out!! Pin
sulabh202021-Aug-07 20:38
sulabh202021-Aug-07 20:38 
QuestionRegular Expression Validator Pin
NICE TO MEET21-Aug-07 19:07
NICE TO MEET21-Aug-07 19:07 
AnswerRe: Regular Expression Validator Pin
Sathesh Sakthivel21-Aug-07 19:23
Sathesh Sakthivel21-Aug-07 19:23 
AnswerRe: Regular Expression Validator Pin
Revathij21-Aug-07 19:59
Revathij21-Aug-07 19:59 
AnswerRe: Regular Expression Validator Pin
mangrovecm22-Aug-07 15:47
mangrovecm22-Aug-07 15:47 
Questionhow to access session variables in html page Pin
dharanighanta21-Aug-07 18:35
dharanighanta21-Aug-07 18:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.