Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Saturday, March 24, 2012

set focus to textbox after click event- tried everything please please help!

Hello-
I have a form which has a listbox, a textbox and a submit button. The
user types a phone number into the textbox, clicks button, text gets
added to the listbox. After this process I need the focus to be back
in the textbox. Sounds easy hu?
Here's my code-

Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddLine.Click

lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
txtAddLine.Text = ""
setFocus(txtAddLine)

End Sub

Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)

Dim strS As String
strS = "<SCRIPT language='javascript'>document.getElementById('" +
ctrl.ID + "').focus();</SCRIPT>"
RegisterStartupScript("focus", strS)

End Sub

This will not place the focus in the textbox. What am I missing?

Again, PLEASE help. Thanks much!On 7 Jul 2004 10:42:20 -0700, JC <ujjc001@.charter.net> wrote:

> Hello-
> I have a form which has a listbox, a textbox and a submit button. The
> user types a phone number into the textbox, clicks button, text gets
> added to the listbox. After this process I need the focus to be back
> in the textbox. Sounds easy hu?
> Here's my code-
> Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdAddLine.Click
> lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
> txtAddLine.Text = ""
> setFocus(txtAddLine)
> End Sub
> Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
> Dim strS As String
> strS = "<SCRIPT language='javascript'>document.getElementById('" +
> ctrl.ID + "').focus();</SCRIPT>"
> RegisterStartupScript("focus", strS)
> End Sub
> This will not place the focus in the textbox. What am I missing?
> Again, PLEASE help. Thanks much!

Do you get a JS error? I assume you are; your control will get a unique
client ID that .NET creates on the actual HTML, so you can't just look for
ctrl.ID. Try ctrl.ClientID

http://msdn.microsoft.com/library/e...rmscontrols.asp

--
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
gah, dang sig...ignore, just testing/updating my sig correctly..

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7 Jul 2004 10:42:20 -0700, ujjc001@.charter.net (JC) wrote:

>Hello-
>I have a form which has a listbox, a textbox and a submit button. The
>user types a phone number into the textbox, clicks button, text gets
>added to the listbox. After this process I need the focus to be back
>in the textbox. Sounds easy hu?
>Here's my code-
>Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles cmdAddLine.Click
>lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
>txtAddLine.Text = ""
>setFocus(txtAddLine)
>End Sub
>Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
>Dim strS As String
>strS = "<SCRIPT language='javascript'>document.getElementById('" +
>ctrl.ID + "').focus();</SCRIPT>"
>RegisterStartupScript("focus", strS)
>End Sub
>This will not place the focus in the textbox. What am I missing?
>Again, PLEASE help. Thanks much!

Put a blank label at the bottom of the form and set its text property
in the codebehind instead of using the registerstartupscript.

-Adam
:o) You're all wrong. I took and made a clean application and it
worked, so I knew it wasn't the code there. I went back to my app,
(made a copy) and proceded to strip everything out until it worked.
Well, after everything was gone it still didn't work. There was only
one remaining thing, smartnavigaion = true.
That fixed the focus problem by turning it off, however it introduced a
whole new set of problems.
Having a database application, the users need to not use the back
button. I've got all the standard code for this but it's still not as
clean as smartnav.
Is there ANY way to overcome smartnav's focus problem?
MICROSOFT??
I didn't think so.
Anyhow, I've solved one problem only to intoduce many more. I may have
more ?'s soon, some really good ones I've been working on. Thanks for
the help so far.
Jeff

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

set focus to textbox after click event- tried everything please please help!

Hello-
I have a form which has a listbox, a textbox and a submit button. The
user types a phone number into the textbox, clicks button, text gets
added to the listbox. After this process I need the focus to be back
in the textbox. Sounds easy hu?
Here's my code-
Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdAddLine.Click
lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
txtAddLine.Text = ""
setFocus(txtAddLine)
End Sub
Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
Dim strS As String
strS = "<SCRIPT language='javascript'>document.getElementById('" +
ctrl.ID + "').focus();</SCRIPT>"
RegisterStartupScript("focus", strS)
End Sub
This will not place the focus in the textbox. What am I missing?
Again, PLEASE help. Thanks much!On 7 Jul 2004 10:42:20 -0700, JC <ujjc001@.charter.net> wrote:

> Hello-
> I have a form which has a listbox, a textbox and a submit button. The
> user types a phone number into the textbox, clicks button, text gets
> added to the listbox. After this process I need the focus to be back
> in the textbox. Sounds easy hu?
> Here's my code-
> Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles cmdAddLine.Click
> lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
> txtAddLine.Text = ""
> setFocus(txtAddLine)
> End Sub
> Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
> Dim strS As String
> strS = "<SCRIPT language='javascript'>document.getElementById('" +
> ctrl.ID + "').focus();</SCRIPT>"
> RegisterStartupScript("focus", strS)
> End Sub
> This will not place the focus in the textbox. What am I missing?
> Again, PLEASE help. Thanks much!
Do you get a JS error? I assume you are; your control will get a unique
client ID that .NET creates on the actual HTML, so you can't just look for
ctrl.ID. Try ctrl.ClientID
http://msdn.microsoft.com/library/e...br />
rols.asp
Using Opera's revolutionary e-mail client: http://www.opera.com/m2/
gah, dang sig...ignore, just testing/updating my sig correctly..
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
On 7 Jul 2004 10:42:20 -0700, ujjc001@.charter.net (JC) wrote:

