|
Hi all,
Im using C# as my code behind, im having a code in the button click event where im checking whether a file is exists, if it exists then it show the confirmation message box like "file found, want to continue", but its happening if we register the script in the page load and its not checking the condition. By clciking the button itself its showing the message box.
i need that script should get pop up only after the condition get satisfied. Is it possible? Please help me out to solve this problem. Thanks a lot in advance.
The code is given below
private void Page_Load(object sender, System.EventArgs e)
{
i = "file Exists";
StringBuilder str = new StringBuilder();
str.Append("");
str.Append("function PopWindow()");
str.Append("{");
str.Append("alert('hello world')");
str.Append("}");
str.Append("");
if(!Page.IsClientScriptBlockRegistered("clientscript"))
{
Page.RegisterStartupScript("clientscript",str.ToString());
}
Button1.Attributes.Add("onclick","PopWindow();");
}
private void Button1_Click(object sender, System.EventArgs e)
{
if (i=="file Exists")
{
int x= 0;
int y =0;
x = x+ y;
Button1.Attributes.Add("onclick","PopWindow();");
int a = 2;
int z = 2;
z = z+ a;
Response.Write(z.ToString());
}
}
Regards
Mukilan.
REgards
Mukilan
|
|
|
|
|
Well the problem is that client side code always get executed before the page is sent to the server.
So if your button has a server-side event and also a client side one (Button1.Attributes.Add("onclick","PopWindow();"); ) the PopWindow() will get called when you press the button and after that the page will be send to the server.
What you need to do is register the client script to be shown after the page has been submitted. So do not add an onclick attribute to the button, but in the Button1_Click(object sender, System.EventArgs e) method after validating if you need to show a popup just use Page.RegisterClientScriptBlock("msg","PopWindow();); . This will cause the PopWindow javascript method to be called after the page loads on the clients side.
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
thank u very much for your suggestion
but if i register code after checking the condition, that message box is not getting pop upped, in the browser if we click button, the "popwindow()" string is getting displayed
Code is given below,
private void Button1_Click(object sender, System.EventArgs e)
{
if (i=="file Exists")
{
int x= 0;
int y =0;
x = x+ y;
StringBuilder str = new StringBuilder();
str.Append("");
str.Append("function PopWindow()");
str.Append("{");
str.Append("alert('hello world')");
str.Append("}");
str.Append(""); Page.RegisterClientScriptBlock("clientscript","PopWindow();");// Here is the problem
Another Way
Page.RegisterClientScriptBlock("clientscript",PopWindow()); // its giving build error as follows(without specified in the quotes)
c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.cs(79): The name 'PopWindow' does not exist in the class or namespace 'WebApplication1.WebForm1'
int a = 2;
int z = 2;
z = z+ a;
}
}
Mukil
|
|
|
|
|
Why are you dynamically creating the PopWindow function. Surely if it's static you can just include it in the head of the page?
|
|
|
|
|
psmukil wrote: StringBuilder str = new StringBuilder();
str.Append("");
str.Append("function PopWindow()");
str.Append("{");
str.Append("alert('hello world')");
str.Append("}");
str.Append(""); Page.RegisterClientScriptBlock("clientscript","PopWindow();");// Here is the problem
You are only putting the code for the function in the StringBuilder, you don't use it for anything.
The StringBuilder doesn't automatically recognise that you have created a script, and that there is a web page where the script could go. Neither does the RegisterClientScriptBlock automatically recognise that you happen to have a StringBuilder that contains a script with a function that corresponds with the function call in the code that you do add to the page.
---
b { font-weight: normal; }
-- modified at 8:28 Tuesday 4th July, 2006
|
|
|
|
|
The problem is that you don't have any function called PopWindow() in your rendered page. Why? Because you didn't place it there. You have just defined the StringBuilder in you method, but didn't send it to the page.
1. Put the Javascript in a .js file and inlcude a link to it from HTML
or
2. Register the javascript in the page on page_load just as you do the function call.
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
google can't search my image in my web site
how can i solve it ?
With Thanks
MHF
|
|
|
|
|
I create DataTable in code C# as Add-method of DataRow. Then I do DataGrid.DataSource = DataTable and DataGrid.DataBind.
Can I set BackColor for DataRow at moment of work Add-method? It is impossible to set BackColor for object DataGridItem in DataGrid in my situation.
michailk2001
|
|
|
|
|
|
I have done windows authentication customization in my project which works on the intranet site , but not on internet site. how can i know that a site is internet or intranet at the customer side. i can't access their site, i just want to know whether it is internet or intranet site.
SatyajitV .Net developer
|
|
|
|
|
Hi!
I have a password fields in a Login form. Now I try to encode it then so decode it again. Please help me!
Thanks!
|
|
|
|
|
What is it that you need help with?
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
.NEt provides algorithms for encryption and decryption in namespace System.Security.Cryptography
Check it,
Thanks
Sushant Duggal.
|
|
|
|
|
Pls , can anybody give me some information related to conversion of xml document to word document using asp.net.
Balasaheb
Software Developer
Platform: Asp.net,vb.net
Database: SQL Server 2000
|
|
|
|
|
Hi there,
You can use the XSLT to transform an XML document to a word document in xml format. Basically, you need to understand the XML schema[^] for a Word document, then you can produce an XSL stylesheet to transform the xml file.
|
|
|
|
|
Hi,
Are there any tab controls in ASP.NET 2.0?? If so what is it called because I can't find it.
Regards,
ma se
|
|
|
|
|
Not that I know of. But you can emulate a tab control by using a table and showing/hiding rows using style display:none; and display:""
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
|
Exactly my point. Take a look at the source code. You will see that there is a table and the information in the table is in two rows. When the user clicks on the name it simply hides and displays the rows using style "display" property
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
As you already know that, there's no tab control existing in the ASP.NET 2.0, but you can either have a look at the third party control in the Control Gallery like you did or use the MultiView and View controls to do on your own.
|
|
|
|
|
Hi, I am asked to work on ASP.NET2.0 web development project which is already in development stage. This project development is in ASP.NET2.0 and SQL Express.
I have downloaded the project related files from the server.
I saw few files as having ".dtsx" extenstion. and one script file (text file, consisting a script to create tables.)
I have following questions.
1. What is .dtsx file meant for?
2. How can I run the query to create datatables? I mean here, in SQL 2000, I used query analyzer to execute queries. How can I do it in SQLExpress? Can I execute the query from VS.NET2005?
Please let me know. Thanks in advance.
|
|
|
|
|
I don't know what the .dtsx file stands for, but you can execute queries and perform most operations on SQL Express using Microsoft SQL Server Management Studio Express[^]. I think you will find it very usefull.
regards,
Mircea
Many people spend their life going to sleep when they’re not sleepy and waking up while they still are.
|
|
|
|
|
|
Hey!
I am about to build a photo site(using ASP.net 2.0 membership with roles) where users will be able to create there albums and upload images. The folder structure will look something like this.
Solution
*photoStore
**Users
***Calle
****Album01
*****Thumbnail
******picture01.jpeg
******picture02.jpeg
*****Medium
******picture01.jpeg
******picture02.jpeg
*****Big
******picture01.jpeg
******picture02.jpeg
***Olle
****Album01
Etc
This structure will make it easy to give a url to a specific image, for example:
www.photosite.se/photoStore/Users/Calle/Album01/Medium/picture01.jpeg
My wish is to be able to set permissions on these dynamic created folders. Maybe Calle have stated that Album01 should only be private, this means that by enter the url above only the user Calle should be able to see the images.
I know that you can set permissions in web.config on folders, but i need to do this dynamically(if a user creates a new album he/she will be able to choose if the album should be private, public or maybe open for just some specific users).
Is this possible to do? and if, how ?
Best Regards
Jimmy
|
|
|
|
|
Hi
i am using vs2005 in which i have to create custom control . But don't know how to create it in VS2005 . Please can anyone send me link for that Also i want to learn Custom control
|
|
|
|