Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Saturday, March 24, 2012

This works on my locahost, but not on a remote server?

Hello. This problem is perplexing me.

I have a asp:button which runs a javascript function when it is clicked. It
returns a true or false depending if a postback is needed. This works great
when I run it on my development pc. But, when I run it from another
computer, it ALWAYS does a postback, even if it returns false. I have no
ideas why??

The plot thickens... I don't know if this really matters or not, but this
button is in a datagrid.

Can anyone explain to me why the javascript function posts back??? The
code is posted below.

Thank you in advance!

SteveS

******ASPX CODE************

<asp:Datagirid.....>
..
<asp:TemplateColumn HeaderText="Deny" ItemStyle-HorizontalAlign=Center
HeaderStyle-HorizontalAlign=Center>
<ItemTemplate>
<asp:Button text="Deny" ID="btnDeny" Runat="server"
CommandName="btnDeny"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
..
</asp:Datagrid
<script lang=javascript>
function OpenDenyWindow(changeId, btn) {
var ret = false
retVal=window.showModalDialog('DenialEmailForm.asp x?id=' +
changeId+'&mem='+document.Form1.hdnMemId.value,'', '');
alert ("retval = " + retVal)
if (retVal == "Successful") {
//return true
ret = true
}
else {
//return false
ret = false
}
alert(ret);
// *** even if this function returns a FALSE, the form is still posted
when I am not running the web page from my local host.
return ret;
}

**** CODE BEHIND****

Private Sub grdList_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdList.ItemCreated
'ADD THE JAVASCRIPT TO TO THE BUTTON
Dim ctrlDeny As Button = CType(e.Item.FindControl("btnDeny"),
Button)
If Not IsNothing(ctrlDeny) Then
Dim grid As DataGrid = CType(sender, DataGrid)
ctrlDeny.Attributes.Add("onclick", "return OpenDenyWindow("
& grid.DataKeys(e.Item.ItemIndex).ToString & ", this); return false;")
End If
End SubWhat is the configuration of the browser on the other PC? Maybe it has
disabled javascript?

