Saturday, March 31, 2012
Server Side Code dependent on JavaScript
On a Button Click, I am using JavaScript to print to current page. When the print has been sent, I want to run a Server Side Function to update a record (which also changes the screen so I have to wait until it prints to run the server side function).
Thanks.I imagine in your JS function, you could print and then do a postback to the server?
This may get your problem resolved.
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Button1.Attributes.Add("onClick","javascript:DoSomething();");
string html = "";
html += "<script>";
html += " function DoSomething()";
html += " {";
html += " window.print();";
html += " }";
html += "</script>";
Response.Write(html);
}
private void Button1_Click(object sender, System.EventArgs e)
{
Update();
}
public void Update()
{
Response.Write("Now going to update the record.");
}
How to force a postback using javascript:
http://weblogs.asp.net/mnolton/archive/2003/06/04/8260.aspx
Server side function calling
Uses: VS.NET 2003, VB.NET, Windows xp
I've written an apsx web page through vb.net. In that I've mentioned a
procedure(Server Side). Now I want to call it through Jscript.
The reason behind is about validations. There are some text to enter in one
text box. So once the user has entered the text, it will check whether the
text is null, if not it will call that server side procedure I've mentioned
in aspx page.
I'm wondering how can I call it. One guy in the news group said to use the
following:
1. __doPostBack(...);
2. document.forms[0].submit();
3. document.getElementById(<Some asp control's client ID>).click();
however it wasn't specific and I didn't understod how to use it. Using codes
to illustrate the solution will be much worthy here.
Thank you,
--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.Hifni Shahzard wrote:
> Hi,
> Uses: VS.NET 2003, VB.NET, Windows xp
> I've written an apsx web page through vb.net. In that I've mentioned a
> procedure(Server Side). Now I want to call it through Jscript.
> The reason behind is about validations. There are some text to enter
> in one text box. So once the user has entered the text, it will check
> whether the text is null, if not it will call that server side
> procedure I've mentioned in aspx page.
> I'm wondering how can I call it. One guy in the news group said to
> use the following:
> 1. __doPostBack(...);
> 2. document.forms[0].submit();
> 3. document.getElementById(<Some asp control's client ID>).click();
> however it wasn't specific and I didn't understod how to use it.
> Using codes to illustrate the solution will be much worthy here.
> Thank you,
If you want validation, use a CustomValidator. You could provide some
client-side javascript, but that's not required. You are after the server-side
event. There you can do your validation.
Hans Kesting
You can use the AJAX.NET libraries to asynchronously do a server side method
call easily through javascript.
Go here http://ajax.schwarz-interactive.de/...le/default.aspx for
examples and downloadable libraries and code.
--
- Paul Glavich
MVP ASP.NET
http://weblogs.asp.net/pglavich
ASPInsiders member - http://www.aspinsiders.com
"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:%23VZF4l%23zFHA.1968@.TK2MSFTNGP10.phx.gbl...
> Hifni Shahzard wrote:
>> Hi,
>> Uses: VS.NET 2003, VB.NET, Windows xp
>>
>> I've written an apsx web page through vb.net. In that I've mentioned a
>> procedure(Server Side). Now I want to call it through Jscript.
>>
>> The reason behind is about validations. There are some text to enter
>> in one text box. So once the user has entered the text, it will check
>> whether the text is null, if not it will call that server side
>> procedure I've mentioned in aspx page.
>>
>> I'm wondering how can I call it. One guy in the news group said to
>> use the following:
>>
>> 1. __doPostBack(...);
>> 2. document.forms[0].submit();
>> 3. document.getElementById(<Some asp control's client ID>).click();
>>
>> however it wasn't specific and I didn't understod how to use it.
>> Using codes to illustrate the solution will be much worthy here.
>>
>> Thank you,
> If you want validation, use a CustomValidator. You could provide some
> client-side javascript, but that's not required. You are after the
> server-side
> event. There you can do your validation.
> Hans Kesting
Server side function calling
Uses: VS.NET 2003, VB.NET, Windows xp
I've written an apsx web page through vb.net. In that I've mentioned a
procedure(Server Side). Now I want to call it through Jscript.
The reason behind is about validations. There are some text to enter in one
text box. So once the user has entered the text, it will check whether the
text is null, if not it will call that server side procedure I've mentioned
in aspx page.
I'm wondering how can I call it. One guy in the news group said to use the
following:
1. __doPostBack(...);
2. document.forms[0].submit();
3. document.getElementById(<Some asp control's client ID> ).click();
however it wasn't specific and I didn't understod how to use it. Using codes
to illustrate the solution will be much worthy here.
Thank you,
--
Mohammed Hifni Shahzard Nazeer,
JB Securities Pvt. Ltd.,
Colombo.Hifni Shahzard wrote:
> Hi,
> Uses: VS.NET 2003, VB.NET, Windows xp
> I've written an apsx web page through vb.net. In that I've mentioned a
> procedure(Server Side). Now I want to call it through Jscript.
> The reason behind is about validations. There are some text to enter
> in one text box. So once the user has entered the text, it will check
> whether the text is null, if not it will call that server side
> procedure I've mentioned in aspx page.
> I'm wondering how can I call it. One guy in the news group said to
> use the following:
> 1. __doPostBack(...);
> 2. document.forms[0].submit();
> 3. document.getElementById(<Some asp control's client ID> ).click();
> however it wasn't specific and I didn't understod how to use it.
> Using codes to illustrate the solution will be much worthy here.
> Thank you,
If you want validation, use a CustomValidator. You could provide some
client-side javascript, but that's not required. You are after the server-si
de
event. There you can do your validation.
Hans Kesting
You can use the AJAX.NET libraries to asynchronously do a server side method
call easily through javascript.
Go here http://ajax.schwarz-interactive.de/...le/default.aspx for
examples and downloadable libraries and code.
- Paul Glavich
MVP ASP.NET
http://weblogs.asp.net/pglavich
ASPInsiders member - http://www.aspinsiders.com
"Hans Kesting" <news.2.hansdk@.spamgourmet.com> wrote in message
news:%23VZF4l%23zFHA.1968@.TK2MSFTNGP10.phx.gbl...
> Hifni Shahzard wrote:
> If you want validation, use a CustomValidator. You could provide some
> client-side javascript, but that's not required. You are after the
> server-side
> event. There you can do your validation.
> Hans Kesting
>
Thursday, March 29, 2012
server side kepress event on textbox
I have a webform and I am wanting to call a function from a textbox control
located on the webform when a key is pressed. Can this be done in server sid
e.
already know do like this
on ASPX page within javascript tags
<script laguage=javascript>
function trapKeypress() {
alert (window.event.keyCode);
}
</script>
and in .vb page of the .aspx page ..'
textbox1.attributes.item("onkeypress") = "javascript:trapKeypress();"
Can I do it without using JavaScript .
RegardsYou can submit the form in trapKeypress(). This will cause a postback and
you can pass to the server a sort of info telling what exactly caused the
postback. This will resemble a server event. You can't avoid using
javascript on the client side. How can server know what is happening in the
browser?
Eliyahu
"Raed Sawalha" <RaedSawalha@.discussions.microsoft.com> wrote in message
news:1D18DAD2-5F54-4F85-8E27-8F63BB1F3B7E@.microsoft.com...
> HI There,
> I have a webform and I am wanting to call a function from a textbox
control
> located on the webform when a key is pressed. Can this be done in server
side.
> already know do like this
> on ASPX page within javascript tags
> <script laguage=javascript>
> function trapKeypress() {
> alert (window.event.keyCode);
> }
> </script>
> and in .vb page of the .aspx page ..'
> textbox1.attributes.item("onkeypress") = "java script:trapKeypress();"
> Can I do it without using JavaScript .
> Regards
server side kepress event on textbox
I have a webform and I am wanting to call a function from a textbox control
located on the webform when a key is pressed. Can this be done in server side.
already know do like this
on ASPX page within javascript tags
<script laguage=javascript>
function trapKeypress() {
alert (window.event.keyCode);
}
</script
and in .vb page of the .aspx page ..'
textbox1.attributes.item("onkeypress") = "javascript:trapKeypress();"
Can I do it without using JavaScript .
RegardsYou can submit the form in trapKeypress(). This will cause a postback and
you can pass to the server a sort of info telling what exactly caused the
postback. This will resemble a server event. You can't avoid using
javascript on the client side. How can server know what is happening in the
browser?
Eliyahu
"Raed Sawalha" <RaedSawalha@.discussions.microsoft.com> wrote in message
news:1D18DAD2-5F54-4F85-8E27-8F63BB1F3B7E@.microsoft.com...
> HI There,
> I have a webform and I am wanting to call a function from a textbox
control
> located on the webform when a key is pressed. Can this be done in server
side.
> already know do like this
> on ASPX page within javascript tags
> <script laguage=javascript>
> function trapKeypress() {
> alert (window.event.keyCode);
> }
> </script>
> and in .vb page of the .aspx page ..'
> textbox1.attributes.item("onkeypress") = "javascript:trapKeypress();"
> Can I do it without using JavaScript .
> Regards
Thursday, March 22, 2012
server.execute vs response.redirect
I'm just starting to shift to asp.net so forgive my question in case what i'm asking for is a obsolete function.
Using classic ASP, all of my form submission and links points to only one file which is like a index.asp, passing a hidden value indicating the type of processing it needed. From this index file, I check the hidden value passed then transfer the control to the appropriate "process" page, for this transfer of control I used "server.execute". Now using ASP wherein the form processing is embeded in the same page as the submitting form, is it still ok to use server.execute to transfer to another page after processing the page submitted? or should I use "response.redirect" instead? Or is there a better way to do this page redirection?
Thanks in advance.
Regards,
Well, in asp.net pages postback to themselves, so once you submit a form, its posting to itself.
You have different options:
1- Response.Redirect(); -- redirect you to another page
2- Server.Execute(); -- will execute a another page get the contents of it, but you will stay in the same page
3- Server.Transfer(); -- will transfer you to another page keeping the url of the first page in the address bar
Hope that helps.
regards
Tuesday, March 13, 2012
Server.MapPath
-SteveWhen your code is run in design mode (VS.NET or WebMatrix), Server.MapPath doesn't provide a useful path. There is no alternative method built into ASP.NET to solve this in design mode. If you are looking for a solution in design mode, ask and I can provide a third party solution.
Server.MapPath in Global.asax
in an application variable the path of my database. Global.asax is in the
root directory of my web folder and database is in database/database.mdb.
Now, if I start my web site from default.aspx in the root folder all is ok,
but if start it with a page in a nested folder Global.asax can't find the
folder because Server.MapPath use the relative path of nested folder as base
for its search.
What can I do?
Many thanks
SebastianoUse an absolute path for the Server.MapPath argument such as
~/database/database.mdb instead of just database/database.mdb
Patrice
"Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
>
try to use Request.PhysicalApplicationPath to combine path
Thanks.
Lostinet (MS ASP.NET MVP)
lostinetweb@.hotmail.com
--
Need MessageBox,ComboBox,DatePicker,PasswordB
ox,TreeView,ASP.Net RPC ?
http://www.lostinet.com/
"Sebastiano" <info@.sebastianogazzola.it> д?
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
>
Thank you so much, I can't understand why MS did not mention the importance
of the "~" symbol in the path request. I have waisted hours trying to look
for documentation.
- Rashad
"Patrice" <nobody@.nowhere.com> wrote in message
news:upo4Do6IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> Use an absolute path for the Server.MapPath argument such as
> ~/database/database.mdb instead of just database/database.mdb
> Patrice
> "Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
> news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> save
the
database/database.mdb.
> ok,
the
> base
>
Server.MapPath in Global.asax
in an application variable the path of my database. Global.asax is in the
root directory of my web folder and database is in database/database.mdb.
Now, if I start my web site from default.aspx in the root folder all is ok,
but if start it with a page in a nested folder Global.asax can't find the
folder because Server.MapPath use the relative path of nested folder as base
for its search.
What can I do?
Many thanks
SebastianoUse an absolute path for the Server.MapPath argument such as
~/database/database.mdb instead of just database/database.mdb
Patrice
"Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
try to use Request.PhysicalApplicationPath to combine path
--
Thanks.
Lostinet (MS ASP.NET MVP)
lostinetweb@.hotmail.com
--------
Need MessageBox,ComboBox,DatePicker,PasswordBox,TreeVie w,ASP.Net RPC ?
http://www.lostinet.com/
"Sebastiano" <info@.sebastianogazzola.it> д?
news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> I want to use Server.MapPath function in Global.asax because I want to
save
> in an application variable the path of my database. Global.asax is in the
> root directory of my web folder and database is in database/database.mdb.
> Now, if I start my web site from default.aspx in the root folder all is
ok,
> but if start it with a page in a nested folder Global.asax can't find the
> folder because Server.MapPath use the relative path of nested folder as
base
> for its search.
> What can I do?
> Many thanks
> Sebastiano
Thank you so much, I can't understand why MS did not mention the importance
of the "~" symbol in the path request. I have waisted hours trying to look
for documentation.
- Rashad
"Patrice" <nobody@.nowhere.com> wrote in message
news:upo4Do6IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> Use an absolute path for the Server.MapPath argument such as
> ~/database/database.mdb instead of just database/database.mdb
> Patrice
> "Sebastiano" <info@.sebastianogazzola.it> a crit dans le message de
> news:OtVprw4IEHA.3964@.TK2MSFTNGP10.phx.gbl...
> > I want to use Server.MapPath function in Global.asax because I want to
> save
> > in an application variable the path of my database. Global.asax is in
the
> > root directory of my web folder and database is in
database/database.mdb.
> > Now, if I start my web site from default.aspx in the root folder all is
> ok,
> > but if start it with a page in a nested folder Global.asax can't find
the
> > folder because Server.MapPath use the relative path of nested folder as
> base
> > for its search.
> > What can I do?
> > Many thanks
> > Sebastiano