Showing posts with label load. Show all posts
Showing posts with label load. Show all posts

Saturday, March 31, 2012

Set browser in PrinPreview state on page load

Hi, Can i set the clients browser programmatically to PrintPreview state (File->Print Preview) when the client clicks the button print?

I don't want to use Crystal nor Report Viewer for some reasons

regards

Thanks in advance! More Power!

Hi,

As far as I know, it's impossible because you have to manipulate IE from client. If so, that means you have access to control windows process, then that's very dangerous. What's more, in fact, there are little APIs for us to control IE's function, especially such thing.

HTH


Hey Dfox,

Unfortunately asp.net works server side, so you can't change client side behaviour.

Keep up the good programming!

Monday, March 26, 2012

set focus

How can I set focus to a txtbox in the page load handler?Yes it is possible , in several ways, but the most effective is:

<FORM NAME="myFormName">
<INPUT ITEM="text" NAME="myTextField">
</FORM>
<SCRIPT LANGUAGE=JAVASCRIPT><!--
document.myFormName.myTextField.focus();
//--></SCRIPT>

It's client side script...
what if it's a web control instead of a HTML control?
Sorry, send you the wrong code!
This will work, except on self-made usercontrols...

just add a 'imports system.text' line before your class dec.

add this to your startup:

Dim strBuilder As StringBuilder = New StringBuilder()

strBuilder.Append("<script language='javascript'>")
strBuilder.Append("function setFocus() {")
strBuilder.Append("document.getElementById('TextBox3').focus();}")
strBuilder.Append(" window.onload=setFocus;")
strBuilder.Append("</script>")
RegisterClientScriptBlock("Focus", strBuilder.ToString)

Good luck!

Tim.
thanks..

Set Focus

When i load a form and the user selects an item from a dropdown list i want to set focus to another control. In standard vb and standard vb.net i can do this. Anyone know how to do this asp.net?... any help would be greatly appreciated

Thank youYou need to add some clientside JavaScript code in the form of an onchange event handler.
OTTOMH, something like:

DDL.attributes.add("onchange","document.getElementById('controlId').focus()")

Saturday, March 24, 2012

Set focus and cursor at end of text?

I use this code to set focus to a textbox when I load a page:

private void SetFocus(System.Web.UI.Control ctrl)
{
string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
ctrl.ID + "').focus()</SCRIPT>";

RegisterStartupScript("focus", s);
}

I would also like the cursor to be positioned at the end of the text field.
Using only the above code, the cursor is positioned at the beginning of the
textbox even if there are some text present in the field.

How can I position the cusrsor at the end of the text?

OlavOlav,

Here we go:

Create a new function in your <head> tag in the HTML section:

function SetEnd (TB)
{
if (TB.createTextRange)
{
var FieldRange = TB.createTextRange();
FieldRange.moveStart('character', TB.value.length);
FieldRange.collapse();
FieldRange.select();
}
}

Create a new onfocus JavaScript event in your asp text box tag (asp:textBox)
that calls the SetEnd function above:

<asp:textbox id="TextBox1" runat="server" Width="65px"
onfocus="SetEnd(this)">Existing text</asp:textbox
Make sure you keep your existing code that calls the SetFocus function as it
is:

private void SetFocus(System.Web.UI.Control ctrl)
{
string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
ctrl.ID + "').focus()</SCRIPT>";

RegisterStartupScript("focus", s);
}

Don't forget to call the above SetFocus() function in your Body tag on page
load ....( <body onload="SetFocus()"> )

Good luck!

Regards,

Mohammad Samara.

ICS (London) Ltd.

"Olav Tollefsen" <x@.y.com> wrote in message
news:uxrxLYt3DHA.3656@.TK2MSFTNGP11.phx.gbl...
> I use this code to set focus to a textbox when I load a page:
> private void SetFocus(System.Web.UI.Control ctrl)
> {
> string s = "<SCRIPT language=\"javascript\">document.getElementById('" +
> ctrl.ID + "').focus()</SCRIPT>";
> RegisterStartupScript("focus", s);
> }
> I would also like the cursor to be positioned at the end of the text
field.
> Using only the above code, the cursor is positioned at the beginning of
the
> textbox even if there are some text present in the field.
> How can I position the cusrsor at the end of the text?
> Olav

