Saturday, March 31, 2012
Submitting form from the Server Control
the form data exists in the Request.Form collection. how do you mavigate
from Page1 to Page2?
if you use server.transfer make sure the the secound parameter set to
true otherwise the Form wont redirect to Page2.
Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Hi,
Thanks for the info. I was using Response.Redirect to redirect to the next
page. Because of that I was not getting the submitted value.
Regards
Pradeep
"Natty Gur" <natty@.dao2com.com> wrote in message
news:uBoQVf7ZDHA.1744@.TK2MSFTNGP12.phx.gbl...
> Hi,
> the form data exists in the Request.Form collection. how do you mavigate
> from Page1 to Page2?
> if you use server.transfer make sure the the secound parameter set to
> true otherwise the Form wont redirect to Page2.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Hi,
One more thing. When i use Server.Transfer, the URL of the IE doesn't get
updated with the current form. Also it always displays the URL of the last
Form.
Any idea ?
Pradeep
"Natty Gur" <natty@.dao2com.com> wrote in message
news:uBoQVf7ZDHA.1744@.TK2MSFTNGP12.phx.gbl...
> Hi,
> the form data exists in the Request.Form collection. how do you mavigate
> from Page1 to Page2?
> if you use server.transfer make sure the the secound parameter set to
> true otherwise the Form wont redirect to Page2.
> Natty Gur, CTO
> Dao2Com Ltd.
> 34th Elkalay st. Raanana
> Israel , 43000
> Phone Numbers:
> Office: +972-(0)9-7740261
> Fax: +972-(0)9-7740261
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Submitting form from the Server Control
How can I submit the whole form data when I click on the "ASP Server
Button". I want to use the Posted data in the redirect form.
Regards
PradeepHi,
What "whole form data means. Every form submits already sending all
the Input values to the server by default. If you want the entire HTML
add invisible Input box and put the body innerhtml in that input box
before submitting.
Natty Gur, CTO
Dao2Com Ltd.
34th Elkalay st. Raanana
Israel , 43000
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Submitting form with multiple onclick events
I'm building a custom control which basically takes data from the user
and then submits it. I would use the validator controls but if I
understand correctly (I've been working with .Net for 2 weeks) you
cant 'embed' them in the custom controls. Someone correct me if I'm
wrong (and please point to an example :) )
So, to get around this, I'm using Javascript. In my control, I'm doing
Writer.WriteAttribute("OnClick", "javascript:checkData();" &
Page.GetPostBackEventReference(Me, "Data"))
for an Input item so I get something like
<input type="button" value="Submit"
OnClick="javascript:checkData();__doPostBack('MyControl','D ata')" /
The checkData() function does this:
function checkLogin()
{
if (document.Data.item1.value == "" )
{
alert("Please enter item 1.");
return false;
}
if (document.Data.item2.value == "" )
{
alert("Please enter item 2.");
return false;
}
if (document.Data.item1.value != "" && document.Data.item2.value !=
"" )
{
return true;
}
}
My query is, how do I get the click event to fire correctly so that i
get alerts when there is a problem, and it passes through and submits
the form if there isnt a problem?
Thanks
SamHi,
Your client side script should use cancelBubble and returnValue to
disable event default process and raise alert if error found.
function CallServer()
{
if validate
{
__doPostBack('MyControl','Data');
}
else
{
alert("Error");
window.event.cancelBubble = true;
window.event.returnValue = false;
}
}
HTH
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Natty Gur <natty@.dao2com.com> wrote in message news:<uSSwHLhAEHA.3348@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> Your client side script should use cancelBubble and returnValue to
> disable event default process and raise alert if error found.
> function CallServer()
> {
> if validate
> {
> __doPostBack('MyControl','Data');
> }
> else
> {
> alert("Error");
> window.event.cancelBubble = true;
> window.event.returnValue = false;
> }
> }
>
> HTH
> Natty Gur[MVP]
> blog : http://weblogs.asp.net/ngur
> Mobile: +972-(0)58-888377
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Thanks Natty
This means I have to create inline javascripts which I'd rather not do
if I can help it. Just as luck would have it, after spending an 'hour
or two' trying to find a solution before posting, 5 mins after posting
I find a solution :( Always the way...
Anyhow, just for reference purposes, what I've done is to validate on
OnMouseDown and postback on OnClick. Works a treat
Hi Samuel,
Its unfortunate that you had to rework validation because of some incorrect
information about validators. The ASP.NET validators work fine within custom
controls. They have one key limitation related to their "location": the
ControlToValidate must be associated with the ID of a control in the same
"naming container". If your custom control impliments INamingContainer,
ControlToValidate can only point to other controls within your custom
control. If not, it can refer to other controls in the same naming container
that your custom control appears. Some types of naming containers: Page,
UserControl, and rows in DataGrid and DataList.
If you wanted to support validation without naming container limits, I wrote
a replacement to Microsoft's validators that overcomes that limitation among
numerous others: Professional Validation And More.
http://www.peterblum.com/vam/home.aspx.
-- Peter Blum
www.PeterBlum.com
Email: PLBlum@.PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Samuel Hon" <noreply@.samuelhon.co.uk> wrote in message
news:c8672b7d.0403040703.c458604@.posting.google.co m...
> Hi
> I'm building a custom control which basically takes data from the user
> and then submits it. I would use the validator controls but if I
> understand correctly (I've been working with .Net for 2 weeks) you
> cant 'embed' them in the custom controls. Someone correct me if I'm
> wrong (and please point to an example :) )
> So, to get around this, I'm using Javascript. In my control, I'm doing
> Writer.WriteAttribute("OnClick", "javascript:checkData();" &
> Page.GetPostBackEventReference(Me, "Data"))
> for an Input item so I get something like
> <input type="button" value="Submit"
> OnClick="javascript:checkData();__doPostBack('MyControl','D ata')" />
> The checkData() function does this:
> function checkLogin()
> {
> if (document.Data.item1.value == "" )
> {
> alert("Please enter item 1.");
> return false;
> }
> if (document.Data.item2.value == "" )
> {
> alert("Please enter item 2.");
> return false;
> }
> if (document.Data.item1.value != "" && document.Data.item2.value !=
> "" )
> {
> return true;
> }
> }
> My query is, how do I get the click event to fire correctly so that i
> get alerts when there is a problem, and it passes through and submits
> the form if there isnt a problem?
> Thanks
> Sam
"Peter Blum" <PLBlum@.Blum.info> wrote in message news:<OC#ZP$uAEHA.624@.TK2MSFTNGP10.phx.gbl>...
> Hi Samuel,
> Its unfortunate that you had to rework validation because of some incorrect
> information about validators. The ASP.NET validators work fine within custom
> controls. They have one key limitation related to their "location": the
> ControlToValidate must be associated with the ID of a control in the same
> "naming container". If your custom control impliments INamingContainer,
> ControlToValidate can only point to other controls within your custom
> control. If not, it can refer to other controls in the same naming container
> that your custom control appears. Some types of naming containers: Page,
> UserControl, and rows in DataGrid and DataList.
> If you wanted to support validation without naming container limits, I wrote
> a replacement to Microsoft's validators that overcomes that limitation among
> numerous others: Professional Validation And More.
> http://www.peterblum.com/vam/home.aspx.
> -- Peter Blum
> www.PeterBlum.com
> Email: PLBlum@.PeterBlum.com
> Creator of "Professional Validation And More" at
> http://www.peterblum.com/vam/home.aspx
<snip
Thanks Peter for clearing that up, I will re-investigate
Sam
Submitting Using Javascript
My question is related to making a form submit using javascript. Here is my
scenario. I have a form, which includes a user control. The user control
has a search button and a submit button. I have visably hidden th search
button by setting its appearance and added an HTML button which calls the
click event of my real server control button.
This works fine.
I now want to cause the click event of the search button to be called when
the user hits the enter key in the text search text box. I have done this by
using the OnKeyDown event of the body tag and check if the character is the
enter key. This does invoke the function and I can do an alert('hello
world'); to prove it is working.
However . . . . . . .
If I try and call the real search button click() from this event nothing
happens.
Does anyone have insight into what I am doing wrong or how I can resolve it.
Many ThanksThis is probably a bug but for some reason asp.net doesn't sent the form
post variables to the web server if one textbox is on the page. So, calling
the button click() would actually post the form; but asp.net would not run
any server side processing since it has no clue on what control caused the
postback. There is a way around this. You can drop an extra textbox on the
page and hide it with css. If 2 textboxes are on the page then all the form
post variables will be sent along with the page and calling the click() on
the button would actually run the server side code. To hide the textbox you
can do something like this:
<asp:TextBox runat="server" style="display:hidden;visibility:none;" />
I hope this works.
"Goofy" <me@.mine.comwrote in message
news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
Hi everyone,
>
My question is related to making a form submit using javascript. Here is
my scenario. I have a form, which includes a user control. The user
control has a search button and a submit button. I have visably hidden th
search button by setting its appearance and added an HTML button which
calls the click event of my real server control button.
>
This works fine.
>
I now want to cause the click event of the search button to be called when
the user hits the enter key in the text search text box. I have done this
by using the OnKeyDown event of the body tag and check if the character is
the enter key. This does invoke the function and I can do an alert('hello
world'); to prove it is working.
>
However . . . . . . .
>
If I try and call the real search button click() from this event nothing
happens.
>
Does anyone have insight into what I am doing wrong or how I can resolve
it.
>
Many Thanks
>
>
>
>
>
Having made this change, when the enter key is pressed the form is
submitted, but I dont want a default submission, I need it to be the
btnSearch
function OKD(){ if (window.event.keyCode == 13 )
{
MultiProjectPicker1_btnSearch.click();
event.returnValue=false;
event.cancel = true; }
}
"tdavisjr" <tdavisjr@.gmail.comwrote in message
news:%23PRIIZt7GHA.4408@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
This is probably a bug but for some reason asp.net doesn't sent the form
post variables to the web server if one textbox is on the page. So,
calling the button click() would actually post the form; but asp.net would
not run any server side processing since it has no clue on what control
caused the postback. There is a way around this. You can drop an extra
textbox on the page and hide it with css. If 2 textboxes are on the page
then all the form post variables will be sent along with the page and
calling the click() on the button would actually run the server side code.
To hide the textbox you can do something like this:
>
<asp:TextBox runat="server" style="display:hidden;visibility:none;" />
>
I hope this works.
>
"Goofy" <me@.mine.comwrote in message
news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
>Hi everyone,
>>
>My question is related to making a form submit using javascript. Here is
>my scenario. I have a form, which includes a user control. The user
>control has a search button and a submit button. I have visably hidden th
>search button by setting its appearance and added an HTML button which
>calls the click event of my real server control button.
>>
>This works fine.
>>
>I now want to cause the click event of the search button to be called
>when the user hits the enter key in the text search text box. I have done
>this by using the OnKeyDown event of the body tag and check if the
>character is the enter key. This does invoke the function and I can do an
>alert('hello world'); to prove it is working.
>>
>However . . . . . . .
>>
>If I try and call the real search button click() from this event nothing
>happens.
>>
>Does anyone have insight into what I am doing wrong or how I can resolve
>it.
>>
>Many Thanks
>>
>>
>>
>>
>>
there are several possible problems.
1) you specified invisible for the button. this will cause the button to not
render, so there is nothing for javascript to call.
2) you are not using validation, so the button is a standard submit button.
in this case there is not a onclick routine to call.
a simple solution for what you want is to use onchange on the textbx and set
autopostback. then asp.net will generate javascript to postback.
-- bruce (sqlwork.com)
"Goofy" <me@.mine.comwrote in message
news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
Hi everyone,
>
My question is related to making a form submit using javascript. Here is
my scenario. I have a form, which includes a user control. The user
control has a search button and a submit button. I have visably hidden th
search button by setting its appearance and added an HTML button which
calls the click event of my real server control button.
>
This works fine.
>
I now want to cause the click event of the search button to be called when
the user hits the enter key in the text search text box. I have done this
by using the OnKeyDown event of the body tag and check if the character is
the enter key. This does invoke the function and I can do an alert('hello
world'); to prove it is working.
>
However . . . . . . .
>
If I try and call the real search button click() from this event nothing
happens.
>
Does anyone have insight into what I am doing wrong or how I can resolve
it.
>
Many Thanks
>
>
>
>
>
Excellent
Just goes to show, the simple solution is easy once you know it. I never
thought to use AP on this, what a dummy I am.
Cheers
"bruce barker (sqlwork.com)" <b_r_u_c_e_removeunderscores@.sqlwork.comwrote
in message news:ukVX54t7GHA.2384@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
there are several possible problems.
>
1) you specified invisible for the button. this will cause the button to
not render, so there is nothing for javascript to call.
>
2) you are not using validation, so the button is a standard submit
button. in this case there is not a onclick routine to call.
>
a simple solution for what you want is to use onchange on the textbx and
set autopostback. then asp.net will generate javascript to postback.
>
>
-- bruce (sqlwork.com)
>
>
>
>
"Goofy" <me@.mine.comwrote in message
news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
Quote:
Originally Posted by
>Hi everyone,
>>
>My question is related to making a form submit using javascript. Here is
>my scenario. I have a form, which includes a user control. The user
>control has a search button and a submit button. I have visably hidden th
>search button by setting its appearance and added an HTML button which
>calls the click event of my real server control button.
>>
>This works fine.
>>
>I now want to cause the click event of the search button to be called
>when the user hits the enter key in the text search text box. I have done
>this by using the OnKeyDown event of the body tag and check if the
>character is the enter key. This does invoke the function and I can do an
>alert('hello world'); to prove it is working.
>>
>However . . . . . . .
>>
>If I try and call the real search button click() from this event nothing
>happens.
>>
>Does anyone have insight into what I am doing wrong or how I can resolve
>it.
>>
>Many Thanks
>>
>>
>>
>>
>>
>
>
Submitting Using Javascript
My question is related to making a form submit using javascript. Here is my
scenario. I have a form, which includes a user control. The user control
has a search button and a submit button. I have visably hidden th search
button by setting its appearance and added an HTML button which calls the
click event of my real server control button.
This works fine.
I now want to cause the click event of the search button to be called when
the user hits the enter key in the text search text box. I have done this by
using the OnKeyDown event of the body tag and check if the character is the
enter key. This does invoke the function and I can do an alert('hello
world'); to prove it is working.
However . . . . . . .
If I try and call the real search button click() from this event nothing
happens.
Does anyone have insight into what I am doing wrong or how I can resolve it.
Many ThanksThis is probably a bug but for some reason asp.net doesn't sent the form
post variables to the web server if one textbox is on the page. So, calling
the button click() would actually post the form; but asp.net would not run
any server side processing since it has no clue on what control caused the
postback. There is a way around this. You can drop an extra textbox on the
page and hide it with css. If 2 textboxes are on the page then all the form
post variables will be sent along with the page and calling the click() on
the button would actually run the server side code. To hide the textbox you
can do something like this:
<asp:TextBox runat="server" style="display:hidden;visibility:none;" />
I hope this works.
"Goofy" <me@.mine.com> wrote in message
news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
> Hi everyone,
> My question is related to making a form submit using javascript. Here is
> my scenario. I have a form, which includes a user control. The user
> control has a search button and a submit button. I have visably hidden th
> search button by setting its appearance and added an HTML button which
> calls the click event of my real server control button.
> This works fine.
> I now want to cause the click event of the search button to be called when
> the user hits the enter key in the text search text box. I have done this
> by using the OnKeyDown event of the body tag and check if the character is
> the enter key. This does invoke the function and I can do an alert('hello
> world'); to prove it is working.
> However . . . . . . .
> If I try and call the real search button click() from this event nothing
> happens.
> Does anyone have insight into what I am doing wrong or how I can resolve
> it.
> Many Thanks
>
>
>
Having made this change, when the enter key is pressed the form is
submitted, but I dont want a default submission, I need it to be the
btnSearch
function OKD(){ if (window.event.keyCode == 13 )
{
MultiProjectPicker1_btnSearch.click();
event.returnValue=false;
event.cancel = true; }
}
"tdavisjr" <tdavisjr@.gmail.com> wrote in message
news:%23PRIIZt7GHA.4408@.TK2MSFTNGP02.phx.gbl...
> This is probably a bug but for some reason asp.net doesn't sent the form
> post variables to the web server if one textbox is on the page. So,
> calling the button click() would actually post the form; but asp.net would
> not run any server side processing since it has no clue on what control
> caused the postback. There is a way around this. You can drop an extra
> textbox on the page and hide it with css. If 2 textboxes are on the page
> then all the form post variables will be sent along with the page and
> calling the click() on the button would actually run the server side code.
> To hide the textbox you can do something like this:
> <asp:TextBox runat="server" style="display:hidden;visibility:none;" />
> I hope this works.
> "Goofy" <me@.mine.com> wrote in message
> news:eNZ#6Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
there are several possible problems.
1) you specified invisible for the button. this will cause the button to not
render, so there is nothing for javascript to call.
2) you are not using validation, so the button is a standard submit button.
in this case there is not a onclick routine to call.
a simple solution for what you want is to use onchange on the textbx and set
autopostback. then asp.net will generate javascript to postback.
-- bruce (sqlwork.com)
"Goofy" <me@.mine.com> wrote in message
news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
> Hi everyone,
> My question is related to making a form submit using javascript. Here is
> my scenario. I have a form, which includes a user control. The user
> control has a search button and a submit button. I have visably hidden th
> search button by setting its appearance and added an HTML button which
> calls the click event of my real server control button.
> This works fine.
> I now want to cause the click event of the search button to be called when
> the user hits the enter key in the text search text box. I have done this
> by using the OnKeyDown event of the body tag and check if the character is
> the enter key. This does invoke the function and I can do an alert('hello
> world'); to prove it is working.
> However . . . . . . .
> If I try and call the real search button click() from this event nothing
> happens.
> Does anyone have insight into what I am doing wrong or how I can resolve
> it.
> Many Thanks
>
>
>
Excellent
Just goes to show, the simple solution is easy once you know it. I never
thought to use AP on this, what a dummy I am.
Cheers
"bruce barker (sqlwork.com)" <b_r_u_c_e_removeunderscores@.sqlwork.com> wrote
in message news:ukVX54t7GHA.2384@.TK2MSFTNGP04.phx.gbl...
> there are several possible problems.
> 1) you specified invisible for the button. this will cause the button to
> not render, so there is nothing for javascript to call.
> 2) you are not using validation, so the button is a standard submit
> button. in this case there is not a onclick routine to call.
> a simple solution for what you want is to use onchange on the textbx and
> set autopostback. then asp.net will generate javascript to postback.
>
> -- bruce (sqlwork.com)
>
>
> "Goofy" <me@.mine.com> wrote in message
> news:eNZ%236Jt7GHA.4288@.TK2MSFTNGP02.phx.gbl...
>
Subroutine /helper function error
would be displayed inside a datalist control's <itemtemplate> )
<script language="VB" runat="server">
Public Sub checkforimg(ByVal Imagesubprod1 As String)
If Imagesubprod1 <> "" then
response.write(Imagesubprod1)
Else
response.write("nbsp;")
End If
End Sub
</script>
... but I get an "Overload resolution failed because no accessible
'ToString' can be called with these arguments:" error when it comes
time to check for the image as follows.
<%# checkforimg(DataBinder.Eval(Container.DataItem,
"Imagesubprod1"))%>
When I form the header for the sub as follows:
Public Sub checkforimg(ByVal Imagesubprod1 As String) As string
..i get an "Expected end of statement " error on this lineOn 10 Jun 2004 11:55:42 -0700, Chumley the Walrus <springb2k@.yahoo.com>
wrote:
> I'm using a subroutine/helper function display an image (the image
> would be displayed inside a datalist control's <itemtemplate> )
> <script language="VB" runat="server">
> Public Sub checkforimg(ByVal Imagesubprod1 As String)
> If Imagesubprod1 <> "" then
> response.write(Imagesubprod1)
> Else
> response.write("nbsp;")
> End If
> End Sub
> </script>
> ... but I get an "Overload resolution failed because no accessible
> 'ToString' can be called with these arguments:" error when it comes
> time to check for the image as follows.
> <%# checkforimg(DataBinder.Eval(Container.DataItem,
> "Imagesubprod1"))%>
looks like it's having trouble converting the value you're passing in thru
databinding to a String. If you have Option Strict on, you might try
either casting the value in the databinding statement to a string before
passing it in, or change the parameter in your method above to an Object
and then cast it inside the function itself.
Otherwise verify the value in your datasource is truly capable of being a
string.
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
IE does not support inline images, so you code should be writing something
like: <img src=url> not the binary image.
-- bruce (sqlwork.com)
"Chumley the Walrus" <springb2k@.yahoo.com> wrote in message
news:1ef65641.0406101055.8852102@.posting.google.com...
> I'm using a subroutine/helper function display an image (the image
> would be displayed inside a datalist control's <itemtemplate> )
> <script language="VB" runat="server">
> Public Sub checkforimg(ByVal Imagesubprod1 As String)
> If Imagesubprod1 <> "" then
> response.write(Imagesubprod1)
> Else
> response.write("nbsp;")
> End If
> End Sub
> </script>
> ... but I get an "Overload resolution failed because no accessible
> 'ToString' can be called with these arguments:" error when it comes
> time to check for the image as follows.
> <%# checkforimg(DataBinder.Eval(Container.DataItem,
> "Imagesubprod1"))%>
> When I form the header for the sub as follows:
> Public Sub checkforimg(ByVal Imagesubprod1 As String) As string
> ..i get an "Expected end of statement " error on this line
Subscribing to event from Template Column
datagrid. The control (myControl) raises an event.
I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.
How can I subscribe to the event?
Thanks,
THi Tina,
If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the ascx
codebehind file.
Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in this
example: http://www.societopia.net/Samples/D...tDelegates.aspx
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
> I have an ascx control in the ItemTemplate of a Template Column in a
> datagrid. The control (myControl) raises an event.
> I'm trying to figure out how I can subscribe to the event. It can't be done
> at design time because myControl is not one of the recognized controls. At
> run time I would expect to use AddHandler but I can't seem to reference
> myControl.
> How can I subscribe to the event?
> Thanks,
> T
>
I guess I'm going to have to learn c# if for nothing other than to follow
the examples...
in VB to handle an event we ....
AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
..
..
Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
.. code to handle event is here...
end sub
How would the AddHandler code look in the case where myControl is in
DataGrid1?
"Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> Hi Tina,
> If your control is simply a composite control that is placed declaratively
> on the page at design time then you can add the event handler within the
> ascx
> codebehind file.
> Alternatively, you can use event delegates to expose events out of your
> ascx
> to its NamingContainer (in your case it is the DataGridItem) as I did in
> this
> example: http://www.societopia.net/Samples/D...tDelegates.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
> "Tina" wrote:
>> I have an ascx control in the ItemTemplate of a Template Column in a
>> datagrid. The control (myControl) raises an event.
>>
>> I'm trying to figure out how I can subscribe to the event. It can't be
>> done
>> at design time because myControl is not one of the recognized controls.
>> At
>> run time I would expect to use AddHandler but I can't seem to reference
>> myControl.
>>
>> How can I subscribe to the event?
>>
>> Thanks,
>> T
>>
>>
>
Hi Tina,
For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing that
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)
I created here
http://www.societopia.net/Samples/D...rolsEvents.aspx a sample
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
"OnCustomEvent1". I then included that control in a TemplateColumn on the
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
> I guess I'm going to have to learn c# if for nothing other than to follow
> the examples...
> in VB to handle an event we ....
> AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
> ..
> ..
> Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
> .. code to handle event is here...
> end sub
> How would the AddHandler code look in the case where myControl is in
> DataGrid1?
> "Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
> news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> > Hi Tina,
> > If your control is simply a composite control that is placed declaratively
> > on the page at design time then you can add the event handler within the
> > ascx
> > codebehind file.
> > Alternatively, you can use event delegates to expose events out of your
> > ascx
> > to its NamingContainer (in your case it is the DataGridItem) as I did in
> > this
> > example: http://www.societopia.net/Samples/D...tDelegates.aspx
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> > "Tina" wrote:
> >> I have an ascx control in the ItemTemplate of a Template Column in a
> >> datagrid. The control (myControl) raises an event.
> >>
> >> I'm trying to figure out how I can subscribe to the event. It can't be
> >> done
> >> at design time because myControl is not one of the recognized controls.
> >> At
> >> run time I would expect to use AddHandler but I can't seem to reference
> >> myControl.
> >>
> >> How can I subscribe to the event?
> >>
> >> Thanks,
> >> T
> >>
> >>
> >>
>
Subscribing to event from Template Column
datagrid. The control (myControl) raises an event.
I'm trying to figure out how I can subscribe to the event. It can't be done
at design time because myControl is not one of the recognized controls. At
run time I would expect to use AddHandler but I can't seem to reference
myControl.
How can I subscribe to the event?
Thanks,
THi Tina,
If your control is simply a composite control that is placed declaratively
on the page at design time then you can add the event handler within the asc
x
codebehind file.
Alternatively, you can use event delegates to expose events out of your ascx
to its NamingContainer (in your case it is the DataGridItem) as I did in thi
s
example: http://www.societopia.net/Samples/D...tDelegates.aspx
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
> I have an ascx control in the ItemTemplate of a Template Column in a
> datagrid. The control (myControl) raises an event.
> I'm trying to figure out how I can subscribe to the event. It can't be do
ne
> at design time because myControl is not one of the recognized controls. A
t
> run time I would expect to use AddHandler but I can't seem to reference
> myControl.
> How can I subscribe to the event?
> Thanks,
> T
>
>
I guess I'm going to have to learn c# if for nothing other than to follow
the examples...
in VB to handle an event we ....
AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
.
.
Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
. code to handle event is here...
end sub
How would the AddHandler code look in the case where myControl is in
DataGrid1?
"Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
> Hi Tina,
> If your control is simply a composite control that is placed declaratively
> on the page at design time then you can add the event handler within the
> ascx
> codebehind file.
> Alternatively, you can use event delegates to expose events out of your
> ascx
> to its NamingContainer (in your case it is the DataGridItem) as I did in
> this
> example: http://www.societopia.net/Samples/D...tDelegates.aspx
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
> "Tina" wrote:
>
Hi Tina,
For you to be able to handle an event (e.g. TimerEvent) raised by your
control it has to define a delegate method that you can use when placing tha
t
control in the DataGrid. If it does that then you can handle that event by
specifying a function for the delegate method (e.g. if your event is named
TimerEvent, you should design your control to expose a method named
OnTimerEvent)
I created here
http://www.societopia.net/Samples/D...rolsEvents.aspx a sampl
e
in VB.Net where I designed a user control (in an ascx file) that raises an
event (I called it CustomEvent1) by exposing a delegate method called
“OnCustomEvent1”. I then included that control in a TemplateColumn on t
he
DataGrid and wired the delegate function named OnCustomEvents to an event
handler within the page class codebehind.
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Tina" wrote:
> I guess I'm going to have to learn c# if for nothing other than to follow
> the examples...
> in VB to handle an event we ....
> AddHandler myControl.TimerEvent, AddressOf me.HandleTimerEvent
> ..
> ..
> Protected Sub HandleTimerEvent(byval o as Object, byval e as TimerArgs)
> .. code to handle event is here...
> end sub
> How would the AddHandler code look in the case where myControl is in
> DataGrid1?
> "Phillip Williams" <Phillip.Williams@.webswapp.com> wrote in message
> news:0EF5A6EE-2CBF-4FDE-9B9F-148297D8E8CA@.microsoft.com...
>
>
Substitue ItemArray with something else in a FormView
this code:
Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
EventArgs)
If FormView1.Row.RowState = DataControlRowState.Edit Then
Dim rowView As DataRowView = TryCast(FormView1.DataItem,
DataRowView)
If Not rowView Is Nothing Then
'Get and fill cboProject
Dim strProjectID As String =
TryCast(rowView.Row.ItemArray(8), String)
Dim cboProject As WebCombo =
TryCast(FormView1.FindControl("cboProject"), WebCombo)
cboProject.Value = strProjectID
End If
End If
End Sub
It works great except that I would like to change
"TryCast(rowView.Row.ItemArray(8), String)" and use the column name
instead of ItemArray(8). I have many columns in the FormView so it's
very difficult for me to guess which number represents a certain
column.
How can this be done?
I'm very grateful for help!
// SHi there,
First of all it's better to move databound-releated code to DataBound event
handler. Second you can access column by names directly from DataRowView:
protected Sub FormView1_DataBound( _
ByVal sender As Object, _
ByVal e As EventArgs)
dim formView as FormView = DirectCast(sender, FormView)
if formView.CurrentMode = FormViewMode.Edit then
Dim rowView As DataRowView = TryCast( _
formView.DataItem, DataRowView)
Dim cboProject as WebCombo = TryCast( _
formView.FindControl("cboProject"), WebControl)
cboProject.Value = Convert.ToString(rowView("ColumnName"))
end if
end sub
Hope this helps
--
Milosz
"staeri@.gmail.com" wrote:
> When loading a FormView I try to fill a third-party combo control with
> this code:
> Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
> EventArgs)
> If FormView1.Row.RowState = DataControlRowState.Edit Then
> Dim rowView As DataRowView = TryCast(FormView1.DataItem,
> DataRowView)
> If Not rowView Is Nothing Then
> 'Get and fill cboProject
> Dim strProjectID As String =
> TryCast(rowView.Row.ItemArray(8), String)
> Dim cboProject As WebCombo =
> TryCast(FormView1.FindControl("cboProject"), WebCombo)
> cboProject.Value = strProjectID
> End If
> End If
> End Sub
> It works great except that I would like to change
> "TryCast(rowView.Row.ItemArray(8), String)" and use the column name
> instead of ItemArray(8). I have many columns in the FormView so it's
> very difficult for me to guess which number represents a certain
> column.
> How can this be done?
> I'm very grateful for help!
> // S
>
Monday, March 26, 2012
Suggestion for next release of 2.0 - ValidationSummary Control
I have a feature request for 2.x or 3.x. How about we have the option
to let the ValidationSummary display messages from all validators on
the page? For instance, maybe we can have an additional property
"DisplayAllValidators."
Or maybe you can just modify the ValidationGroup property on the
summary control to work like this:
1. Undefined - Summarize all undefined Validators ignoring those with a
defined group
2. Defined - Summarize only the specified group's validators
3. All - Summarize every validator on the page (including those in user
controls)
That would be nice!
Forcing us to place multiple summary controls for each group on a page
is pretty lame. Allowing us the ability is nice...you could also just allow us to enter comma delimited Groups. I still
like my first suggestion better but at least that would solve my
problem.
re:
Quote:
Originally Posted by
I have a feature request for 2.x or 3.x.
Please submit that request at the Visual Studio
and .NET Framework Feedback page :
http://connect.microsoft.com/feedba...aspx?SiteID=210
Click on the "Submit Feedback" link and make sure you have a Microsoft Passport
handy so you can login, which is required in order to be able to submit requests and bugs.
If you don't have a Passport, get a free one here :
https://accountservices.passport.ne...?vv=410&lc=1033
Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espaol : http://asp.net.do/foros/
===================================
"r2thej151" <csharpdesign@.gmail.comwrote in message
news:1155851585.512982.134980@.i3g2000cwc.googlegro ups.com...
Quote:
Originally Posted by
Hi Guys,
>
I have a feature request for 2.x or 3.x. How about we have the option
to let the ValidationSummary display messages from all validators on
the page? For instance, maybe we can have an additional property
"DisplayAllValidators."
>
Or maybe you can just modify the ValidationGroup property on the
summary control to work like this:
1. Undefined - Summarize all undefined Validators ignoring those with a
defined group
2. Defined - Summarize only the specified group's validators
3. All - Summarize every validator on the page (including those in user
controls)
>
That would be nice!
>
Forcing us to place multiple summary controls for each group on a page
is pretty lame. Allowing us the ability is nice...
>
thanks for the link. it is already filed and open.
Suggestions for ASP.NET Data Repeater
The salient fields in the Establishments table in relation to the image are:
ID, Name, Area
The ID is just the ID for each establishment, the name is the name (e.g. "Arklow Bay Confer...", "Glenart Castle Hotel", "Ballyknocked Coun..." etc. etc."), and the Area (e.g. Arklow, Ashford, Aughrim, Blessington).
Any thoughts on how I could design my Repeater or Grid etc to display everything, but to group by the Area field as in the image?This is coming from a database, correct? And you have control over the recordset that is returned?
Absolute and complete control yes
Have two datatables filled up in your dataset.
First:
EstablishmentID+LongName
Second:
EstablishmentID+Area
You can then add a relationship between them, and bind it to the repeater. Styling it as you wish of course.
Here's an example:
http://support.microsoft.com/default.aspx?scid=kb;en-us;326338
Cool thanks I'll have a look at that!
Post your code when it works. It's helpful for searches. :)
Didn't take too much tinkering to get it working. I'll post a fuller example in a little while...
<asp:Repeater id="parentRepeater" runat="server">
<itemtemplate>
<b>
<%#DataBinder.Eval(Container.DataItem, "[Area Name]")%>
</b>
<br>
<asp:Repeater id="childRepeater" runat="server" datasource='<%#Container.DataItem.Row.GetChildRows("myrelation")%>'>
<itemtemplate>
<%#Container.DataItem("Name")%><br>
</itemtemplate>
</asp:Repeater>
</itemtemplate>
</asp:Repeater>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cnn As SqlConnection = New SqlConnection("Data Source=localhost;Initial Catalog=SomeDB;Integrated Security=True;Pooling=False")
Dim cmd1 As SqlDataAdapter = New SqlDataAdapter("select * from areas", cnn)
Dim ds As DataSet = New DataSet()
cmd1.Fill(ds, "areas")
Dim cmd2 As SqlDataAdapter = New SqlDataAdapter("select * from establishments", cnn)
cmd2.Fill(ds, "establishments")
ds.Relations.Add("myrelation", ds.Tables("areas").Columns(0), ds.Tables("establishments").Columns(14))
parentRepeater.DataSource = ds.Tables("areas")
Page.DataBind()
cnn.Close()
End Sub
Saturday, March 24, 2012
suggestions?
to fill one of the control when there is some action like selecting
something from its previous control...I want to simulate as if its a windows
based application and the entire page is not refereshed (trip to
server)...other controls are not involved for this task...how can I
smoothly refresh these contols...I was reading about VIEWSTATE, is that the
solution to my problem...
ThanksYou'd use client side javascript for this. Search on dropdown list
and dependent in google for examples.
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx
"abcd" <abcd@.abcd.com> wrote in message
news:elV6cUQTFHA.3620@.TK2MSFTNGP09.phx.gbl...
>I want to design an asp.net page which will have multiple controls. I want
>to fill one of the control when there is some action like selecting
>something from its previous control...I want to simulate as if its a
>windows based application and the entire page is not refereshed (trip to
>server)...other controls are not involved for this task...how can I
>smoothly refresh these contols...I was reading about VIEWSTATE, is that the
>solution to my problem...
> Thanks
>
suggestions?
to fill one of the control when there is some action like selecting
something from its previous control...I want to simulate as if its a windows
based application and the entire page is not refereshed (trip to
server)...other controls are not involved for this task...how can I
smoothly refresh these contols...I was reading about VIEWSTATE, is that the
solution to my problem...
ThanksYou'd use client side javascript for this. Search on dropdown list
and dependent in google for examples.
--
2005 Microsoft MVP C#
Robbe Morris
http://www.robbemorris.com
http://www.masterado.net/home/listings.aspx
"abcd" <abcd@.abcd.com> wrote in message
news:elV6cUQTFHA.3620@.TK2MSFTNGP09.phx.gbl...
>I want to design an asp.net page which will have multiple controls. I want
>to fill one of the control when there is some action like selecting
>something from its previous control...I want to simulate as if its a
>windows based application and the entire page is not refereshed (trip to
>server)...other controls are not involved for this task...how can I
>smoothly refresh these contols...I was reading about VIEWSTATE, is that the
>solution to my problem...
> Thanks
Sum of XML data
Dim dstTS As DataSet
dstTS = New DataSet()
dstTS.ReadXml( MapPath( "cw052004.xml" ) )rptTS.DataSource = dstTS
rptTS.DataBind()
It works fine. However, I would also like to calculate the sum of a the "item_cost" from each node in the XML file and place it in a variable.
Can anybody suggest the best way to go about this?do some searching for examples on the itemdatabound event. this is fired everytime an item is bound and you can use this to sum up your grids and such.
Awesome, thanks!
Thursday, March 22, 2012
Suppress Form Action
Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("location.href = window.location.href +
'?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
using the above custom control in an ASPX page (assume that the ASPX
page is named Confirm.aspx):
<%@dotnet.itags.org. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>
<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
Text="EXIT" runat="server"/>
</form>
Note the
Output.Write("location.href = window.location.href + '?Proceed=' +
answer")
line in the VB class file code. When the ASPX page gets rendered, it
displays a Button. Conventionally, when a Button is clicked in an ASPX
page, it posts back to itself using the POST method. When the Button in
the above custom control is clicked, a JavaScript confirm dialog
pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
the value of the variable 'answer' is false.
What I want is irrespective of whether a user clicks the 'OK' or
'Cancel' button in the confirm dialog, instead of posting back to
itself using the conventional POST method, I want the ASPX page to post
to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
to suppress the conventional post & instead add the querystring so that
I can find out whether the user has clicked the 'OK' button or the
'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
be taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
If the user clicks 'Cancel' in the confirm dialog, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=false
Can this be done in anyway?Anyone?
rn5a@.rediffmail.com wrote:
Quote:
Originally Posted by
A custom server control has a Button.
>
Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property
>
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClic k,
"ConfirmMsg()")
End Sub
>
Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)
>
Output.Write("location.href = window.location.href +
'?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
>
Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
using the above custom control in an ASPX page (assume that the ASPX
page is named Confirm.aspx):
>
<%@. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>
>
<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
Text="EXIT" runat="server"/>
</form>
>
Note the
>
Output.Write("location.href = window.location.href + '?Proceed=' +
answer")
>
line in the VB class file code. When the ASPX page gets rendered, it
displays a Button. Conventionally, when a Button is clicked in an ASPX
page, it posts back to itself using the POST method. When the Button in
the above custom control is clicked, a JavaScript confirm dialog
pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
the value of the variable 'answer' is false.
>
What I want is irrespective of whether a user clicks the 'OK' or
'Cancel' button in the confirm dialog, instead of posting back to
itself using the conventional POST method, I want the ASPX page to post
to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
to suppress the conventional post & instead add the querystring so that
I can find out whether the user has clicked the 'OK' button or the
'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
be taken to
>
http://myserver/aspx/Confirm.aspx?Proceed=true
>
If the user clicks 'Cancel' in the confirm dialog, he will be taken to
>
http://myserver/aspx/Confirm.aspx?Proceed=false
>
Can this be done in anyway?
Suppress Form Action
Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property
Protected Overrides Sub AddAttributesToRender(ByVal Output As HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClick, "ConfirmMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("location.href = window.location.href + '?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
Using VBC, I compiled the above intoConfirm.dll. This is how I am using the above custom control in an ASPX page (assume that the ASPX page is namedConfirm.aspx):
<%@dotnet.itags.org. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %
<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?" Text="EXIT" runat="server"/>
</form>
Note the
Output.Write("location.href = window.location.href + '?Proceed=' + answer")
line (which is highlighted) in the VB class file code. When the ASPX page gets rendered, it displays a Button. Conventionally, when a Button is clicked in an ASPX page, it posts back to itself using the POST method. When the Button in the above custom control is clicked, a JavaScriptconfirm dialog pops-up with 2 buttons -OK &Cancel. IfOK is clicked, the value of the JavaScript variableanswer istrue & ifCancel is clicked, the value of the variableanswer isfalse.
What I want is irrespective of whether a user clicks theOK orCancel button in theconfirm dialog, instead of posting back to itself using the conventional POST method, I want the ASPX page to post to itself BUT with a querystringProceed=<value> appended i.e. I want to suppress the conventional post & instead add the querystring so that I can find out whether the user has clicked theOK button or theCancel button in theconfirm dialog. If the user clicksOK, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
On the other hand, if the user clicksCancel in theconfirm dialog, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=false
Can this be done in anyway?
Output.AddAttribute(HtmlTextWriterAttribute.OnClick, "ConfirmMsg();return false;")
Thanks, mate, your suggestion turned out to be a great one. Could you please tell me what role doesreturn=false; which you have appended afterConfirmMsg(), play here?
Going by your suggestion does add the querystringProceed=<value> at the end of the URL but there's a *** here. Suppose when a user clicks the server-side Button; he is shown the JavaScriptconfirm dialog with theOK &Cancel buttons. If the user clicksOK, then he is taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
That's fine but if the user clicks the server-side Button once again & clicksCancel in theconfirm dialog, then he is taken to
http://myserver/aspx/Confirm.aspx?Proceed=true?Proceed=false
i.e. the querystring gets appended twice. In other words, a querystringProceed=<value> will go on getting appended at the URL wheneverOK &Cancel is clicked in the JavaScriptconfirm dialog. For e.g. if a user clicks eitherOK orCancel in theconfirm dialog 5 times, then the querystring will get appended one after the other 5 times.
Any workaround to overcome this?
Suppress Form Action
Namespace Confirm
Public Class ShowConfirm : Inherits Button
Private strConfirmMsg As String
Public Property ConfirmMessage() As String
Get
ConfirmMessage = strConfirmMsg
End Get
Set(ByVal value As String)
strConfirmMsg = value
End Set
End Property
Protected Overrides Sub AddAttributesToRender(ByVal Output As
HtmlTextWriter)
MyBase.AddAttributesToRender(Output)
Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
"ConfirmMsg()")
End Sub
Protected Overrides Sub RenderContents(ByVal Output As
HtmlTextWriter)
Output.Write(vbCrLf)
Output.Write("<script language='JavaScript'>")
Output.Write(vbCrLf)
Output.Write("function ConfirmMsg(){")
Output.Write(vbCrLf)
Output.Write("var answer = confirm('")
Output.Write(strConfirmMsg)
Output.Write("')")
Output.Write(vbCrLf)
Output.Write("location.href = window.location.href +
'?Proceed=' + answer")
Output.Write(vbCrLf)
Output.Write("}")
Output.Write(vbCrLf)
Output.Write("</script>")
End Sub
End Class
End Namespace
Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
using the above custom control in an ASPX page (assume that the ASPX
page is named Confirm.aspx):
<%@dotnet.itags.org. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>
<form EnableViewState="true" runat="server">
<CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
Text="EXIT" runat="server"/>
</form>
Note the
Output.Write("location.href = window.location.href + '?Proceed=' +
answer")
line in the VB class file code. When the ASPX page gets rendered, it
displays a Button. Conventionally, when a Button is clicked in an ASPX
page, it posts back to itself using the POST method. When the Button in
the above custom control is clicked, a JavaScript confirm dialog
pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
the value of the variable 'answer' is false.
What I want is irrespective of whether a user clicks the 'OK' or
'Cancel' button in the confirm dialog, instead of posting back to
itself using the conventional POST method, I want the ASPX page to post
to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
to suppress the conventional post & instead add the querystring so that
I can find out whether the user has clicked the 'OK' button or the
'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
be taken to
http://myserver/aspx/Confirm.aspx?Proceed=true
If the user clicks 'Cancel' in the confirm dialog, he will be taken to
http://myserver/aspx/Confirm.aspx?Proceed=false
Can this be done in anyway?Anyone?
rn5a@.rediffmail.com wrote:
> A custom server control has a Button.
> Namespace Confirm
> Public Class ShowConfirm : Inherits Button
> Private strConfirmMsg As String
> Public Property ConfirmMessage() As String
> Get
> ConfirmMessage = strConfirmMsg
> End Get
> Set(ByVal value As String)
> strConfirmMsg = value
> End Set
> End Property
> Protected Overrides Sub AddAttributesToRender(ByVal Output As
> HtmlTextWriter)
> MyBase.AddAttributesToRender(Output)
> Output.AddAttribute(HtmlTextWriterAttribute.OnClick,
> "ConfirmMsg()")
> End Sub
> Protected Overrides Sub RenderContents(ByVal Output As
> HtmlTextWriter)
> Output.Write(vbCrLf)
> Output.Write("<script language='JavaScript'>")
> Output.Write(vbCrLf)
> Output.Write("function ConfirmMsg(){")
> Output.Write(vbCrLf)
> Output.Write("var answer = confirm('")
> Output.Write(strConfirmMsg)
> Output.Write("')")
> Output.Write(vbCrLf)
> Output.Write("location.href = window.location.href +
> '?Proceed=' + answer")
> Output.Write(vbCrLf)
> Output.Write("}")
> Output.Write(vbCrLf)
> Output.Write("</script>")
> End Sub
> End Class
> End Namespace
> Using VBC, I compiled the above into 'Confirm.dll'. This is how I am
> using the above custom control in an ASPX page (assume that the ASPX
> page is named Confirm.aspx):
> <%@. Register Assembly="Confirm" Namespace="Confirm" TagPrefix="CC" %>
> <form EnableViewState="true" runat="server">
> <CC:ShowConfirm ID="ShowConfirm1" ConfirmMessage="WANNA EXIT?"
> Text="EXIT" runat="server"/>
> </form>
> Note the
> Output.Write("location.href = window.location.href + '?Proceed=' +
> answer")
> line in the VB class file code. When the ASPX page gets rendered, it
> displays a Button. Conventionally, when a Button is clicked in an ASPX
> page, it posts back to itself using the POST method. When the Button in
> the above custom control is clicked, a JavaScript confirm dialog
> pops-up with 2 buttons - 'OK' & 'Cancel'. If 'OK' is clicked, the value
> of the JavaScript variable 'answer' is true & if 'Cancel' is clicked,
> the value of the variable 'answer' is false.
> What I want is irrespective of whether a user clicks the 'OK' or
> 'Cancel' button in the confirm dialog, instead of posting back to
> itself using the conventional POST method, I want the ASPX page to post
> to itself BUT with a querystring 'Proceed=<value>' appended i.e. I want
> to suppress the conventional post & instead add the querystring so that
> I can find out whether the user has clicked the 'OK' button or the
> 'Cancel' button in the confirm dialog. If the user clicks 'OK', he will
> be taken to
> http://myserver/aspx/Confirm.aspx?Proceed=true
> If the user clicks 'Cancel' in the confirm dialog, he will be taken to
> http://myserver/aspx/Confirm.aspx?Proceed=false
> Can this be done in anyway?
Tuesday, March 13, 2012
Swapping programmatically created user controls?
I have a form in which I'm trying to load a user control depending on
some user choice, and my control's events are not firing properly.
Here's a completely stripped down repro of the problem:
The form itself is empty:
<body>
<form id="form1" runat="server" />
</body>
and here's the code behind for the form:
protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;
form1.Controls.Add( LoadControl( currentControl + ".ascx" ) );
}
The first user control:
===============
<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="UC1.ascx.cs"
Inherits="UC1" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC2" />
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC2.ascx" );
ctl.ID = "UC2";
Parent.Controls.Add( ctl );
HttpContext.Current.Session["CurrentControl"] = "UC2";
Parent.Controls.Remove( this );
}
The second user control:
==================
<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="UC2.ascx.cs"
Inherits="UC2" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC1" />
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC1.ascx" );
ctl.ID = "UC1";
Parent.Controls.Add( ctl );
Parent.Controls.Remove( this );
HttpContext.Current.Session["CurrentControl"] = "UC1";
}
and here's the problem:
When I run this, the page loads fine, with UC1. I click on the button
in UC1, the form gets posted, and comes back with UC2. Now if I click
on the button in UC2, the form gets posted, but comes back with UC2
itself instead of UC1. I click on the button in UC2 again, and now the
form comes back with UC1! It seems that the control loads fine, but the
button click event defined inside the user control will not fire the
first time, but only the second time.
I'm from the WinForms world and I'm new to the WebForms, so I might be
missing something obvious. Could anyone kindly point out what I'm doing
wrong? I've been scratching my head for the past two days without
making any progress. Thanks a lot in advance for your time.
- Ramesh.Hi,
I solved the problem myself. All I had to do was change the OnInit of
the form to set the ID of the control as well, like this:
protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;
Control ctl = LoadControl( currentControl + ".ascx" );
ctl.ID = currentControl;
form1.Controls.Add( ctl );
}
and it works fine now. I knew I was missing something obvious... Sorry
if I had wasted your time.
This approach, with an Atlas UpdatePanel thrown in to enclose the user
controls, results in a very WinForms like feel. Wow!
- Ramesh
Ramesh wrote:
Quote:
Originally Posted by
Hello all,
>
I have a form in which I'm trying to load a user control depending on
some user choice, and my control's events are not firing properly.
Here's a completely stripped down repro of the problem:
>
The form itself is empty:
<body>
<form id="form1" runat="server" />
</body>
>
and here's the code behind for the form:
protected override void OnInit( EventArgs e )
{
string currentControl = "UC1";
object objCurrentControl = Session["CurrentControl"];
if( objCurrentControl != null )
currentControl = (string)objCurrentControl;
>
form1.Controls.Add( LoadControl( currentControl + ".ascx" ) );
}
>
>
The first user control:
===============
<%@. Control Language="C#" AutoEventWireup="true" CodeFile="UC1.ascx.cs"
Inherits="UC1" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC2" />
>
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC2.ascx" );
ctl.ID = "UC2";
Parent.Controls.Add( ctl );
HttpContext.Current.Session["CurrentControl"] = "UC2";
Parent.Controls.Remove( this );
}
>
The second user control:
==================
<%@. Control Language="C#" AutoEventWireup="true" CodeFile="UC2.ascx.cs"
Inherits="UC2" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Create UC1" />
>
and the code behind:
protected void Button1_Click( object sender, EventArgs e )
{
Control ctl = LoadControl( "UC1.ascx" );
ctl.ID = "UC1";
Parent.Controls.Add( ctl );
Parent.Controls.Remove( this );
HttpContext.Current.Session["CurrentControl"] = "UC1";
}
>
and here's the problem:
When I run this, the page loads fine, with UC1. I click on the button
in UC1, the form gets posted, and comes back with UC2. Now if I click
on the button in UC2, the form gets posted, but comes back with UC2
itself instead of UC1. I click on the button in UC2 again, and now the
form comes back with UC1! It seems that the control loads fine, but the
button click event defined inside the user control will not fire the
first time, but only the second time.
>
I'm from the WinForms world and I'm new to the WebForms, so I might be
missing something obvious. Could anyone kindly point out what I'm doing
wrong? I've been scratching my head for the past two days without
making any progress. Thanks a lot in advance for your time.
>
- Ramesh.
Switch / case statements
Error I'm getting is...
Control cannot fall through from one case label ('case 14:') to another
Well, not just case 14, but all of them.
Here's the sample...
publicbool checkMe(ArrayList myArray,int myInt){
switch (myInt) {
case 3 :
if(System.Convert.ToInt32( myArray[0] )== 0 &&
System.Convert.ToInt32( myArray[1]) == 1 )
{
myArray[1] = 0;
myArray[3] = 0;
myArray[0] = 1;
pNum = 3;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
if( System.Convert.ToInt32( myArray[5] ) == 0 &&
System.Convert.ToInt32( myArray[4] ) == 1 )
{
myArray[4] = 0;
myArray[3] = 0;
myArray[5] = 1;
pNum = 3;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
case 5 :
if( System.Convert.ToInt32( myArray[0] ) == 0 &&
System.Convert.ToInt32( myArray[2] ) == 1 )
{
myArray[2] = 0;
myArray[5] = 0;
myArray[0] = 1;
pNum = 5;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
if( System.Convert.ToInt32( myArray[3] ) == 0 &&
System.Convert.ToInt32( myArray[4] ) == 1 )
{
myArray[4] = 0;
myArray[5] = 0;
myArray[3] = 1;
pNum = 5;
tempAL = myArray;
printArray(tempAL);
bSuccess =true;
break;
}
default :
{
bSuccess =false;
}
}
So, what's the deal?
Thanks,
Zath
That's because C# requires a break statement after every case statement (at least ones with code in them), and yours are within conditionals. Here's your code fixed up:
public bool checkMe(ArrayList myArray, int myInt)
{
switch ( myInt )
{
case 3:
if ( System.Convert.ToInt32(myArray[0]) == 0 &&
System.Convert.ToInt32(myArray[1]) == 1 )
{
myArray[1] = 0;
myArray[3] = 0;
myArray[0] = 1;
pNum = 3;
tempAL = myArray;
printArray(tempAL);
bSuccess = true;
break;
}
if ( System.Convert.ToInt32(myArray[5]) == 0 &&
System.Convert.ToInt32(myArray[4]) == 1 )
{
myArray[4] = 0;
myArray[3] = 0;
myArray[5] = 1;
pNum = 3;
tempAL = myArray;
printArray(tempAL);
bSuccess = true;
break;
}
break;
case 5:
if ( System.Convert.ToInt32(myArray[0]) == 0 &&
System.Convert.ToInt32(myArray[2]) == 1 )
{
myArray[2] = 0;
myArray[5] = 0;
myArray[0] = 1;
pNum = 5;
tempAL = myArray;
printArray(tempAL);
bSuccess = true;
break;
}
if ( System.Convert.ToInt32(myArray[3]) == 0 &&
System.Convert.ToInt32(myArray[4]) == 1 )
{
myArray[4] = 0;
myArray[5] = 0;
myArray[3] = 1;
pNum = 5;
tempAL = myArray;
printArray(tempAL);
bSuccess = true;
break;
}
break;
default :
bSuccess = false;
break;
} // end of switch statement
} // end of method
You could do something like this and it would work:
switch ( someValue )
{
case 0:
case 1:
// do something
break;
case 2:
// do something
break;
default:
break;
}
NC...
Thanks, that did the trick.
Just when you think you know all the syntax
Zath