473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to call a specified url, outside of event click, to redirect

1
How to call a specified url, outside of event click, to redirect?

Expand|Select|Wrap|Line Numbers
  1. public void Page_Load(object sender, EventArgs e)
  2.     {
  3.         qry = "Select slink from Sites";
  4.         OleDbConnection con = new OleDbConnection(global.cs1);
  5.         OleDbCommand com = new OleDbCommand(qry, con);
  6.         con.Open();
  7.         OleDbDataReader re = com.ExecuteReader();
  8.  
  9.         while (re.Read())
  10.         {
  11.             i++;
  12.             Table tb = new Table();
  13.             tb.ID = "Table" + i;
  14.             this.form1.Controls.Add(tb);
  15.             TableRow Tr = new TableRow();
  16.             Tr.ID = "TableRow" + i;
  17.             tb.Controls.Add(Tr);
  18.             TableCell tc = new TableCell();
  19.             tc.ID = "TableCell" + i;
  20.             Tr.Controls.Add(tc);
  21.             LinkButton lnk = new LinkButton();
  22.             lnk.ID = "lnk" + i;
  23.             tc.Controls.Add(lnk);
  24.             lnk.Text = "" + re["slink"];
  25.             j = lnk.Text;
  26.             lnk.Click += new System.EventHandler(lnk_Click);
  27.             lbladd.Controls.Add(tb);
  28.         }
  29.         con.Close();
  30.     }
  31.  
  32.     public void lnk_Click(object sender, EventArgs e)
  33.     {
  34.      //Here is problem to redirect to that particular link 
  35.     }
Aug 2 '12 #1
1 1265
Frinavale
9,735 Expert Mod 8TB
You are dynamically creating LinkButtons within your PageLoad event.

The problem with this is that when the LinkButton is clicked, it posts back to the server for processing the Click event.

But the Click Event for the LinkButton is generated in the PageInit event.

The PageInit event occurs before the PageLoad event and so since the LinkButton doesn't exist at that time, the Click Event is never generated...

This is why your lnk_Click method is never being executed.

So, instead of dynamically creating the LInkButtons in the PageLoad event, I recommend that you use a Repeater Control to dynamically create your table (with links within it).

-Frinny
Aug 2 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jack | last post by:
Hello, By VBScript ASP How can I call a function by click one button? May you help me
2
by: harry | last post by:
Hi I am trying to add an event handler to the window so that If the user clicks the close window button, it creates a popup to tell the user it should use the log out button before closing window....
8
by: dbuchanan | last post by:
Hello, What does this error mean? "The event click is read-only and cannot be changed" This is a design-time error. It is displayed instead of the form. Here is the full text \\ "One or...
2
by: moi | last post by:
Hello, i would like a sample code to call a button click with the event "textchanged" of a textbox. I just would like to valide a textbox with the textchanged event and not to click on the submit...
3
by: Bryan | last post by:
I pass my form's collection of controls to a public sub in a module that loops through and checks for any ErrorProvider text. The sub returns all the ErrorProvider strings that were found for...
1
by: ThunderMusic | last post by:
Hi, I want to use a class (if possible other than Socket) which one I could call a custom handler and receive the redirect code it sends... Actually, I tried using the WebClient class, but when...
3
by: =?Utf-8?B?T2xlZw==?= | last post by:
(in .NET 2.0 with AJAX extensions) I have an UpdatePanel on the form. Now I want to use a link outside of my UpdatePanel to make it to update (asynchronously) and also send some(at least one )...
3
by: phpmel | last post by:
hi guys, I have 2 gridviews, one inside a modal popup(gvSuppliers) and one on the page(gvFirms). The header row of the gvFirms has 4 text boxes. I can find those controls easily inside the...
1
by: gracepaul | last post by:
hi all, I want to call the Mouse_Click event from the previous form f1 in the next form f2. how can do that? when i close the form f2 and then raise the mouse_click event in form f1 at that...
1
by: gayat jain | last post by:
jsf <h:select item> how i can call bean method one click any select item
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.