Set focus on page load

Hello,

This is probably super simple but I can't figure out how to set the initial focus on an aspx page. I have a text box control that I would like to be the default focus on page load, how do I do this?

Thanks for any help

-SI think this might be the simple way but only good for IE:


<asp:TextBox id=TextBox1 runat="server"></asp:TextBox>
<SCRIPT>window.document.all["TextBox1"].focus()</SCRIPT>

Please see below thread, it has related info on it

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=314815

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.

I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.

Eliyahu

"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegro ups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
you can write a function something like this and use it when u need them.

protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);

Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net

"Any one who has never made a mistake has never tried anything new" - Einstein

"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-

Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"

' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub

Hope this helps
Patrick

*** Sent via Developersdex http://www.developersdex.com ***

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page loads, I need the focus to be on one of the textboxes called txtUserName.

I come from a VB background, so expecting the obvious, I go to the Page_Load event of the index.aspx page and try to write txtUserName.SetFocus but I see there isn't a SetFocus method for the System.Web.UI.WebControls.TextBox class.

What's the way to set the focus to a textbox on the page load in ASP.NET?take a look at this thread:

http://www.vbforums.com/showthread.php?t=316582&highlight=textbox+focus
Hi , You may use a java script

<SCRIPT LANGUAGE="JavaScript">
function setFocus()
{
document.Form1('TxtCno').focus()
}
</SCRIPT>

and call it in

<body MS_POSITIONING="GridLayout" bgColor="#003366" onload="setFocus();">


thats it it will focus the cursor on your desired field

Set focus to a textbox on page load

