Showing posts with label submit. Show all posts
Showing posts with label submit. Show all posts

Saturday, March 24, 2012

set focus on the control

Can I set a specific control on focus? My case is after I click a "Submit" button, I want to set the cursor on a textbox .

Million thanksCheck out this code snippet,
http://www.extremeexperts.com/Net/C...erPostback.aspx

--
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com

"Grey" <ericyum@.i-cable.com> wrote in message news:equliHu5DHA.1504@.TK2MSFTNGP12.phx.gbl...
Can I set a specific control on focus? My case is after I click a "Submit" button, I want to set the cursor on a textbox .

Million thanks
This is the code i use. it takes a control and sets the focus.
public static void SetInitialFocus(System.Web.UI.Control control)

{

if (control.Page == null)

{

throw new ArgumentException(

"The Control must be added to a Page before you can set the IntialFocus to it.");

}

if (control.Page.Request.Browser.JavaScript == true)

{

// Create JavaScript

System.Text.StringBuilder s = new System.Text.StringBuilder();

s.Append("\n<SCRIPT LANGUAGE='JavaScript'>\n");

s.Append("<!--\n");

s.Append("function SetInitialFocus()\n");

s.Append("{\n");

s.Append(" document.");

// Find the Form

System.Web.UI.Control p = control.Parent;

while (!(p is System.Web.UI.HtmlControls.HtmlForm))

p = p.Parent;

s.Append(p.ClientID);

s.Append("['");

s.Append(control.UniqueID);

// Set Focus on the selected item of a RadioButtonList

System.Web.UI.WebControls.TextBox rbl = control as System.Web.UI.WebControls.TextBox;

s.Append("'].focus();\n");

s.Append("}\n");

if (control.Page.SmartNavigation)

s.Append("window.setTimeout(SetInitialFocus, 500);\n");

else

s.Append("window.onload = SetInitialFocus;\n");

s.Append("// -->\n");

s.Append("</SCRIPT>");

// Register Client Script

control.Page.RegisterClientScriptBlock("InitialFocus", s.ToString());

}

}

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Grey" <ericyum@.i-cable.com> wrote in message news:equliHu5DHA.1504@.TK2MSFTNGP12.phx.gbl...
Can I set a specific control on focus? My case is after I click a "Submit" button, I want to set the cursor on a textbox .

Million thanks
In code-behind file, register JavaScript code to handle client onclick method of submit button:

e.g. btnSubmit.Attributes.Add("onclick", "OnSubmitTest");

in .aspx file, add following JavaScript method:

function OnSubmitTest()
{
if (null != document.all("txtTextbox"))
document.all("txtTextbox").focus();
}

Tiendq,
tien@.tienonsoftware.com
"Grey" <ericyum@.i-cable.com> wrote in message news:equliHu5DHA.1504@.TK2MSFTNGP12.phx.gbl...
Can I set a specific control on focus? My case is after I click a "Submit" button, I want to set the cursor on a textbox .

Million thanks

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!

Thursday, March 22, 2012

Set hidden values and then submit automatically

>From my page shopping cart page I want to send the amount value to the
following payment page:

<script type="text/javascript">
window.onload = function (evt) { document.forms[0].submit(); }
</script>

</head>

<body>
<form name="payform" method="post"
action="https://mmm.com/payment/start.pml">
<input type="hidden" id="amount" name="amount" value=""
runat="server" />
<input type="hidden" name="merchant" value="752" />
</form>

The amount value should be set in the hidden input and then the form
should be submitted autmatically to the payment company. I have
problems capturing and setting the amount value.

I've tried with:

Sub Page_load()
amount.Value = 1212
End Sub

But I receive an error message from the payment company telling me that
amount is missing.

Can someone help me think clear?

Regards,

SDid you check if the value is getting set in the hidden variable before
calling forms[0].submit function?

Regards,
Augustin
http://augustinprasanna.blogspot.com
"staeri@.gmail.com" wrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

From my page shopping cart page I want to send the amount value to the


following payment page:
>
<script type="text/javascript">
window.onload = function (evt) { document.forms[0].submit(); }
</script>
>
</head>
>
<body>
<form name="payform" method="post"
action="https://mmm.com/payment/start.pml">
<input type="hidden" id="amount" name="amount" value=""
runat="server" />
<input type="hidden" name="merchant" value="752" />
</form>
>
The amount value should be set in the hidden input and then the form
should be submitted autmatically to the payment company. I have
problems capturing and setting the amount value.
>
I've tried with:
>
Sub Page_load()
amount.Value = 1212
End Sub
>
But I receive an error message from the payment company telling me that
amount is missing.
>
Can someone help me think clear?
>
Regards,
>
S
>
>



"staeri@.gmail.com" wrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

From my page shopping cart page I want to send the amount value to the


following payment page:
>
<script type="text/javascript">
window.onload = function (evt) { document.forms[0].submit(); }
</script>
>
</head>
>
<body>
<form name="payform" method="post"
action="https://mmm.com/payment/start.pml">
<input type="hidden" id="amount" name="amount" value=""
runat="server" />
<input type="hidden" name="merchant" value="752" />
</form>
>
The amount value should be set in the hidden input and then the form
should be submitted autmatically to the payment company. I have
problems capturing and setting the amount value.
>
I've tried with:
>
Sub Page_load()
amount.Value = 1212
End Sub
>
But I receive an error message from the payment company telling me that
amount is missing.
>
Can someone help me think clear?


If you want to set it using page_load, could you not edit your HTML source
and use:

<input type="hidden" id="amount" name="amount" value="<%=intAmount%>"
runat="server" />

and declare and set intAmount somewhere else?