Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Attributes.Add not working in composite control

Posted on 2008-09-30
5
Medium Priority
?
548 Views
Last Modified: 2013-12-17
I have a ton of composite controls and i have the Attributes.Add function on a lot of my asp controls inside of them. I noticed something. If i go directly to the page via the menu or typing a url, the attributes are added flawlessly. If i do a response.redirect or server.transfer, these attributes dont get added. If i hit f5 then the attributes appear. What is the problem? Heres the piece of code where im adding the attribute:

  protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            addBtn.Click += new EventHandler(addBtn_Click);
            addBtn.Text = "Add Leg";
            //addBtn.OnClientClick = "MyFunc();"; <--this doesnt work either
            addBtn.Attributes.Add("onclick", "MyFunc();");
}
0
Comment
Question by:troycomp
  • 3
  • 2
5 Comments
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22610261
You are using the OnInit which may not be getting called when you use the other methods since the page may already be initialized at that point.  Try moving this code to your page load sub.
0
 

Author Comment

by:troycomp
ID: 22610335
It is getting called. I put a breakpoint on the line in question and it stoped. I also moved it to the CreateChildControls() method and still a no go. This has to do with the difference between response.redirect (or server.transfer) and accessing the page directly. Thats the only difference in what im doing.
0
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 1500 total points
ID: 22610448
If it were differences in Server.Transfer and Response.Redirect may have been differences in how page transfer, but not sure why then for your case where both don't work if moving the code to Page_Load didn't fix the issue.
0
 

Author Comment

by:troycomp
ID: 22610556
I added it to page_load on the aspx page and it works now. I misunderstood you earlier.  Honestly im doing this for another one of my controls. Ive worked almost 30 hours in 2 days so my brain is tired. Thanks

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22610571
Not a problem at all.

Glad I re-iterated it.  I was actually just trying to let you and other experts know I was out of ideas beyond the Page_Load so you would get the help you needed. :)

Anyway, good luck with remainder of the project.

Regards,
Kevin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question