|
|
When I click once on button the event is not fired..when I click twice then only the event is fired...what culd the proble b?
thanx
|
|
|
|
|
Hard to say, without seeing any code. No way does a button not fire until you click it twice.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
The code is in C#
I have written a javascript code on click event of button following is the code:
Also once condition is true i hv displayed a grid view getting data from db
function checkDotOnly()
{
if (document.form1.txtcustomerName.length!=0)
{
if((document.form1.txtcustomerName.value==".")||(document.form1.txtcustomerName.value==". ")||(document.form1.txtcustomerName.value==" "))
{
alert("Please Enter Valid Customer Name.");
/*document.form1.lblErrMsg.value="Please Enter Valid Customer Name.";
document.form1.lblErrMsg.disabled=false;*/
return false;
}
return true;
}
return true;
}
thanx
|
|
|
|
|
ouch.. Very tough to read that script. Let me make it more clear
<script language="javascript" type="text/javascript">
function checkDotOnly()
{
if (document.form1.txtcustomerName.length!=0)
{
if((document.form1.txtcustomerName.value==".") ||(document.form1.txtcustomerName.value==". ") ||(document.form1.txtcustomerName.value==" "))
{
alert("Please Enter Valid Customer Name.");
return false;
}
return true;
}
return true;
}
</script>
I think last two true you are returning. That is making problem. Try writting this like
<script language="javascript" type="text/javascript">
function checkDotOnly()
{
if (document.form1.txtcustomerName.length!=0)
{
if((document.form1.txtcustomerName.value==".") ||(document.form1.txtcustomerName.value==". ") ||(document.form1.txtcustomerName.value==" "))
{
alert("Please Enter Valid Customer Name.");
return false;
}
else
return true;
}
else
return true;
}
</script>
|
|
|
|
|
hello miniThomas,
Call that javascript in the Buton in onclientclick....It will work it is client side event.....
ok byeee
|
|
|
|
|
You might have coded under button_doubleClick
You right the code under button_Click
Try it out
Vidya
|
|
|
|
|
Hi Vidya,
The code is written On Click event
<asp:imagebutton id="imgbtnSearch" runat="server" imageurl="~/images/search.gif" alternatetext="Search" height="35" width="30" onclick="imgbtnSearch_Click">
thanx
|
|
|
|
|
Hi,
Have you added this javascript function as the attributes of the button.
EX: Button1.attributes.add("OnClick","<Javascript function>")
Try this out.
Regards,
Manowj
|
|
|
|
|
vidya.p.nair wrote: You might have coded under button_doubleClick
It's ASP.NET. Not windows app. In this you won't get double click event.
|
|
|
|
|
Hi Guys,
here is code:
<asp:imagebutton id="imgbtnSearch" runat="server" imageurl="~/images/search.gif" alternatetext="Search" height="35" width="30" onclick="imgbtnSearch_Click">
function checkDotOnly()
{
if (document.form1.txtcustomerName.length!=0)
{
if((document.form1.txtcustomerName.value==".")||(document.form1.txtcustomerName.value==". ")||(document.form1.txtcustomerName.value==" "))
{
alert("Please Enter Valid Customer Name.");
/*document.form1.lblErrMsg.value="Please Enter Valid Customer Name.";
document.form1.lblErrMsg.disabled=false;*/
return false;
}
return true;
}
return true;
}
protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
{
if (RadioButtonList1.SelectedValue.ToString() == "")
{
lblMsg.Text = "";
lblErrMsg.Visible = true;
lblErrMsg.Text = "Please Select One Option.";
PnlSearchResults.Visible = false;
}
else
{
if (RadioButtonList1.SelectedIndex.ToString() == "0" && ddlOrderNo.SelectedItem.Value == "-1")
{
lblMsg.Text = "";
lblErrMsg.Visible = true;
lblErrMsg.Text = "Please Select Order Number.";
PnlSearchResults.Visible = false;
}
else
{
lblErrMsg.Visible = false;
fillSearchResults();
}
if (RadioButtonList1.SelectedIndex.ToString() == "1")
{
if (txtcustomerName.Text == "")
{
lblMsg.Text = "";
lblErrMsg.Visible = true;
lblErrMsg.Text = "Please Enter Customer Name.";
PnlSearchResults.Visible = false;
}
else
{
lblMsg.Text = "";
lblErrMsg.Visible = false;
fillSearchResults();
//Response.Write("domain=" + txtDomainName.Text + "cust=" + txtcustomerName.Text);
}
}
}
}//imgbtnSearch_Click
thanx
|
|
|
|
|
Have you tried suggestion in my previous posting ?
|
|
|
|
|
Scenario:
I have two web users. If user 1 makes a change to an Application server state variable, how do I notify user 2 about the new info without doing constant javascript polling in a timer using Ajax, which is what I am doing right now?
I would like to make this more efficient because the contant polling seems expensive to me. Any ideas?
Thanks!
|
|
|
|
|
AJAX is the only way you can send info to a user who does not themselves click on a link, or go to a new page.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi All,
We have two dropdownlists in my web page.In second dropdownlist items will be appear based upon first dropdownlist selection item with out page postback.I have implemented using System.Web.UI.ICallbackEventHandler interface with asp.net2.0. But i structed with button click event.If i click button for save the info into database the second dropdownlist items cleared.I am sending my code here.Pls go throught it tell me solution.....
CODEBEHIEND CODE:
Using System;
Using System.Data;
Using System.Data. SqlClient;
Using System.Configuratio n;
Using System.Web.Configur ation;
Using System.Collections;
Using System.Web;
Using System.Web.Security ;
Using System.Web.UI;
Using System.Web.UI. WebControls;
Using System.Web.UI. WebControls. WebParts;
Using System.Web.UI. HtmlControls;
Using System.Text;
Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private string raiseCallArgument, stateId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;
SqlConnection con = new SqlConnection(strConnection) ;
string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";
using (con)
{
con.Open();
SqlCommand objCmd = new SqlCommand(strSQL, con);
SqlDataReader dtReader = objCmd.ExecuteReade r();
using (dtReader)
{
if (dtReader.HasRows)
{
ddl.DataSource = dtReader;
ddl.DataTextField = "Statename";
ddl.DataValueField = "Statename";
ddl.DataBind( );
}
}
}
}
if (Request.Browser. SupportsCallback )
{
string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");
ddl.Attributes["onChange"] = callbackRef;
}
}
public void RaiseCallbackEvent(string raiseCallArgument)
{
this.raiseCallArgument = raiseCallArgument;
stateId = this.raiseCallArgument;
}
//This method should return a string value for the Javascript method to handle
public string GetCallbackResult( )
{
StringBuilder returnString = new StringBuilder();
using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))
{
cn.Close();
cn.Open();
SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);
SqlDataReader dr;
dr = cmd1.ExecuteReader( );
string str = "";
while (dr.Read())
{
str = dr[
"Stateid"].ToString() ;
}
dr.Close();
cn.Close();
int a = ddl.SelectedIndex + 1;
string exp = raiseCallArgument;
try
{
cn.Open();
SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str, cn);
SqlDataReader rdr1 = cmd.ExecuteReader( );
using (rdr1)
{
while (rdr1.Read() )
{
returnString. Append(rdr1[ 2]);
returnString. Append(",");
}
}
rdr1.Close() ;
cn.Close();
}
catch (Exception ex)
{
Response.Write( ex.Message) ;
}
}
return returnString. ToString( );
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write( ddl.SelectedItem .Text);
Response.Write( DropDownList1. SelectedItem. Text);
}
}
ASPX CODE:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallBack. aspx.cs" Inherits="ClientCallBack" EnableEventValidati on="false" %>
<
html xmlns="http://www. w3.org/1999/ xhtml">
<
head id="Head1" runat="server">
<title>Client Callback on ChillapzLocal
//Function to handle and process the server-side result
//The result comes as string and the method takes two arguments, here.
function CallbackonClientsid e(stringResult, context)
{
var listCompany = document.forms[ 0].elements['DropDownList1'];
listCompany. innerHTML =
"";
var entries = stringResult. split(',');
var str = "";
for(var i=0;i<entries.length- 1;i++)
{
var company = entries[i];
//Create the list item
var item = document.createElem ent('option');
item.value = company;
item.innerHTML = company;
listCompany. appendChild( item);
}
//alert("end" );
}
<
body>
State:
<asp:dropdownlist id="ddl" runat="server">
County:
<asp:dropdownlist id="DropDownList1" runat="server">
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="Button">
|
|
|
|
|
Can you narrow down where the problem is occurring? It is rather difficult with the way the code is formatted in your post. Try to have it inside < pre > / < /pre >tags to preserve the indentation for the most part
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi Paul,
Thank you for the immediate reply.I am sending code put it in pre tags...
CODEBEHIEND CODE:
Using System;
Using System.Data;
Using System.Data. SqlClient;
Using System.Configuratio n;
Using System.Web.Configur ation;
Using System.Collections;
Using System.Web;
Using System.Web.Security ;
Using System.Web.UI;
Using System.Web.UI. WebControls;
Using System.Web.UI. WebControls. WebParts;
Using System.Web.UI. HtmlControls;
Using System.Text;
Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private string raiseCallArgument, stateId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;
SqlConnection con = new SqlConnection(strConnection) ;
string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";
using (con)
{
con.Open();
SqlCommand objCmd = new SqlCommand(strSQL, con);
SqlDataReader dtReader = objCmd.ExecuteReade r();
using (dtReader)
{
if (dtReader.HasRows)
{
ddl.DataSource = dtReader;
ddl.DataTextField = "Statename";
ddl.DataValueField = "Statename";
ddl.DataBind( );
}
}
}
}
if (Request.Browser. SupportsCallback )
{
string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");
ddl.Attributes["onChange"] = callbackRef;
}
}
public void RaiseCallbackEvent(string raiseCallArgument)
{
this.raiseCallArgument = raiseCallArgument;
stateId = this.raiseCallArgument;
}
public string GetCallbackResult( )
{
StringBuilder returnString = new StringBuilder();
using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))
{
cn.Close();
cn.Open();
SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);
SqlDataReader dr;
dr = cmd1.ExecuteReader( );
string str = "";
while (dr.Read())
{
str = dr[
"Stateid"].ToString() ;
}
dr.Close();
cn.Close();
int a = ddl.SelectedIndex + 1;
string exp = raiseCallArgument;
try
{
cn.Open();
SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str, cn);
SqlDataReader rdr1 = cmd.ExecuteReader( );
using (rdr1)
{
while (rdr1.Read() )
{
returnString. Append(rdr1[ 2]);
returnString. Append(",");
}
}
rdr1.Close() ;
cn.Close();
}
catch (Exception ex)
{
Response.Write( ex.Message) ;
}
}
return returnString. ToString( );
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write( ddl.SelectedItem .Text);
Response.Write( DropDownList1. SelectedItem. Text);
}
}
ASPX CODE:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallBack. aspx.cs" Inherits="ClientCallBack" EnableEventValidati on="false" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ /EN" "http://www. w3.org/TR/ xhtml1/DTD/ xhtml1-transitio nal.dtd">
<
html xmlns="http://www. w3.org/1999/ xhtml">
<
head id="Head1" runat="server">
<title>Client Callback on ChillapzLocal</title>
<script type="text/javascript" language="javascript">
function CallbackonClientsid e(stringResult, context)
{
var listCompany = document.forms[ 0].elements['DropDownList1'];
listCompany. innerHTML =
"";
var entries = stringResult. split(',');
var str = "";
for(var i=0;i<entries.length- 1;i++)
{
var company = entries[i];
var item = document.createElem ent('option');
item.value = company;
item.innerHTML = company;
listCompany. appendChild( item);
}
}
</script>
</
head>
<
body>
<form id="form1" runat="server">
<div>
State:
<asp:DropDownList ID="ddl" runat="server">
</asp:DropDownList>
<br />
<br />
County:
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList> <br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</
body>
</
html>
|
|
|
|
|
Hi paul,
I posted aspx source code but in that code i had two dropdownlist and one button control those controls are not displaying in the posted message.why it is not appearing?
|
|
|
|
|
You may have to step through the code, cannot really tell where the problem is.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi Paul,
Just go through the below link
http://www.remapper.com/callback.aspx
In that i have two dropdownlists,I will select state from first dropdownlist then those counties will be appear in second dropdownlist without postaback of the page.I am getting but if i click the button for retreiving selected state and county value then county values are disappeared.
|
|
|
|
|
hello dharini,
try to keep the countrydropdownlist in AutPostBack=True or otherwise how ur calling the values of the dropdownlist of country like that call that function int the button click event.
ok then u will get
byeee
Murali
Murali
|
|
|
|
|
Hi Murali,
Thank you for the reply.Actually,my requirement is fill the county dropdownlist with out page postback.I am sending my code below...Just go thru it....That code copy into ur application and check it.
CODEBEHIEND CODE:
Using System;
Using System.Data;
Using System.Data. SqlClient;
Using System.Configuratio n;
Using System.Web.Configur ation;
Using System.Collections;
Using System.Web;
Using System.Web.Security ;
Using System.Web.UI;
Using System.Web.UI. WebControls;
Using System.Web.UI. WebControls. WebParts;
Using System.Web.UI. HtmlControls;
Using System.Text;
Public partial class ClientCallBack : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
{
private string raiseCallArgument, stateId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string strConnection = WebConfigurationMan ager.ConnectionStrings["DemoConn"].ConnectionString;
SqlConnection con = new SqlConnection(strConnection) ;
string strSQL = "SELECT DISTINCT * FROM tblRmStateMaster";
using (con)
{
con.Open();
SqlCommand objCmd = new SqlCommand(strSQL, con);
SqlDataReader dtReader = objCmd.ExecuteReade r();
using (dtReader)
{
if (dtReader.HasRows)
{
ddl.DataSource = dtReader;
ddl.DataTextField = "Statename";
ddl.DataValueField = "Statename";
ddl.DataBind( );
}
}
}
}
if (Request.Browser. SupportsCallback )
{
string callbackRef = Page.ClientScript. GetCallbackEvent Reference(this, "document.forms[ 0].elements[ 'ddl'].value", "CallbackonClientsi de", "null");
ddl.Attributes["onChange"] = callbackRef;
}
}
public void RaiseCallbackEvent(string raiseCallArgument)
{
this.raiseCallArgument = raiseCallArgument;
stateId = this.raiseCallArgument;
}
public string GetCallbackResult( )
{
StringBuilder returnString = new StringBuilder();
using (SqlConnection cn = new SqlConnection(ConfigurationManage r.ConnectionStrings["DemoConn"].ToString() ))
{
cn.Close();
cn.Open();
SqlCommand cmd1 = new SqlCommand("select * from tblRmStateMaster where Statename='" + stateId + "' ", cn);
SqlDataReader dr;
dr = cmd1.ExecuteReader( );
string str = "";
while (dr.Read())
{
str = dr[
"Stateid"].ToString() ;
}
dr.Close();
cn.Close();
int a = ddl.SelectedIndex + 1;
string exp = raiseCallArgument;
try
{
cn.Open();
SqlCommand cmd = new SqlCommand("select DISTINCT * from tblRmCountyMaster where Stateid=" + str, cn);
SqlDataReader rdr1 = cmd.ExecuteReader( );
using (rdr1)
{
while (rdr1.Read() )
{
returnString. Append(rdr1[ 2]);
returnString. Append(",");
}
}
rdr1.Close() ;
cn.Close();
}
catch (Exception ex)
{
Response.Write( ex.Message) ;
}
}
return returnString. ToString( );
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write( ddl.SelectedItem .Text);
Response.Write( DropDownList1. SelectedItem. Text);
}
}
ASPX CODE:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="ClientCallBack. aspx.cs" Inherits="ClientCallBack" EnableEventValidati on="false" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional/ /EN" "http://www. w3.org/TR/ xhtml1/DTD/ xhtml1-transitio nal.dtd">
<
html xmlns="http://www. w3.org/1999/ xhtml">
<
head id="Head1" runat="server">
<title>Client Callback on ChillapzLocal</title>
<script type="text/javascript" language="javascript">
function CallbackonClientsid e(stringResult, context)
{
var listCompany = document.forms[ 0].elements['DropDownList1'];
listCompany. innerHTML =
"";
var entries = stringResult. split(',');
var str = "";
for(var i=0;i<entries.length- 1;i++)
{
var company = entries[i];
var item = document.createElem ent('option');
item.value = company;
item.innerHTML = company;
listCompany. appendChild( item);
}
}
</script>
</
head>
<
body>
<form id="form1" runat="server">
<div>
State:
<asp:DropDownList ID="ddl" runat="server">
</asp:DropDownList>
<br />
<br />
County:
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList> <br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</
body>
</
html>
|
|
|
|
|
dharanighanta wrote: my requirement is fill the county dropdownlist with out page postback
Why? I doubt it is possible without page postback. Anytime I've done web stuff that required populating a control after another control had some user action performed on it, I've always had to run the page through again but the next time, conditional branches guiding the behind the scenes code based on that user action.
I don't know much about Ajax, but maybe that could help.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Friends,
I am working on a Product which is migrated from Visual Basic 6.0 to .NET 2.0.
The product uses ADO Connection object. And the connection object is using Reshape Name Property (MSDataShape) and SHAPE method to concatenate set of tables.
Right now, the DB Connection is using Standard Login Method. We are trying to implement Integrated Security Login. This MSDataShape does not supporting Integrated Security. Any one has solution without removing MSDataShape to achieve Integrated Security?
Current ConnectionString,
"Provider=MSDataShape; Data Provider=MSDASQL; DSN=MyDSN; UID=user1; PWD=pass;"
I tried as,
"Provider=MSDataShape; Data Provider=MSDASQL; DSN=MyDSN; Integrated Security = SSPI"
|
|
|
|
|
This doesn't look like an ASP.NET question to me ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|