473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Mixing a client-side/server-side event

I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #1
7 1509
Hi,
Add this code in form load or any other appropriate event:
btnSearch.Attributes.Add("onClick","return javascript:DisplayLabelText();")
After adding this attribute, your asp:button (search button) will call the
javascript function first then submit the form if the function returns true,
otherwise it halts further execution if false is returned.
Code for javascript function would be something like this:
<script language="Javascript">
function DisplayLabelText()
{
document.getElementsByTagName('lblCkeck').innerTex t = 'Getting Data..';
return true;
}
</script>
Although i may not written exact syntax but i hope you have got an idea
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #2

"jonefer" <jo*****@discussions.microsoft.comwrote in message
news:C5**********************************@microsof t.com...
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...."
text
in the lblCheck - because it needs to do a round-trip to the server -
first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Don't hold me to it, but if you're using .Net 2.0, can't you use this?

Label1.Text = Server.HtmlEncode("Getting data.....")

I noticed it populated the label before it made the round trip when I pushed
the Submit button.

Jun 5 '07 #3
Tried it and understand what it is supposed to do, but I will have to request
that you help me get the javascript exactly right, since I am unfamiliar with
what it needs exactly

the error I am recieving is: 'Error: expected ";"

and as you know, you ended all your lines with that.

"Manish Bafna" wrote:
Hi,
Add this code in form load or any other appropriate event:
btnSearch.Attributes.Add("onClick","return javascript:DisplayLabelText();")
After adding this attribute, your asp:button (search button) will call the
javascript function first then submit the form if the function returns true,
otherwise it halts further execution if false is returned.
Code for javascript function would be something like this:
<script language="Javascript">
function DisplayLabelText()
{
document.getElementsByTagName('lblCkeck').innerTex t = 'Getting Data..';
return true;
}
</script>
Although i may not written exact syntax but i hope you have got an idea
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #4
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:ret urn
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #5
Ok, I implemented it, however --- it still doesn't do anything.

I read something about the property: OnClientClick

Here is a sample that actually does something:
<asp:Button ID="btnAlert" runat="server" OnClientClick="alert('Are you sure
you want to do this? (I dont do anything really.)');" Text="Client Alert"
UseSubmitBehavior="false" />

Can you help me modify it so that it just changes the text in lblCheck?
"Manish Bafna" wrote:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:ret urn
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #6
Ok, these two pieces effectively work to make the label say "Getting Data"
However - Now the SearchActionList() function that I run the code-behind
file doesn't run anymore. Did the client-side scripting replace the
code-behind OnClick?

[1]
function doClientCode(msg){
document.getElementById('<%=lblCheck.ClientID %>').innerText = msg;
document.getElementById('<%=btnSearch.ClientID %>').disabled = true;
}

[2] Code on in the Asp: button tag
<asp:Button ID="btnSearch" runat="server" onclientclick="javascript:return
doClientCode('Getting data....');" Text="Search" />

"Manish Bafna" wrote:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:ret urn
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #7
It works, but now the Code-Behind routine connected to the button doesn't work.
How can I make the client-side run as well as the

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

SearchActionList()

End Sub

They need to both work.
"Manish Bafna" wrote:
Hi,
Below code is working perfectly well in my machine:
[1] Javascript Code:
<script language="Javascript">
function DisplayLabelText()
{
var obj = document.getElementById('lblCheck');
obj.innerText = 'Getting Data..' ;
return true;
}
</script>
[2]Code you will write in page load:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
btnSearch.Attributes.Add("onClick","javascript:ret urn
DisplayLabelText();");

}
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"jonefer" wrote:
I'm hoping this is a classic question, but the answer to it would help me
with a lot of things.

As you can see below, this code will never display the "Getting data...." text
in the lblCheck - because it needs to do a round-trip to the server - first.
And when it gets back, my other routine will over-write the text as "34
records found"

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click

Me.lblCheck.Text = "Getting data....."
SearchActionList()

End Sub
Jun 5 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: bergel | last post by:
Hello, Does anyone already have some experience in mixing AWT and Swing? Is it conceptually doable? Does the design of Swing prevent interaction between an AWT and a Swing widget? Regards,...
6
by: Russell E. Owen | last post by:
At one time, mixing for x in file and readline was dangerous. For example: for line in file: # read some lines from a file, then break nextline = readline() # bad would not do what a naive...
0
by: Erik Max Francis | last post by:
Is there any prohibition against mixing different protocols within the same pickle? I don't see anything about this in the Python Library Reference and, after all, the pickle.dump function takes a...
4
by: Rudolf | last post by:
Is it possible to add a vb.net source code module to a c# project and if so how? Thanks Rudolf
1
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
4
by: Cristian Tota | last post by:
Hi, I'd appreciate any thoughts on mixing C++ and C code. I have a project that uses a given C interface, the rest of the project can be either in C or C++. What would be the recomended design...
2
by: Dan | last post by:
Hi What are the dangers of mixing asp and asp.net? For the .net part of the site i will need to use the global.asax file but for the asp parts it will be using the other global. file, is there...
28
by: ziman137 | last post by:
Hello all, I have a question and am seeking for some advice. I am currently working to implement an algorithmic library. Because the performance is the most important factor in later...
3
by: jason | last post by:
I've been working with C# for over a year now without touching vb.net code. I had a few light years of vb.net before that. No real vb6 or windows form experience. Suddenly, I have an assignment...
0
by: John Scheldroup | last post by:
Source: Article Mixing C and C++ Code in the Same Program By Stephen Clamage, Sun Microsystems, Sun ONE Studio Solaris Tools Development Engineering ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.