Client Generated IDs and JavaScript
-
Hi, When we use HtmlControls or WebControls with runat=server, server automatically generates the required StyleSheets, JavaScripts etc, but the ID is now regenerated as _ctl13_txtName :confused::confused: If we restrict ourselves to RequiredFieldValidators and/or serverside validation and throw a message, everything is okay? But if we need to append our custom JavaScript for any of the elements, then comes how to access individual elements. I have been trying out the following shortcut. After </form> I insert some script language javascript to be executed on window.onLoad to get the index of the form elements that I need to access in my scripts. Then I do a eval("document.myform.elements["+indexValue+"]").value I am not sure whether this is a right solution or is there a better solution for this problem. Perhaps we can also use getElementById() but is it not heavy for the browser since again constructing a DOM tree etc? Please advise... Deepak Kumar Vasudevan http://deepak.portland.co.uk/
-
Hi, When we use HtmlControls or WebControls with runat=server, server automatically generates the required StyleSheets, JavaScripts etc, but the ID is now regenerated as _ctl13_txtName :confused::confused: If we restrict ourselves to RequiredFieldValidators and/or serverside validation and throw a message, everything is okay? But if we need to append our custom JavaScript for any of the elements, then comes how to access individual elements. I have been trying out the following shortcut. After </form> I insert some script language javascript to be executed on window.onLoad to get the index of the form elements that I need to access in my scripts. Then I do a eval("document.myform.elements["+indexValue+"]").value I am not sure whether this is a right solution or is there a better solution for this problem. Perhaps we can also use getElementById() but is it not heavy for the browser since again constructing a DOM tree etc? Please advise... Deepak Kumar Vasudevan http://deepak.portland.co.uk/
Perhaps this is what u want... This sample is from .net sdk documentation. void Page_Load(Object sender, EventArgs e) { TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');"; }
Attributes Property of a Web Control
-
Perhaps this is what u want... This sample is from .net sdk documentation. void Page_Load(Object sender, EventArgs e) { TextBox1.Attributes["onblur"]="javascript:alert('Hello! Focus lost from text box!!');"; }
Attributes Property of a Web Control
Hi Manish, Adding JavaScript function from CodeBehind is okay with me. But my actual problem was managing with the dynamically generated IDs for the control. Deepak Deepak Kumar Vasudevan http://deepak.portland.co.uk/