>Hello-
>I have a form which has a listbox, a textbox and a submit button. The
>user types a phone number into the textbox, clicks button, text gets
>added to the listbox. After this process I need the focus to be back
>in the textbox. Sounds easy hu?
>Here's my code-
>Private Sub cmdAddLine_Click(ByVal sender As System.Object, ByVal e As
>System.EventArgs) Handles cmdAddLine.Click
>lstLines.Items.Add(PhoneFormat(txtAddLine.Text))
>txtAddLine.Text = ""
>setFocus(txtAddLine)
>End Sub
>Public Sub setFocus(ByVal ctrl As System.Web.UI.Control)
>Dim strS As String
>strS = "<SCRIPT language='javascript'>document.getElementById('" +
>ctrl.ID + "').focus();</SCRIPT>"
>RegisterStartupScript("focus", strS)
>End Sub
>This will not place the focus in the textbox. What am I missing?
>Again, PLEASE help. Thanks much!
Put a blank label at the bottom of the form and set its text property
in the codebehind instead of using the registerstartupscript.
-Adam
:o) You're all wrong. I took and made a clean application and it
worked, so I knew it wasn't the code there. I went back to my app,
(made a copy) and proceded to strip everything out until it worked.
Well, after everything was gone it still didn't work. There was only
one remaining thing, smartnavigaion = true.
That fixed the focus problem by turning it off, however it introduced a
whole new set of problems.
Having a database application, the users need to not use the back
button. I've got all the standard code for this but it's still not as
clean as smartnav.
Is there ANY way to overcome smartnav's focus problem?
MICROSOFT'
I didn't think so.
Anyhow, I've solved one problem only to intoduce many more. I may have
more ?'s soon, some really good ones I've been working on. Thanks for
the help so far.
Jeff
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Tuesday, March 13, 2012

Set property in Code-Behind from .aspx page

Hello there,

I have a number of aspx pages that are all the same but with different data in them. These pages are created by a content management system, and also retrieve some Database content based on a unique SQL statement.
Here are two .asp example pages so you can see what I am getting at:
http://www.cntraveller.co.uk/guides/England/
http://www.cntraveller.co.uk/guides/USA/

There is going to be one .dll file for all of these pages but I need to alter the SQL statment depending on which page you are viewing, for example for the Engand page it would be something like:
"SELECT * from Counties where Country = 'GB'" and the USA;
"SELECT * from Counties where Country = 'USA'".

My problem is I want to set somewhere in the .aspx page a variable that can be used in the SELECT statment. I have tried defining a function in the .aspx page like:


<script language="C#" runat="server">
void SetLBCountry()
{
this.strLBCountry = "GB";
}
</script>

and calling it from my .dll like this:


public strLBCountry;
private void Page_Load(object sender, System.EventArgs e)
{
SetLBCountry();
}

but it does not recognise the function when I compile it.

Anyone have any idea as to what I can do?

Thanks in advance,
Dave Asbury.You're going the wrong way, essentially you want the base class (codebehind) to call a sub only defined in a derived class (aspx page). It doesn't work that way. Why can't you just do this from the codebehind class?
Can you not simply parse the Request.Url to see what contry they are viewing from and then use some sort of select statement to get the relevant query string.. This could all be done in teh Page_Load method of the .dll
Thanks for your reply,

This is a good idea, but editors can create new folders and pages using the content management system and I don't want to have to edit the .dll to add in a new "If Request.Url = "blah blah" then strSQL = "SELECT BLAH" type statement.

I can see that there probably going to be other situations that require a similar solution too that I haven't come accross yet.

What I really would like is to be able to set a number of parameters in the .aspx page (this is the page that is created in the content management system from a template) that can be passed into the .dll - just like a form element or a querystring BUT that is set in the page the first time you view it (if you see what I mean!).

Any ideas??
Thanks for your reply,

I need to do it this way as I have my codebehind base class all set up and running fine, but I need all the different countries to use this one .dll but they all need different SQL statements.

The .aspx files are created by editorial staff using a content management system that uses a template and merges this with the data they put in to create the .aspx file.

What I want is for one of the fields they enter to be the key that is used to retreive further data from the database at run time - exactly as if I passed in a querystring or a form element - BUT I want this parameter to be in the page all the time so that when the page is viewed it is picked up and used inside the .dll file.

Do you see what I mean?
Still not sure if I get you fully, but could you an asp:textbox control to the page, you could set its text field to the value that you want and then set it Visiblity to false so that it doesn't show up on the page? you could then get the value of the textbox in the code behind page.
Yes!

That is exactly what I want, now you point it out I feel stupid for not seeing it.
Thanks for the help and sorry for taking up your time.

Dave.