How do I get the form name my controls are in?

D

Dale

Greetings

I am building a composite control that populates a CheckBoxList with values from a database. A HtmlInputText control allows the user to type in the checkbox label value and have it checked in the list. All of the values are 3 characters in length, so I have a client-side onKeyUp checking the length of entry. If it is 3, then I do a postback. What I want to be able to do is have the text selected in the HtmlInputText after the postback. Right now, I am doing that with Page.RegisterStartupScript in my Render event. But I am having to use sScript += "Form1." & _filterText.ClientID & ".select();" to do it. I am concerned that if the developer changes the name of the form from Form1 to something else, that it will break. How do I get the actual form name

Thanks

Dale.
 
S

Stanley

Try doing something like:

document.forms[0]." & _filterText.ClientID & ".select();

That way you just get the first form.

-Stanley


Dale said:
Greetings.

I am building a composite control that populates a CheckBoxList with
values from a database. A HtmlInputText control allows the user to type in
the checkbox label value and have it checked in the list. All of the values
are 3 characters in length, so I have a client-side onKeyUp checking the
length of entry. If it is 3, then I do a postback. What I want to be able
to do is have the text selected in the HtmlInputText after the postback.
Right now, I am doing that with Page.RegisterStartupScript in my Render
event. But I am having to use sScript += "Form1." & _filterText.ClientID &
".select();" to do it. I am concerned that if the developer changes the
name of the form from Form1 to something else, that it will break. How do I
get the actual form name?
 
B

Barry

Dale,
I've used code like the following to get the form name, but it relies on the form name being the same as the aspx page name.

private void getFormName()
{
//string formName ;
string[] _path = this.Request.CurrentExecutionFilePath.Split('/');
int count = _path.Length - 1;
string name = _path[count];
this.i_FormName = name.Substring(0, name.LastIndexOf("."));
}

----- Dale wrote: -----

Greetings.

I am building a composite control that populates a CheckBoxList with values from a database. A HtmlInputText control allows the user to type in the checkbox label value and have it checked in the list. All of the values are 3 characters in length, so I have a client-side onKeyUp checking the length of entry. If it is 3, then I do a postback. What I want to be able to do is have the text selected in the HtmlInputText after the postback. Right now, I am doing that with Page.RegisterStartupScript in my Render event. But I am having to use sScript += "Form1." & _filterText.ClientID & ".select();" to do it. I am concerned that if the developer changes the name of the form from Form1 to something else, that it will break. How do I get the actual form name?

Thanks.

Dale
 
J

Jiho Han

You *could* walk up the control tree until you find an instance of HtmlForm.

Barry said:
Dale,
I've used code like the following to get the form name, but it relies
on the form name being the same as the aspx page name.
private void getFormName()
{
//string formName ;
string[] _path = this.Request.CurrentExecutionFilePath.Split('/');
int count = _path.Length - 1;
string name = _path[count];
this.i_FormName = name.Substring(0, name.LastIndexOf("."));
}

----- Dale wrote: -----

Greetings.

I am building a composite control that populates a CheckBoxList with
values from a database. A HtmlInputText control allows the user to type in
the checkbox label value and have it checked in the list. All of the values
are 3 characters in length, so I have a client-side onKeyUp checking the
length of entry. If it is 3, then I do a postback. What I want to be able
to do is have the text selected in the HtmlInputText after the postback.
Right now, I am doing that with Page.RegisterStartupScript in my Render
event. But I am having to use sScript += "Form1." & _filterText.ClientID &
".select();" to do it. I am concerned that if the developer changes the
name of the form from Form1 to something else, that it will break. How do I
get the actual form name?
 

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

Forum statistics

Threads
473,890
Messages
2,569,972
Members
46,310
Latest member
ClariceGal

Latest Threads

Top