If $ isn't allowed within a ImageButton.ID, why doesn't ASP.Net helps me with this?

G

Guest

Dear all

I've found a problem with raising server-events from a LinkButton (although I suspect that other Controls have the same problem). It appears that if you set the ID property with a string containing "$" that the Server-Side events aren't fired. This is probably caused by the fact that the Javascript __doPostBack expects the $-sign to be used for some Control-identification magic. Now if this is the case I would expect ASP.Net to either raise an exception when I try to set the ID with such an invalid character, or do some kind of escaping to make sure it works transparantly for me. Below the code behind for a WebForm with which I've tested this. The aspx only contains a Panel named MyPanel. Does anyone know if this is something I could have known

using System
using System.Collections
using System.ComponentModel
using System.Data
using System.Drawing
using System.Web
using System.Web.SessionState
using System.Web.UI
using System.Web.UI.WebControls
using System.Web.UI.HtmlControls

namespace LinkButtonTes

public class WebForm1 : System.Web.UI.Pag

protected Panel MyPanel

private void Page_Load(object sender, System.EventArgs e

LinkButton lb = new LinkButton()
lb.ID = "_Edward$Test$X"
lb.Click += new EventHandler(lb_Click)
lb.Text = "CLICK which doesn't work"
MyPanel.Controls.Add(lb)

LiteralControl lc = new LiteralControl("<br/>")

MyPanel.Controls.Add(lc)

LinkButton lb2 = new LinkButton()
lb2.ID = "_EdwardTestX"
lb2.Click += new EventHandler(lb_Click)
lb2.Text = "CLICK which works"
MyPanel.Controls.Add(lb2)


#region Web Form Designer generated cod
!!!REMOVED for clarity!!
#endregio

private void lb_Click(object sender, EventArgs e

LiteralControl lc = new LiteralControl("<br/>Hello")
MyPanel.Controls.Add(lc)
 
G

Guest

Hi Bin

I'm aware of the fact that the contents of the ID of an HTML-tag is bound by rules, however, I'm using an ASP.Net Server-Control here. Although it ultimately will become an HTML-control, it's a more abstract concept, and I have the opinion that it's up to the creator of the ServerControl to make sure that the ID-property is correct, either by documenting what the allowed characters are and generating an Exception if I don't confirm to that, or make sure that by the time it gets converted to an HTM-Id it is in a correct form.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top