"SteveS" <ssinger@.trendmls.com> wrote in message
news:uZ4IRSWIEHA.2128@.TK2MSFTNGP11.phx.gbl...
> Hello. This problem is perplexing me.
> I have a asp:button which runs a javascript function when it is clicked.
It
> returns a true or false depending if a postback is needed. This works
great
> when I run it on my development pc. But, when I run it from another
> computer, it ALWAYS does a postback, even if it returns false. I have no
> ideas why??
> The plot thickens... I don't know if this really matters or not, but this
> button is in a datagrid.
> Can anyone explain to me why the javascript function posts back??? The
> code is posted below.
> Thank you in advance!
> SteveS
>
> ******ASPX CODE************
> <asp:Datagirid.....>
> .
> <asp:TemplateColumn HeaderText="Deny" ItemStyle-HorizontalAlign=Center
> HeaderStyle-HorizontalAlign=Center>
> <ItemTemplate>
> <asp:Button text="Deny" ID="btnDeny" Runat="server"
> CommandName="btnDeny"></asp:Button>
> </ItemTemplate>
> </asp:TemplateColumn>
> .
> </asp:Datagrid>
> <script lang=javascript>
> function OpenDenyWindow(changeId, btn) {
> var ret = false
> retVal=window.showModalDialog('DenialEmailForm.asp x?id=' +
> changeId+'&mem='+document.Form1.hdnMemId.value,'', '');
> alert ("retval = " + retVal)
> if (retVal == "Successful") {
> //return true
> ret = true
> }
> else {
> //return false
> ret = false
> }
> alert(ret);
> // *** even if this function returns a FALSE, the form is still
posted
> when I am not running the web page from my local host.
> return ret;
> }
>
> **** CODE BEHIND****
> Private Sub grdList_ItemCreated(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdList.ItemCreated
> 'ADD THE JAVASCRIPT TO TO THE BUTTON
> Dim ctrlDeny As Button = CType(e.Item.FindControl("btnDeny"),
> Button)
> If Not IsNothing(ctrlDeny) Then
> Dim grid As DataGrid = CType(sender, DataGrid)
> ctrlDeny.Attributes.Add("onclick", "return
OpenDenyWindow("
> & grid.DataKeys(e.Item.ItemIndex).ToString & ", this); return false;")
> End If
> End Sub
>
>
>

This works on my locahost, but not on a remote server?

Hello. This problem is perplexing me.
I have a asp:button which runs a javascript function when it is clicked. It
returns a true or false depending if a postback is needed. This works great
when I run it on my development pc. But, when I run it from another
computer, it ALWAYS does a postback, even if it returns false. I have no
ideas why'
The plot thickens... I don't know if this really matters or not, but this
button is in a datagrid.
Can anyone explain to me why the javascript function posts back'? The
code is posted below.
Thank you in advance!
SteveS
******ASPX CODE************
<asp:Datagirid.....>
.
<asp:TemplateColumn HeaderText="Deny" ItemStyle-HorizontalAlign=Center
HeaderStyle-HorizontalAlign=Center>
<ItemTemplate>
<asp:Button text="Deny" ID="btnDeny" Runat="server"
CommandName="btnDeny"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
.
</asp:Datagrid>
<script lang=javascript>
function OpenDenyWindow(changeId, btn) {
var ret = false
retVal=window.showModalDialog('DenialEmailForm.aspx?id=' +
changeId+'&mem='+document.Form1.hdnMemId.value,'', '');
alert ("retval = " + retVal)
if (retVal == "Successful") {
//return true
ret = true
}
else {
//return false
ret = false
}
alert(ret);
// *** even if this function returns a FALSE, the form is still posted
when I am not running the web page from my local host.
return ret;
}
**** CODE BEHIND****
Private Sub grdList_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdList.ItemCreated
'ADD THE JAVASCRIPT TO TO THE BUTTON
Dim ctrlDeny As Button = CType(e.Item.FindControl("btnDeny"),
Button)
If Not IsNothing(ctrlDeny) Then
Dim grid As DataGrid = CType(sender, DataGrid)
ctrlDeny.Attributes.Add("onclick", "return OpenDenyWindow("
& grid.DataKeys(e.Item.ItemIndex).ToString & ", this); return false;")
End If
End SubWhat is the configuration of the browser on the other PC? Maybe it has
disabled javascript?
"SteveS" <ssinger@.trendmls.com> wrote in message
news:uZ4IRSWIEHA.2128@.TK2MSFTNGP11.phx.gbl...
> Hello. This problem is perplexing me.
> I have a asp:button which runs a javascript function when it is clicked.
It
> returns a true or false depending if a postback is needed. This works
great
> when I run it on my development pc. But, when I run it from another
> computer, it ALWAYS does a postback, even if it returns false. I have no
> ideas why'
> The plot thickens... I don't know if this really matters or not, but this
> button is in a datagrid.
> Can anyone explain to me why the javascript function posts back'? The
> code is posted below.
> Thank you in advance!
> SteveS
>
> ******ASPX CODE************
> <asp:Datagirid.....>
> .
> <asp:TemplateColumn HeaderText="Deny" ItemStyle-HorizontalAlign=Center
> HeaderStyle-HorizontalAlign=Center>
> <ItemTemplate>
> <asp:Button text="Deny" ID="btnDeny" Runat="server"
> CommandName="btnDeny"></asp:Button>
> </ItemTemplate>
> </asp:TemplateColumn>
> .
> </asp:Datagrid>
> <script lang=javascript>
> function OpenDenyWindow(changeId, btn) {
> var ret = false
> retVal=window.showModalDialog('DenialEmailForm.aspx?id=' +
> changeId+'&mem='+document.Form1.hdnMemId.value,'', '');
> alert ("retval = " + retVal)
> if (retVal == "Successful") {
> //return true
> ret = true
> }
> else {
> //return false
> ret = false
> }
> alert(ret);
> // *** even if this function returns a FALSE, the form is still
posted
> when I am not running the web page from my local host.
> return ret;
> }
>
> **** CODE BEHIND****
> Private Sub grdList_ItemCreated(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
grdList.ItemCreated
> 'ADD THE JAVASCRIPT TO TO THE BUTTON
> Dim ctrlDeny As Button = CType(e.Item.FindControl("btnDeny"),
> Button)
> If Not IsNothing(ctrlDeny) Then
> Dim grid As DataGrid = CType(sender, DataGrid)
> ctrlDeny.Attributes.Add("onclick", "return
OpenDenyWindow("
> & grid.DataKeys(e.Item.ItemIndex).ToString & ", this); return false;")
> End If
> End Sub
>
>
>
>

Thursday, March 22, 2012

Thread aborted when doing HttpContext.Current.Response.End

Hi,
I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I a
m
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea
Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.

Thread aborted when doing HttpContext.Current.Response.End

Hi,

I have written a function to export the datagrid data to excel. In that
function I was calling HttpContext.Current.Response.End() at the end. If I am
doing this, I am getting an exception message "Thread was being aborted". If
I don't do this then it is exporting the whole data instead of just the
datagrid. I am not knowing what might be the problem. Please let me know if
you have any idea

Thnx,
Sridhar.That's just how Response.End() works, it throws a ThreadAbortExxception.
You can't doing anything wrong, but you may. You'll either need to handle
(catch/swallow/hide) the exception or change your page so only the grid
shows and there's no need to End the request.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Sridhar" <Sridhar@.discussions.microsoft.com> wrote in message
news:92D1C4A0-006D-4DB7-87D3-86E26C8D0FD9@.microsoft.com...
> Hi,
> I have written a function to export the datagrid data to excel. In that
> function I was calling HttpContext.Current.Response.End() at the end. If I
> am
> doing this, I am getting an exception message "Thread was being aborted".
> If
> I don't do this then it is exporting the whole data instead of just the
> datagrid. I am not knowing what might be the problem. Please let me know
> if
> you have any idea
> Thnx,
> Sridhar.

Tuesday, March 13, 2012

Thread safety issue

In my VB.Net ASP project, I have a function in a module (same thing as a
static function in C#'s terms) that is shared by all the sessions. What is
does once called is to write messages into a common log file that's also
shared by all the sessions. To make sure it is thread safe, I use the Monitor
class to sync it up. Here is the simplified version of that function"

Public Sub WriteLog(ByVal strMsg As String)
Dim oWriter As StreamWriter
Dim strLogPath As String = "C:\Logs\test.log"

If Not File.Exists(strLogPath) Then
oWriter = File.CreateText(strLogPath)
Else
oWriter = File.AppendText(strLogPath)
End If

Monitor.Enter(oWriter)
Try
oWriter.WriteLine(strMsg)
oWriter.Flush()
oWriter.Close()
Finally
Monitor.Exit(oWriter)
End Try
End Sub

My problem is that this code doesn't seem to do what I want it to do. I am
still getting error that says "The process cannot access the file
'C:\Logs\test.log' because it is used by another process.". Why is this
happening? I must be doing something wrong. Can some one tell me how I should
do this?

Thanks a million!

Fengthe object you are locking on is local to the call, so threads do not block
each other because they are all locking different objects.

you need to lock on a static object. you could use the class type, but there
is a performance hit for this, better to create an actual object to lock on.
also the File.Exists need to be in lock.

-- bruce (sqlwork.com)

"Feng" <Feng@.discussions.microsoft.com> wrote in message
news:159CE973-735B-4ED4-BC21-EA7BA0760E20@.microsoft.com...
> In my VB.Net ASP project, I have a function in a module (same thing as a
> static function in C#'s terms) that is shared by all the sessions. What is
> does once called is to write messages into a common log file that's also
> shared by all the sessions. To make sure it is thread safe, I use the
> Monitor
> class to sync it up. Here is the simplified version of that function"
> Public Sub WriteLog(ByVal strMsg As String)
> Dim oWriter As StreamWriter
> Dim strLogPath As String = "C:\Logs\test.log"
> If Not File.Exists(strLogPath) Then
> oWriter = File.CreateText(strLogPath)
> Else
> oWriter = File.AppendText(strLogPath)
> End If
> Monitor.Enter(oWriter)
> Try
> oWriter.WriteLine(strMsg)
> oWriter.Flush()
> oWriter.Close()
> Finally
> Monitor.Exit(oWriter)
> End Try
> End Sub
> My problem is that this code doesn't seem to do what I want it to do. I am
> still getting error that says "The process cannot access the file
> 'C:\Logs\test.log' because it is used by another process.". Why is this
> happening? I must be doing something wrong. Can some one tell me how I
> should
> do this?
> Thanks a million!
> Feng