|
Thanks Kiran, that did the trick for TextBox keypress event, but for Radiobutton and CheckBox, the function in aspx is not firing:
I gave it like this:
rbn1.Attributes.Add("OnCheckedChanged", "Onkeypress(this)");
rbn2.Attributes.Add("OnCheckedChanged", "Onkeypress(this)");
function Onkeypress(thiss)
{
if (document.getElementById (thiss.id).checked == true)
alert("checked");
}
Why does it work when I hook the event handler as an attribute? And why doesn't it work for RadioButton and CheckBox?
Regards,
Blumen
|
|
|
|
|
Now it will work because OnCheckedChange is serverside event.but your function is at client side naa so write like this
rbn1.Attributes.Add("onclick", "Onkeypress(this)");
rbn2.Attributes.Add("onclick", "Onkeypress(this)");
Kiran Kumar.CH
(MCP)
|
|
|
|
|
You are getting the server-side and client-side events mixed up. For an <asp:Button> OnClick is the server side event (and expects a function name that is in your code behind) and OnClientClick is where you can put client-side javascript calls (this attribute simply expects a string). Have a look at the MSDN documentation for more.
|
|
|
|
|
I couldn't find OnClicntClick for CheckBox and RadioButton, what do we do in that case?
|
|
|
|
|
Hi,
This is my first time trying stored procedures on ASP.NET using C# but I am having some problem with the return value. Here is my stored procedures
CREATE PROCEDURE IsValidLogin
(
@username varchar(15) = NULL,
@password varchar(12) = NULL ,
@num_of_user INT = 0
)
AS
BEGIN
SET @num_of_user = (SELECT COUNT(*) AS num_of_user
FROM tb_user
WHERE useremail = @username AND userpassword = @password)
RETURN @num_of_user
END
GO
Then here is my code (btw, this is for login)
try
{
if (myConnection.State == ConnectionState.Closed)
{
myConnection.Open();
}
myCommand = new SqlCommand("IsValidLogin", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1, objParam2, objParam3;
objParam1 = myCommand.Parameters.Add("@username", SqlDbType.VarChar);
objParam2 = myCommand.Parameters.Add("@password", SqlDbType.Char);
objParam3 = myCommand.Parameters.Add("@num_of_user", SqlDbType.Int);
objParam1.Direction = ParameterDirection.Input;
objParam2.Direction = ParameterDirection.Input;
objParam3.Direction = ParameterDirection.ReturnValue;
objParam1.Value = this.TextBox1.Text;
objParam2.Value = this.TextBox2.Text;
myCommand.ExecuteNonQuery();
Response.Write(objParam3.Value);
}
catch(Exception exception)
{
throw exception;
}
finally
{
myConnection.Dispose();
myConnection.Close();
}
It keep on returning '0' whiich I don't know where it gone wrong.
Your help is much appreciated.
Thank you.
J Liang
|
|
|
|
|
J Liang wrote: RETURN @num_of_user
Try SELECT @num_of_user
|
|
|
|
|
Hi,
Do you mean doing SELECT @num_of_user instead of SELECT COUNT(*) AS num_of_user?
If it is, I don't think I could not select @num_of_user as it is suppose to capture the return value from the stored procedure and show it back to me.
Sorry if I did not get what you mean.
J Liang
|
|
|
|
|
Hi,
try this way...
SET @num_of_user = SELECT COUNT(*) FROM tb_user
WHERE useremail = @username AND userpassword = @password)
RETURN @num_of_user
Kiran Kumar.CH
(MCP)
|
|
|
|
|
Hi Kumar,
I'd tried, but the result is still the same, it returns the same value no matter what I type my username and password are.
J Liang
|
|
|
|
|
CREATE PROCEDURE IsValidLogin<br />
(<br />
@username varchar(15) = NULL,<br />
@password varchar(12) = NULL ,<br />
@num_of_user INT = 0 --This means that it's an input parameter<br />
)<br />
Try
CREATE PROCEDURE IsValidLogin
(
@username varchar(15) = NULL,
@password varchar(12) = NULL ,
@num_of_user INT = 0 OUTPUT
)
--Your SET statement here
--No need for a RETURN statement
(OR)
In your C# code
int retVal;<br />
retVal = myCommand.ExecuteNonQuery();
Remember:
If you want any custom output from your SP, use an OUTPUT parameter. By default an SP returns 0 if it was successful and non-zero in case of failure. This must be used exclusively for error checking.
SG
|
|
|
|
|
Hi i_like_tintin,
I tried your way and the retVal keep on returning -1 value. So I tried to display the objParam3.Value which I declare as objParam3.Direction = ParameterDirection.Output; and it return '0' to me no matter my username and password are correct.
|
|
|
|
|
Execute your SP in Query Analyzer and check if it works without errors for different sets of input.
SG
|
|
|
|
|
Hi using place holder & literal control,i created textbox in runtime...,
That code is:
In page load event:
Dim intcount As Integer
If Not IsPostBack Then
ViewState("BookFieldCount") = 1
ElseIf viewstate("BookFieldCount") > 1 Then
For intcount = 2 To viewstate("BookFieldCount")
addbookfield(intcount)
Next
End If
And in button click event:
viewstate("BookFieldCount") += 1
addbookfield(viewstate("bookfieldcount"))
and in "addbookfield" call procedure:
Sub addbookfield(ByVal strfieldnum As String)
Dim litlabel As LiteralControl
Dim txttextbox As TextBox
litlabel = New LiteralControl
litlabel.Text = "
Mark " & strfieldnum & ":"
plhbookfields.Controls.Add(litlabel)
txttextbox = New TextBox
txttextbox.ID = "txtproduct" & strfieldnum
plhbookfields.Controls.Add(txttextbox)
End Sub
After this code
if click the button u will get runtime textbox in ur screen...,
Now my ques is:
In runtime textbox if i enter values, how to add those values to my database?,
Normally with the id of the textbox we can add the values to tables...,
But in runtime textbox where we will get the id and how to add those values to my tables...,
Plz help me...
Magi
|
|
|
|
|
Hi,
When we are creating text box at runtime.
We can use the the object the text box.
but here You used same object "txttextbox" so you can
use "FindControl" method and assign it to a textbox and retrieve the
value.
Magh_M wrote: txttextbox.ID = "txtproduct" & strfieldnum
here u are assigning id to text box.U can use this ID inside FindControl.
To succeed, we must first believe that we can.
Sherin Iranimose
|
|
|
|
|
If u dont mind plz explain some what more...,
How to do that?
Magi
|
|
|
|
|
Hi,
I dont know what control is ir "plhbookfields"
U can use
Dim MyText as TextBox = plhbookfields.FindControl("YourTextboxID")
Now you can access the value by using
MyText.Text
If there are many text box you should make a loop.
"YourTextboxID" is the ID you assigned to text box.
To succeed, we must first believe that we can.
Sherin Iranimose
|
|
|
|
|
ya that only me to finding here,
For Each SubGRD As PlaceHolder In plhbookfields.Controls
Dim t1 As TextBox = CType(SubGRD.FindControl("txttextbox"), TextBox)
next
ya i given like this but i am not getting properly...,
Magi
|
|
|
|
|
Hi,
Here txttextbox is not the id of text box.
txttextbox.ID = "txtproduct" & strfieldnum
You used the above code in your program to generate id.
So use the same mechanism to get id and fin the control.
To succeed, we must first believe that we can.
Sherin Iranimose
|
|
|
|
|
Then whats the id of the textbox??
Magi
|
|
|
|
|
When page is posting I think you can get that on posted values. Means using request.form["TextBoxId"]
|
|
|
|
|
No i didnt get what ur trying to say?,
Plz hlp me...,
Magi
|
|
|
|
|
On page load try writing
Response.Write(Request.Form["YourTextBoxId"]))
If that is not working then try replacing textbox id to name
Last modified: 5mins after originally posted --
|
|
|
|
|
Hi i think u didnt get my probs clearly,
If i know the textbox id probs will be solve...,
See my code in previous msg,in place holder i create textbox at runtime...,
So we want to find first textbox id,
then if more than one textbox will be create in place holder we want to find each and every textbox id...,
Then with that id we can get the values from that textbox...,
So then its not big matter at all to store the database...,
Magi
|
|
|
|
|
Magh_M wrote: If i know the textbox id probs will be solve...,
See my code in previous msg,in place holder i create textbox at runtime...,
So we want to find first textbox id,
I think you know it.
Read your first post. In that you are creating textbox id
|
|
|
|
|
ya i am creating the textbox id...,
But i dont know how to get it..,
Becoz its in placeholder...,
And more than one textbox will be there how u can get each and every textbox id and those values?,
Magi
|
|
|
|