I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
loads, I need the focus to be on one of the textboxes called
txtUserName.
I come from a VB background, so expecting the obvious, I go to the
Page_Load event of the index.aspx page and try to write
txtUserName.SetFocus but I see there isn't a SetFocus method for the
System.Web.UI.WebControls.TextBox class.
What's the way to set the focus to a textbox on the page load in
ASP.NET?It's a client-side task. You need to call javascript focus() method on the
element you want to set focus on.
Eliyahu
"Water Cooler v2" <wtr_clr@.yahoo.com> wrote in message
news:1124274011.476683.55980@.o13g2000cwo.googlegroups.com...
> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
you can write a function something like this and use it when u need them.
protected void SetFocus(Control controlToFocus){
string formName = GetFormName(controlToFocus);
string jsString="<script language=javascript>document." + formName +
".elements['" + controlToFocus.UniqueID + "'].focus();</script>";
if(Page.IsStartupScriptRegistered("SetFocusToSearch")==false)
Page.RegisterStartupScript("SetFocusToSearch",jsString);
Hope this helps.
--
Kannan.V
Home : http://www.kannanv.com
Blog : http://kannanv.blogspot.com
Web : http://www.DotnetLounge.net
"Any one who has never made a mistake has never tried anything new" - Einste
in
"Water Cooler v2" wrote:

> I am new to ASP/ASP.NET so kindly be gentle. When my index.aspx page
> loads, I need the focus to be on one of the textboxes called
> txtUserName.
> I come from a VB background, so expecting the obvious, I go to the
> Page_Load event of the index.aspx page and try to write
> txtUserName.SetFocus but I see there isn't a SetFocus method for the
> System.Web.UI.WebControls.TextBox class.
> What's the way to set the focus to a textbox on the page load in
> ASP.NET?
>
As the last post adviced this should do the trick:-
Private Sub SetFocus(ByVal ctrl As Control)
' Define the JavaScript function for the specified control.
Dim focusScript As String = "<script language='javascript'>" & _
"document.getElementById('" + ctrl.ClientID & _
"').focus();</script>"
' Add the JavaScript code to the page.
Page.RegisterStartupScript("FocusScript", focusScript)
End Sub
Hope this helps
Patrick
*** Sent via Developersdex http://www.examnotes.net ***

Thursday, March 22, 2012

Set Image Control to Bitmap

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image they
can not see the full size. If I can create a bitmap from the stream I know
the size so I can set the properties of a image control and then display the
bitmap in the image. Does this make since or am I going about this the
wrong way? So in a nutshell, I am pulling images from a DB and want to
display the full size without having to actuall save the image to a file.
Any pointers?
TIAYou can make an mypage.aspx page that returns bitmap (not HTML)
1. You need to set ContentType = "img/gif"; or (jpg)
2. You need to set ContentLength to the size of the image
3. Use Response.BinaryWrite to output the image. Or since Response is a
Stream you can do Bitmap.Save(Response);
in your HTML you write <img src="http://pics.10026.com/?src=mypage.aspx">
PS: It's more efficient to use handler for that task. mypage.ashx. But aspx
will work too if you fill more comfortable with aspx.
George.
"MikeB" <m@.nospam.com> wrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...
> Hello All, want to be able to pull images from the database and load them
> into a bitmap through a stream which I have working. I then want to take
> the bitmap and load it into a Image control without haveing to save the
> bitmap as a file. Is this possible? Currently, I just display the bitmap
> by calling Bitmap.save however, if users do not know to click the image
> they can not see the full size. If I can create a bitmap from the stream
> I know the size so I can set the properties of a image control and then
> display the bitmap in the image. Does this make since or am I going about
> this the wrong way? So in a nutshell, I am pulling images from a DB and
> want to display the full size without having to actuall save the image to
> a file. Any pointers?
> TIA
>
Here is a way to do this without relying on an external handler such as
another page:
http://www.eggheadcafe.com/articles/20050911.asp
-Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"MikeB" wrote:

> Hello All, want to be able to pull images from the database and load them
> into a bitmap through a stream which I have working. I then want to take
> the bitmap and load it into a Image control without haveing to save the
> bitmap as a file. Is this possible? Currently, I just display the bitmap
> by calling Bitmap.save however, if users do not know to click the image th
ey
> can not see the full size. If I can create a bitmap from the stream I kno
w
> the size so I can set the properties of a image control and then display t
he
> bitmap in the image. Does this make since or am I going about this the
> wrong way? So in a nutshell, I am pulling images from a DB and want to
> display the full size without having to actuall save the image to a file.
> Any pointers?
> TIA
>
>
Your page can have an Image control on it, and that Image control can point
to another page (or handler) that retrieves the image.
Here are the details:
http://SteveOrr.net/articles/ImproveYourImages.aspx
http://dotnetslackers.com/articles/...FileDenial.aspx
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"MikeB" <m@.nospam.com> wrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...
> Hello All, want to be able to pull images from the database and load them
> into a bitmap through a stream which I have working. I then want to take
> the bitmap and load it into a Image control without haveing to save the
> bitmap as a file. Is this possible? Currently, I just display the bitmap
> by calling Bitmap.save however, if users do not know to click the image
> they can not see the full size. If I can create a bitmap from the stream
> I know the size so I can set the properties of a image control and then
> display the bitmap in the image. Does this make since or am I going about
> this the wrong way? So in a nutshell, I am pulling images from a DB and
> want to display the full size without having to actuall save the image to
> a file. Any pointers?
> TIA
>
Thanks everyone for the replies.
"MikeB" <m@.nospam.com> wrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...
> Hello All, want to be able to pull images from the database and load them
> into a bitmap through a stream which I have working. I then want to take
> the bitmap and load it into a Image control without haveing to save the
> bitmap as a file. Is this possible? Currently, I just display the bitmap
> by calling Bitmap.save however, if users do not know to click the image
> they can not see the full size. If I can create a bitmap from the stream
> I know the size so I can set the properties of a image control and then
> display the bitmap in the image. Does this make since or am I going about
> this the wrong way? So in a nutshell, I am pulling images from a DB and
> want to display the full size without having to actuall save the image to
> a file. Any pointers?
> TIA
>

Set Image Control to Bitmap

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image they
can not see the full size. If I can create a bitmap from the stream I know
the size so I can set the properties of a image control and then display the
bitmap in the image. Does this make since or am I going about this the
wrong way? So in a nutshell, I am pulling images from a DB and want to
display the full size without having to actuall save the image to a file.
Any pointers?

TIAYou can make an mypage.aspx page that returns bitmap (not HTML)
1. You need to set ContentType = "img/gif"; or (jpg)
2. You need to set ContentLength to the size of the image
3. Use Response.BinaryWrite to output the image. Or since Response is a
Stream you can do Bitmap.Save(Response);

in your HTML you write <img src="http://pics.10026.com/?src=mypage.aspx">

PS: It's more efficient to use handler for that task. mypage.ashx. But aspx
will work too if you fill more comfortable with aspx.

George.

"MikeB" <m@.nospam.comwrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image
they can not see the full size. If I can create a bitmap from the stream
I know the size so I can set the properties of a image control and then
display the bitmap in the image. Does this make since or am I going about
this the wrong way? So in a nutshell, I am pulling images from a DB and
want to display the full size without having to actuall save the image to
a file. Any pointers?
>
TIA
>


Here is a way to do this without relying on an external handler such as
another page:

http://www.eggheadcafe.com/articles/20050911.asp
-Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com
"MikeB" wrote:

Quote:

Originally Posted by

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image they
can not see the full size. If I can create a bitmap from the stream I know
the size so I can set the properties of a image control and then display the
bitmap in the image. Does this make since or am I going about this the
wrong way? So in a nutshell, I am pulling images from a DB and want to
display the full size without having to actuall save the image to a file.
Any pointers?
>
TIA
>
>
>


Your page can have an Image control on it, and that Image control can point
to another page (or handler) that retrieves the image.
Here are the details:
http://SteveOrr.net/articles/ImproveYourImages.aspx
http://dotnetslackers.com/articles/...FileDenial.aspx
--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
"MikeB" <m@.nospam.comwrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image
they can not see the full size. If I can create a bitmap from the stream
I know the size so I can set the properties of a image control and then
display the bitmap in the image. Does this make since or am I going about
this the wrong way? So in a nutshell, I am pulling images from a DB and
want to display the full size without having to actuall save the image to
a file. Any pointers?
>
TIA
>


Thanks everyone for the replies.

"MikeB" <m@.nospam.comwrote in message
news:usruSre3HHA.1164@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hello All, want to be able to pull images from the database and load them
into a bitmap through a stream which I have working. I then want to take
the bitmap and load it into a Image control without haveing to save the
bitmap as a file. Is this possible? Currently, I just display the bitmap
by calling Bitmap.save however, if users do not know to click the image
they can not see the full size. If I can create a bitmap from the stream
I know the size so I can set the properties of a image control and then
display the bitmap in the image. Does this make since or am I going about
this the wrong way? So in a nutshell, I am pulling images from a DB and
want to display the full size without having to actuall save the image to
a file. Any pointers?
>
TIA
>

Set MaxLength on form Load

Hi,

Does anyone know how to populate the maxlength property of an asp:textbox on page load?

I'm getting the value from the my config table in my DB

When I try setting myControl.MaxLength=10 in the onload event
It's not written to the control and when I enter text I'm not restricted at all

I've also tried

<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=SummaryLimit%>"></asp:textbox>

' And

<asp:textbox id="Abstract" Runat="server" Wrap="True" Rows="11" Columns="45" TextMode="MultiLine" maxlength="<%=Convert.ToInt32(SummaryLimit)%>"></asp:textbox>
Geting error - <%=SummaryLimit%> is not a valid value for Int32.
And
<%=Convert.ToInt32(SummaryLimit)%> is not a valid value for Int32.

SummaryLimit Value is declared and assigned as an Int32
Dim m_iSummaryLimit As Int32 = 250

Public Property SummaryLimit() As Int32
Get
Return Convert.ToInt32(m_iSummaryLimit)
End Get
Set(ByVal Value As Int32)
m_iSummaryLimit = Convert.ToInt32(Value)
End Set
End PropertyThe textbox control when in multiline mode actually renders as a HTML textarea therefore on a textarea there is no maxlength property so maxlength does not work. One of the ways to control this is to use javascript instead.
Basilisk,

Thanks for that, just wasted the whole morning trying to get it working.

Cheers Al
I did want to pipe in and say that when you use the following:

<%= ... %>

in an item tag, you need to surround it with single quotes - ' - and not double quotes - " -.
Lord Rat,

Thanks, feel free to pop out of your cave with useful tips like that at anytime :D

Cheers Al